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);
34 for (
int i = 0;
i < result.
size(); ++
i) {
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);
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) {
86 float expected = 0.0f;
87 for (
int i = 0;
i < 2; ++
i) {
88 expected += tensor(
i,
j,k,
l,
m);
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) {
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);
112 const Dims2 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);
128 const Dims3 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);
144 const Dims4 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);
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;
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));
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()
276 auto reduction_axis = make_index_list(dim1, dim2, dim3);
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);
299 static void test_mixed_index_list()
307 auto reduction_axis = make_index_list(0, dim2, 2, dim4);
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);
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);
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
void test_cxx11_tensor_index_list()
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
#define VERIFY_IS_APPROX(a, b)
static const Line3 l(Rot3(), 1, 1)
#define VERIFY_IS_EQUAL(a, b)
constexpr int first(int i)
Implementation details for constexpr functions.
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
EIGEN_DEVICE_FUNC bool dimensions_match(Dims1 &dims1, Dims2 &dims2)
#define CALL_SUBTEST(FUNC)
EIGEN_DEVICE_FUNC void set(IndexPair< Idx > val)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const