12 #include <Eigen/CXX11/Tensor> 14 #ifdef EIGEN_HAS_INDEX_LIST 16 static void test_static_index_list()
18 Tensor<float, 4> tensor(2,3,5,7);
21 constexpr
auto reduction_axis = make_index_list(0, 1, 2);
22 VERIFY_IS_EQUAL(internal::array_get<0>(reduction_axis), 0);
23 VERIFY_IS_EQUAL(internal::array_get<1>(reduction_axis), 1);
24 VERIFY_IS_EQUAL(internal::array_get<2>(reduction_axis), 2);
25 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[0]), 0);
26 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[1]), 1);
27 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[2]), 2);
29 EIGEN_STATIC_ASSERT((internal::array_get<0>(reduction_axis) == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
30 EIGEN_STATIC_ASSERT((internal::array_get<1>(reduction_axis) == 1), YOU_MADE_A_PROGRAMMING_MISTAKE);
31 EIGEN_STATIC_ASSERT((internal::array_get<2>(reduction_axis) == 2), YOU_MADE_A_PROGRAMMING_MISTAKE);
33 Tensor<float, 1> result = tensor.sum(reduction_axis);
34 for (
int i = 0; i < result.size(); ++i) {
35 float expected = 0.0f;
36 for (
int j = 0; j < 2; ++j) {
37 for (
int k = 0; k < 3; ++k) {
38 for (
int l = 0; l < 5; ++l) {
39 expected += tensor(j,k,l,i);
43 VERIFY_IS_APPROX(result(i), expected);
48 static void test_type2index_list()
50 Tensor<float, 5> tensor(2,3,5,7,11);
52 tensor += tensor.constant(10.0
f);
54 typedef Eigen::IndexList<Eigen::type2index<0>> Dims0;
55 typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>> Dims1;
56 typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>> Dims2;
57 typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>, Eigen::type2index<3>> Dims3;
58 typedef Eigen::IndexList<Eigen::type2index<0>, Eigen::type2index<1>, Eigen::type2index<2>, Eigen::type2index<3>, Eigen::type2index<4>> Dims4;
61 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims0>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
62 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims1>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
63 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims2>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
64 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims3>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
65 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<Dims4>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
68 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims0, 1, ColMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
69 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims1, 2, ColMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
70 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims2, 3, ColMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
71 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims3, 4, ColMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
72 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims4, 5, ColMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
74 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims0, 1, RowMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
75 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims1, 2, RowMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
76 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims2, 3, RowMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
77 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims3, 4, RowMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
78 EIGEN_STATIC_ASSERT((internal::are_inner_most_dims<Dims4, 5, RowMajor>::value ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
80 const Dims0 reduction_axis0;
81 Tensor<float, 4> result0 = tensor.sum(reduction_axis0);
82 for (
int m = 0; m < 11; ++m) {
83 for (
int l = 0; l < 7; ++l) {
84 for (
int k = 0; k < 5; ++k) {
85 for (
int j = 0; j < 3; ++j) {
86 float expected = 0.0f;
87 for (
int i = 0; i < 2; ++i) {
88 expected += tensor(i,j,k,l,m);
90 VERIFY_IS_APPROX(result0(j,k,l,m), expected);
96 const Dims1 reduction_axis1;
97 Tensor<float, 3> result1 = tensor.sum(reduction_axis1);
98 for (
int m = 0; m < 11; ++m) {
99 for (
int l = 0; l < 7; ++l) {
100 for (
int k = 0; k < 5; ++k) {
101 float expected = 0.0f;
102 for (
int j = 0; j < 3; ++j) {
103 for (
int i = 0; i < 2; ++i) {
104 expected += tensor(i,j,k,l,m);
107 VERIFY_IS_APPROX(result1(k,l,m), expected);
112 const Dims2 reduction_axis2;
113 Tensor<float, 2> result2 = tensor.sum(reduction_axis2);
114 for (
int m = 0; m < 11; ++m) {
115 for (
int l = 0; l < 7; ++l) {
116 float expected = 0.0f;
117 for (
int k = 0; k < 5; ++k) {
118 for (
int j = 0; j < 3; ++j) {
119 for (
int i = 0; i < 2; ++i) {
120 expected += tensor(i,j,k,l,m);
124 VERIFY_IS_APPROX(result2(l,m), expected);
128 const Dims3 reduction_axis3;
129 Tensor<float, 1> result3 = tensor.sum(reduction_axis3);
130 for (
int m = 0; m < 11; ++m) {
131 float expected = 0.0f;
132 for (
int l = 0; l < 7; ++l) {
133 for (
int k = 0; k < 5; ++k) {
134 for (
int j = 0; j < 3; ++j) {
135 for (
int i = 0; i < 2; ++i) {
136 expected += tensor(i,j,k,l,m);
141 VERIFY_IS_APPROX(result3(m), expected);
144 const Dims4 reduction_axis4;
145 Tensor<float, 0> result4 = tensor.sum(reduction_axis4);
146 float expected = 0.0f;
147 for (
int m = 0; m < 11; ++m) {
148 for (
int l = 0; l < 7; ++l) {
149 for (
int k = 0; k < 5; ++k) {
150 for (
int j = 0; j < 3; ++j) {
151 for (
int i = 0; i < 2; ++i) {
152 expected += tensor(i,j,k,l,m);
158 VERIFY_IS_APPROX(result4(), expected);
162 static void test_type2indexpair_list()
164 Tensor<float, 5> tensor(2,3,5,7,11);
166 tensor += tensor.constant(10.0
f);
168 typedef Eigen::IndexPairList<Eigen::type2indexpair<0,10>> Dims0;
169 typedef Eigen::IndexPairList<Eigen::type2indexpair<0,10>, Eigen::type2indexpair<1,11>, Eigen::type2indexpair<2,12>> Dims2_a;
171 typedef Eigen::IndexPairList<Eigen::IndexPair<DenseIndex>, Eigen::type2indexpair<1,11>, Eigen::IndexPair<DenseIndex>> Dims2_c;
177 d2_b.
set(1, Eigen::IndexPair<DenseIndex>(1,11));
180 d2_c.set(0, Eigen::IndexPair<DenseIndex>(Eigen::IndexPair<DenseIndex>(0,10)));
181 d2_c.set(1, Eigen::IndexPair<DenseIndex>(1,11));
182 d2_c.set(2, Eigen::IndexPair<DenseIndex>(2,12));
184 VERIFY_IS_EQUAL(d2_a[0].first, 0);
185 VERIFY_IS_EQUAL(d2_a[0].second, 10);
186 VERIFY_IS_EQUAL(d2_a[1].first, 1);
187 VERIFY_IS_EQUAL(d2_a[1].second, 11);
188 VERIFY_IS_EQUAL(d2_a[2].first, 2);
189 VERIFY_IS_EQUAL(d2_a[2].second, 12);
191 VERIFY_IS_EQUAL(d2_b[0].first, 0);
192 VERIFY_IS_EQUAL(d2_b[0].second, 10);
193 VERIFY_IS_EQUAL(d2_b[1].first, 1);
194 VERIFY_IS_EQUAL(d2_b[1].second, 11);
195 VERIFY_IS_EQUAL(d2_b[2].first, 2);
196 VERIFY_IS_EQUAL(d2_b[2].second, 12);
198 VERIFY_IS_EQUAL(d2_c[0].first, 0);
199 VERIFY_IS_EQUAL(d2_c[0].second, 10);
200 VERIFY_IS_EQUAL(d2_c[1].first, 1);
201 VERIFY_IS_EQUAL(d2_c[1].second, 11);
202 VERIFY_IS_EQUAL(d2_c[2].first, 2);
203 VERIFY_IS_EQUAL(d2_c[2].second, 12);
205 EIGEN_STATIC_ASSERT((d2_a.value_known_statically(0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
206 EIGEN_STATIC_ASSERT((d2_a.value_known_statically(1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
207 EIGEN_STATIC_ASSERT((d2_a.value_known_statically(2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
209 EIGEN_STATIC_ASSERT((d2_b.value_known_statically(0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
210 EIGEN_STATIC_ASSERT((d2_b.value_known_statically(1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
211 EIGEN_STATIC_ASSERT((d2_b.value_known_statically(2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
213 EIGEN_STATIC_ASSERT((d2_c.value_known_statically(0) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
214 EIGEN_STATIC_ASSERT((d2_c.value_known_statically(1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
215 EIGEN_STATIC_ASSERT((d2_c.value_known_statically(2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
217 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims0>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
218 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims0>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
220 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
221 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
222 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(1, 1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
223 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(1, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
224 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
225 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(2, 3) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
227 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
228 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
229 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(1, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
230 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(1, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
231 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
232 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(2, 3) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
234 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(0, 0) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
235 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
236 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(1, 1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
237 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(1, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
238 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(2, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
239 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(2, 3) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
241 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims0>(0, 10) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
242 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims0>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
244 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(0, 10) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
245 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
246 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(1, 11) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
247 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(1, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
248 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(2, 12) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
249 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(2, 13) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
251 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(0, 10) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
252 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
253 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(1, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
254 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(1, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
255 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(2, 12) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
256 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(2, 13) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
258 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(0, 10) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
259 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
260 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(1, 11) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
261 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(1, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
262 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(2, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
263 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(2, 13) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
267 static void test_dynamic_index_list()
269 Tensor<float, 4> tensor(2,3,5,7);
276 auto reduction_axis = make_index_list(dim1, dim2, dim3);
278 VERIFY_IS_EQUAL(internal::array_get<0>(reduction_axis), 2);
279 VERIFY_IS_EQUAL(internal::array_get<1>(reduction_axis), 1);
280 VERIFY_IS_EQUAL(internal::array_get<2>(reduction_axis), 0);
281 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[0]), 2);
282 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[1]), 1);
283 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[2]), 0);
285 Tensor<float, 1> result = tensor.sum(reduction_axis);
286 for (
int i = 0; i < result.size(); ++i) {
287 float expected = 0.0f;
288 for (
int j = 0; j < 2; ++j) {
289 for (
int k = 0; k < 3; ++k) {
290 for (
int l = 0; l < 5; ++l) {
291 expected += tensor(j,k,l,i);
295 VERIFY_IS_APPROX(result(i), expected);
299 static void test_mixed_index_list()
301 Tensor<float, 4> tensor(2,3,5,7);
307 auto reduction_axis = make_index_list(0, dim2, 2, dim4);
309 VERIFY_IS_EQUAL(internal::array_get<0>(reduction_axis), 0);
310 VERIFY_IS_EQUAL(internal::array_get<1>(reduction_axis), 1);
311 VERIFY_IS_EQUAL(internal::array_get<2>(reduction_axis), 2);
312 VERIFY_IS_EQUAL(internal::array_get<3>(reduction_axis), 3);
313 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[0]), 0);
314 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[1]), 1);
315 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[2]), 2);
316 VERIFY_IS_EQUAL(static_cast<DenseIndex>(reduction_axis[3]), 3);
318 typedef IndexList<type2index<0>, int, type2index<2>,
int> ReductionIndices;
319 ReductionIndices reduction_indices;
320 reduction_indices.set(1, 1);
321 reduction_indices.set(3, 3);
322 EIGEN_STATIC_ASSERT((internal::array_get<0>(reduction_indices) == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
323 EIGEN_STATIC_ASSERT((internal::array_get<2>(reduction_indices) == 2), YOU_MADE_A_PROGRAMMING_MISTAKE);
324 EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>(0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
325 EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>(2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
326 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
327 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
329 EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionIndices>() ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
330 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionIndices>() ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
333 typedef IndexList<type2index<0>, type2index<1>, type2index<2>, type2index<3>> ReductionList;
334 ReductionList reduction_list;
335 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
336 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(1, 1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
337 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
338 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(3, 3) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
340 EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionList>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
341 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionList>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
344 Tensor<float, 0> result1 = tensor.sum(reduction_axis);
345 Tensor<float, 0> result2 = tensor.sum(reduction_indices);
346 Tensor<float, 0> result3 = tensor.sum(reduction_list);
348 float expected = 0.0f;
349 for (
int i = 0; i < 2; ++i) {
350 for (
int j = 0; j < 3; ++j) {
351 for (
int k = 0; k < 5; ++k) {
352 for (
int l = 0; l < 7; ++l) {
353 expected += tensor(i,j,k,l);
358 VERIFY_IS_APPROX(result1(), expected);
359 VERIFY_IS_APPROX(result2(), expected);
360 VERIFY_IS_APPROX(result3(), expected);
364 static void test_dim_check()
366 Eigen::IndexList<Eigen::type2index<1>,
int> dim1;
368 Eigen::IndexList<Eigen::type2index<1>,
int> dim2;
378 #ifdef EIGEN_HAS_INDEX_LIST 379 CALL_SUBTEST(test_static_index_list());
380 CALL_SUBTEST(test_type2index_list());
381 CALL_SUBTEST(test_type2indexpair_list());
382 CALL_SUBTEST(test_dynamic_index_list());
383 CALL_SUBTEST(test_mixed_index_list());
384 CALL_SUBTEST(test_dim_check());
void test_cxx11_tensor_index_list()
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
EIGEN_DEVICE_FUNC bool dimensions_match(Dims1 &dims1, Dims2 &dims2)
EIGEN_DEVICE_FUNC void set(IndexPair< Idx > val)