xtensor
Loading...
Searching...
No Matches
xexpression_traits.hpp
1/***************************************************************************
2 * Copyright (c) Johan Mabille, Sylvain Corlay and Wolf Vollprecht *
3 * Copyright (c) QuantStack *
4 * *
5 * Distributed under the terms of the BSD 3-Clause License. *
6 * *
7 * The full license is in the file LICENSE, distributed with this software. *
8 ****************************************************************************/
9
10#ifndef XTENSOR_EXPRESSION_TRAITS_HPP
11#define XTENSOR_EXPRESSION_TRAITS_HPP
12
13#include "xexpression.hpp"
14
15namespace xt
16{
17 /***************
18 * xvalue_type *
19 ***************/
20
21 namespace detail
22 {
23 template <class E, class enable = void>
24 struct xvalue_type_impl
25 {
26 using type = E;
27 };
28
29 template <class E>
30 struct xvalue_type_impl<E, std::enable_if_t<is_xexpression<E>::value>>
31 {
32 using type = typename E::value_type;
33 };
34 }
35
36 template <class E>
37 using xvalue_type = detail::xvalue_type_impl<E>;
38
39 template <class E>
40 using xvalue_type_t = typename xvalue_type<E>::type;
41
42 /*********************
43 * common_value_type *
44 *********************/
45
46 template <class... C>
48 {
49 using type = std::common_type_t<typename std::decay_t<C>::value_type...>;
50 };
51
52 template <class... C>
53 using common_value_type_t = typename common_value_type<C...>::type;
54
55 /********************
56 * common_size_type *
57 ********************/
58
59 template <class... Args>
61 {
62 using type = std::common_type_t<typename Args::size_type...>;
63 };
64
65 template <>
67 {
68 using type = std::size_t;
69 };
70
71 template <class... Args>
72 using common_size_type_t = typename common_size_type<Args...>::type;
73
74 /**************************
75 * common_difference type *
76 **************************/
77
78 template <class... Args>
80 {
81 using type = std::common_type_t<typename Args::difference_type...>;
82 };
83
84 template <>
86 {
87 using type = std::ptrdiff_t;
88 };
89
90 template <class... Args>
91 using common_difference_type_t = typename common_difference_type<Args...>::type;
92
93 /******************
94 * temporary_type *
95 ******************/
96
97 namespace detail
98 {
99 template <class S>
100 struct xtype_for_shape
101 {
102 template <class T, layout_type L>
103 using type = xarray<T, L>;
104 };
105
106#if defined(__GNUC__) && (__GNUC__ > 6)
107#if __cplusplus == 201703L
108 template <template <class, std::size_t, class, bool> class S, class X, std::size_t N, class A, bool Init>
109 struct xtype_for_shape<S<X, N, A, Init>>
110 {
111 template <class T, layout_type L>
112 using type = xarray<T, L>;
113 };
114#endif // __cplusplus == 201703L
115#endif // __GNUC__ && (__GNUC__ > 6)
116
117 template <template <class, std::size_t> class S, class X, std::size_t N>
118 struct xtype_for_shape<S<X, N>>
119 {
120 template <class T, layout_type L>
121 using type = xtensor<T, N, L>;
122 };
123
124 template <template <std::size_t...> class S, std::size_t... X>
125 struct xtype_for_shape<S<X...>>
126 {
127 template <class T, layout_type L>
128 using type = xtensor_fixed<T, xshape<X...>, L>;
129 };
130 }
131
132 template <class Tag, class T>
134
135 template <class T>
137 {
138 using I = std::decay_t<T>;
139 using shape_type = typename I::shape_type;
140 using value_type = typename I::value_type;
141 static constexpr layout_type static_layout = XTENSOR_DEFAULT_LAYOUT;
142 using type = typename detail::xtype_for_shape<shape_type>::template type<value_type, static_layout>;
143 };
144
145 template <class T, class = void>
147 {
148 using type = typename temporary_type_from_tag<xexpression_tag_t<T>, T>::type;
149 };
150
151 template <class T>
152 struct temporary_type<T, void_t<typename std::decay_t<T>::temporary_type>>
153 {
154 using type = typename std::decay_t<T>::temporary_type;
155 };
156
157 template <class T>
158 using temporary_type_t = typename temporary_type<T>::type;
159
160 /**********************
161 * common_tensor_type *
162 **********************/
163
164 namespace detail
165 {
166 template <class... C>
167 struct common_tensor_type_impl
168 {
169 static constexpr layout_type static_layout = compute_layout(std::decay_t<C>::static_layout...);
170 using value_type = common_value_type_t<C...>;
171 using shape_type = promote_shape_t<typename C::shape_type...>;
172 using type = typename xtype_for_shape<shape_type>::template type<value_type, static_layout>;
173 };
174 }
175
176 template <class... C>
177 struct common_tensor_type : detail::common_tensor_type_impl<std::decay_t<C>...>
178 {
179 };
180
181 template <class... C>
182 using common_tensor_type_t = typename common_tensor_type<C...>::type;
183
184 /**************************
185 * big_promote_value_type *
186 **************************/
187
188 template <class E>
190 {
191 using type = xtl::big_promote_type_t<typename std::decay_t<E>::value_type>;
192 };
193
194 template <class E>
195 using big_promote_value_type_t = typename big_promote_value_type<E>::type;
196}
197
198#endif
standard mathematical functions for xexpressions
constexpr layout_type compute_layout(Args... args) noexcept
Implementation of the following logical table:
Definition xlayout.hpp:88
layout_type
Definition xlayout.hpp:24
fixed_shape< N... > xshape
Alias template for fixed_shape allows for a shorter template shape definition in xtensor_fixed.
xfixed_container< T, FSH, L, Sharable > xtensor_fixed
Alias template on xfixed_container with default parameters for layout type.