12 #include <Eigen/CXX11/Tensor>
14 #ifdef EIGEN_HAS_INDEX_LIST
16 static void test_static_index_list()
21 constexpr
auto reduction_axis = make_index_list(0, 1, 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);
36 for (
int j = 0;
j < 2; ++
j) {
37 for (
int k = 0; k < 3; ++k) {
38 for (
int l = 0;
l < 5; ++
l) {
48 static void test_type2index_list()
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);
80 const Dims0 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) {
87 for (
int i = 0;
i < 2; ++
i) {
96 const Dims1 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) {
102 for (
int j = 0;
j < 3; ++
j) {
103 for (
int i = 0;
i < 2; ++
i) {
112 const Dims2 reduction_axis2;
114 for (
int m = 0;
m < 11; ++
m) {
115 for (
int l = 0;
l < 7; ++
l) {
117 for (
int k = 0; k < 5; ++k) {
118 for (
int j = 0;
j < 3; ++
j) {
119 for (
int i = 0;
i < 2; ++
i) {
128 const Dims3 reduction_axis3;
130 for (
int m = 0;
m < 11; ++
m) {
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) {
144 const Dims4 reduction_axis4;
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) {
162 static void test_type2indexpair_list()
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;
170 typedef Eigen::IndexPairList<Eigen::type2indexpair<0,10>,
Eigen::IndexPair<Index>, Eigen::type2indexpair<2,12>> Dims2_b;
171 typedef Eigen::IndexPairList<Eigen::IndexPair<Index>, Eigen::type2indexpair<1,11>,
Eigen::IndexPair<Index>> Dims2_c;
204 EIGEN_STATIC_ASSERT((d2_a.value_known_statically(0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
205 EIGEN_STATIC_ASSERT((d2_a.value_known_statically(1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
206 EIGEN_STATIC_ASSERT((d2_a.value_known_statically(2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
208 EIGEN_STATIC_ASSERT((d2_b.value_known_statically(0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
209 EIGEN_STATIC_ASSERT((d2_b.value_known_statically(1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
210 EIGEN_STATIC_ASSERT((d2_b.value_known_statically(2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
212 EIGEN_STATIC_ASSERT((d2_c.value_known_statically(0) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
213 EIGEN_STATIC_ASSERT((d2_c.value_known_statically(1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
214 EIGEN_STATIC_ASSERT((d2_c.value_known_statically(2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
216 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims0>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
217 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims0>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
219 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
220 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
221 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(1, 1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
222 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(1, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
223 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
224 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_a>(2, 3) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
226 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
227 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
228 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(1, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
229 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(1, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
230 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
231 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_b>(2, 3) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
233 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(0, 0) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
234 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(0, 1) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
235 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(1, 1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
236 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(1, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
237 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(2, 2) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
238 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_first_statically_eq<Dims2_c>(2, 3) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
240 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims0>(0, 10) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
241 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims0>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
243 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(0, 10) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
244 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
245 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(1, 11) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
246 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(1, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
247 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(2, 12) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
248 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_a>(2, 13) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
250 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(0, 10) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
251 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
252 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(1, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
253 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(1, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
254 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(2, 12) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
255 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_b>(2, 13) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
257 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(0, 10) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
258 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(0, 11) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
259 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(1, 11) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
260 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(1, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
261 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(2, 12) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
262 EIGEN_STATIC_ASSERT((Eigen::internal::index_pair_second_statically_eq<Dims2_c>(2, 13) ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
266 static void test_dynamic_index_list()
275 auto reduction_axis = make_index_list(dim1, dim2, dim3);
285 for (
int i = 0;
i <
result.size(); ++
i) {
287 for (
int j = 0;
j < 2; ++
j) {
288 for (
int k = 0; k < 3; ++k) {
289 for (
int l = 0;
l < 5; ++
l) {
298 static void test_mixed_index_list()
306 auto reduction_axis = make_index_list(0, dim2, 2, dim4);
317 typedef IndexList<type2index<0>,
int, type2index<2>,
int> ReductionIndices;
318 ReductionIndices reduction_indices;
319 reduction_indices.set(1, 1);
320 reduction_indices.set(3, 3);
321 EIGEN_STATIC_ASSERT((internal::array_get<0>(reduction_indices) == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
322 EIGEN_STATIC_ASSERT((internal::array_get<2>(reduction_indices) == 2), YOU_MADE_A_PROGRAMMING_MISTAKE);
323 EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>(0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
324 EIGEN_STATIC_ASSERT((internal::index_known_statically<ReductionIndices>(2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
325 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
326 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionIndices>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
328 EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionIndices>() ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
329 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionIndices>() ==
false), YOU_MADE_A_PROGRAMMING_MISTAKE);
332 typedef IndexList<type2index<0>, type2index<1>, type2index<2>, type2index<3>> ReductionList;
333 ReductionList reduction_list;
334 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(0, 0) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
335 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(1, 1) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
336 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(2, 2) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
337 EIGEN_STATIC_ASSERT((internal::index_statically_eq<ReductionList>(3, 3) ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
339 EIGEN_STATIC_ASSERT((internal::all_indices_known_statically<ReductionList>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
340 EIGEN_STATIC_ASSERT((internal::indices_statically_known_to_increase<ReductionList>() ==
true), YOU_MADE_A_PROGRAMMING_MISTAKE);
348 for (
int i = 0;
i < 2; ++
i) {
349 for (
int j = 0;
j < 3; ++
j) {
350 for (
int k = 0; k < 5; ++k) {
351 for (
int l = 0;
l < 7; ++
l) {
363 static void test_dim_check()
365 Eigen::IndexList<Eigen::type2index<1>,
int> dim1;
367 Eigen::IndexList<Eigen::type2index<1>,
int> dim2;
377 #ifdef EIGEN_HAS_INDEX_LIST