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 "../core/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// Workaround for rebind_container problems when C++17 feature is enabled
107#ifdef __cpp_template_template_args
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 // __cpp_template_template_args
115
116 template <template <class, std::size_t> class S, class X, std::size_t N>
117 struct xtype_for_shape<S<X, N>>
118 {
119 template <class T, layout_type L>
120 using type = xtensor<T, N, L>;
121 };
122
123 template <template <std::size_t...> class S, std::size_t... X>
124 struct xtype_for_shape<S<X...>>
125 {
126 template <class T, layout_type L>
127 using type = xtensor_fixed<T, xshape<X...>, L>;
128 };
129 }
130
131 template <class Tag, class T>
133
134 template <class T>
136 {
137 using I = std::decay_t<T>;
138 using shape_type = typename I::shape_type;
139 using value_type = typename I::value_type;
140 static constexpr layout_type static_layout = XTENSOR_DEFAULT_LAYOUT;
141 using type = typename detail::xtype_for_shape<shape_type>::template type<value_type, static_layout>;
142 };
143
144 template <class T, class = void>
146 {
147 using type = typename temporary_type_from_tag<xexpression_tag_t<T>, T>::type;
148 };
149
150 template <class T>
151 struct temporary_type<T, void_t<typename std::decay_t<T>::temporary_type>>
152 {
153 using type = typename std::decay_t<T>::temporary_type;
154 };
155
156 template <class T>
157 using temporary_type_t = typename temporary_type<T>::type;
158
159 /**********************
160 * common_tensor_type *
161 **********************/
162
163 namespace detail
164 {
165 template <class... C>
166 struct common_tensor_type_impl
167 {
168 static constexpr layout_type static_layout = compute_layout(std::decay_t<C>::static_layout...);
169 using value_type = common_value_type_t<C...>;
170 using shape_type = promote_shape_t<typename C::shape_type...>;
171 using type = typename xtype_for_shape<shape_type>::template type<value_type, static_layout>;
172 };
173 }
174
175 template <class... C>
176 struct common_tensor_type : detail::common_tensor_type_impl<std::decay_t<C>...>
177 {
178 };
179
180 template <class... C>
181 using common_tensor_type_t = typename common_tensor_type<C...>::type;
182
183 /**************************
184 * big_promote_value_type *
185 **************************/
186
187 template <class E>
189 {
190 using type = xtl::big_promote_type_t<typename std::decay_t<E>::value_type>;
191 };
192
193 template <class E>
194 using big_promote_value_type_t = typename big_promote_value_type<E>::type;
195}
196
197#endif
standard mathematical functions for xexpressions
xarray_container< uvector< T, A >, L, xt::svector< typename uvector< T, A >::size_type, 4, SA, true > > xarray
Alias template on xarray_container with default parameters for data container type and shape / stride...
constexpr layout_type compute_layout(Args... args) noexcept
Implementation of the following logical table:
Definition xlayout.hpp:88
layout_type
Definition xlayout.hpp:24
xfixed_container< T, FSH, L, Sharable > xtensor_fixed
Alias template on xfixed_container with default parameters for layout type.
xtensor_container< uvector< T, A >, N, L > xtensor
Alias template on xtensor_container with default parameters for data container type.
fixed_shape< N... > xshape
Alias template for fixed_shape allows for a shorter template shape definition in xtensor_fixed.