12 #include <Eigen/CXX11/Tensor> 16 template<
int DataLayout>
23 chip1 = tensor.template chip<0>(1);
30 for (
int i = 0; i < 3; ++i) {
31 for (
int j = 0; j < 5; ++j) {
32 for (
int k = 0; k < 7; ++k) {
33 for (
int l = 0; l < 11; ++l) {
34 VERIFY_IS_EQUAL(chip1(i,j,k,l), tensor(1,i,j,k,l));
45 for (
int i = 0; i < 2; ++i) {
46 for (
int j = 0; j < 3; ++j) {
47 for (
int k = 0; k < 7; ++k) {
48 for (
int l = 0; l < 11; ++l) {
49 VERIFY_IS_EQUAL(chip2(i,j,k,l), tensor(i,1,j,k,l));
60 for (
int i = 0; i < 2; ++i) {
61 for (
int j = 0; j < 3; ++j) {
62 for (
int k = 0; k < 7; ++k) {
63 for (
int l = 0; l < 11; ++l) {
64 VERIFY_IS_EQUAL(chip3(i,j,k,l), tensor(i,j,2,k,l));
75 for (
int i = 0; i < 2; ++i) {
76 for (
int j = 0; j < 3; ++j) {
77 for (
int k = 0; k < 5; ++k) {
78 for (
int l = 0; l < 7; ++l) {
79 VERIFY_IS_EQUAL(chip4(i,j,k,l), tensor(i,j,k,5,l));
90 for (
int i = 0; i < 2; ++i) {
91 for (
int j = 0; j < 3; ++j) {
92 for (
int k = 0; k < 5; ++k) {
93 for (
int l = 0; l < 7; ++l) {
94 VERIFY_IS_EQUAL(chip5(i,j,k,l), tensor(i,j,k,l,7));
101 template<
int DataLayout>
108 chip1 = tensor.
chip(1, 0);
113 for (
int i = 0; i < 3; ++i) {
114 for (
int j = 0; j < 5; ++j) {
115 for (
int k = 0; k < 7; ++k) {
116 for (
int l = 0; l < 11; ++l) {
117 VERIFY_IS_EQUAL(chip1(i,j,k,l), tensor(1,i,j,k,l));
128 for (
int i = 0; i < 2; ++i) {
129 for (
int j = 0; j < 3; ++j) {
130 for (
int k = 0; k < 7; ++k) {
131 for (
int l = 0; l < 11; ++l) {
132 VERIFY_IS_EQUAL(chip2(i,j,k,l), tensor(i,1,j,k,l));
143 for (
int i = 0; i < 2; ++i) {
144 for (
int j = 0; j < 3; ++j) {
145 for (
int k = 0; k < 7; ++k) {
146 for (
int l = 0; l < 11; ++l) {
147 VERIFY_IS_EQUAL(chip3(i,j,k,l), tensor(i,j,2,k,l));
154 VERIFY_IS_EQUAL(chip4.dimension(0), 2);
155 VERIFY_IS_EQUAL(chip4.dimension(1), 3);
156 VERIFY_IS_EQUAL(chip4.dimension(2), 5);
157 VERIFY_IS_EQUAL(chip4.dimension(3), 11);
158 for (
int i = 0; i < 2; ++i) {
159 for (
int j = 0; j < 3; ++j) {
160 for (
int k = 0; k < 5; ++k) {
161 for (
int l = 0; l < 7; ++l) {
162 VERIFY_IS_EQUAL(chip4(i,j,k,l), tensor(i,j,k,5,l));
169 VERIFY_IS_EQUAL(chip5.dimension(0), 2);
170 VERIFY_IS_EQUAL(chip5.dimension(1), 3);
171 VERIFY_IS_EQUAL(chip5.dimension(2), 5);
172 VERIFY_IS_EQUAL(chip5.dimension(3), 7);
173 for (
int i = 0; i < 2; ++i) {
174 for (
int j = 0; j < 3; ++j) {
175 for (
int k = 0; k < 5; ++k) {
176 for (
int l = 0; l < 7; ++l) {
177 VERIFY_IS_EQUAL(chip5(i,j,k,l), tensor(i,j,k,l,7));
184 template<
int DataLayout>
192 for (
int i = 0; i < 3; ++i) {
193 for (
int j = 0; j < 5; ++j) {
194 for (
int k = 0; k < 7; ++k) {
195 for (
int l = 0; l < 11; ++l) {
196 float expected = input1(0,i,j,k,l) + input2(i,j,k,l);
197 VERIFY_IS_EQUAL(result(i,j,k,l), expected);
206 for (
int i = 0; i < 3; ++i) {
207 for (
int j = 0; j < 7; ++j) {
208 for (
int k = 0; k < 11; ++k) {
209 float expected = input1(0,i,2,j,k) + input3(i,j,k);
210 VERIFY_IS_EQUAL(result2(i,j,k), expected);
216 template<
int DataLayout>
225 tensor.template chip<0>(1) = input2;
226 for (
int i = 0; i < 2; ++i) {
227 for (
int j = 0; j < 3; ++j) {
228 for (
int k = 0; k < 5; ++k) {
229 for (
int l = 0; l < 7; ++l) {
230 for (
int m = 0; m < 11; ++m) {
232 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
234 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input2(j,k,l,m));
245 tensor.template chip<1>(1) = input3;
246 for (
int i = 0; i < 2; ++i) {
247 for (
int j = 0; j < 3; ++j) {
248 for (
int k = 0; k < 5; ++k) {
249 for (
int l = 0; l < 7; ++l) {
250 for (
int m = 0; m < 11; ++m) {
252 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
254 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input3(i,k,l,m));
265 tensor.template chip<2>(3) = input4;
266 for (
int i = 0; i < 2; ++i) {
267 for (
int j = 0; j < 3; ++j) {
268 for (
int k = 0; k < 5; ++k) {
269 for (
int l = 0; l < 7; ++l) {
270 for (
int m = 0; m < 11; ++m) {
272 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
274 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input4(i,j,l,m));
285 tensor.template chip<3>(4) = input5;
286 for (
int i = 0; i < 2; ++i) {
287 for (
int j = 0; j < 3; ++j) {
288 for (
int k = 0; k < 5; ++k) {
289 for (
int l = 0; l < 7; ++l) {
290 for (
int m = 0; m < 11; ++m) {
292 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
294 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input5(i,j,k,m));
305 tensor.template chip<4>(5) = input6;
306 for (
int i = 0; i < 2; ++i) {
307 for (
int j = 0; j < 3; ++j) {
308 for (
int k = 0; k < 5; ++k) {
309 for (
int l = 0; l < 7; ++l) {
310 for (
int m = 0; m < 11; ++m) {
312 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
314 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input6(i,j,k,l));
325 tensor.
chip(0, 0) = input7.
chip(0, 0);
326 for (
int i = 0; i < 2; ++i) {
327 for (
int j = 0; j < 3; ++j) {
328 for (
int k = 0; k < 5; ++k) {
329 for (
int l = 0; l < 7; ++l) {
330 for (
int m = 0; m < 11; ++m) {
332 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input1(i,j,k,l,m));
334 VERIFY_IS_EQUAL(tensor(i,j,k,l,m), input7(i,j,k,l,m));
348 typedef TensorEvaluator<decltype(tensor.
chip<4>(3)), DefaultDevice> Evaluator4;
349 auto chip = Evaluator4(tensor.
chip<4>(3), DefaultDevice());
350 for (
int i = 0; i < 2; ++i) {
351 for (
int j = 0; j < 3; ++j) {
352 for (
int k = 0; k < 5; ++k) {
353 for (
int l = 0; l < 7; ++l) {
354 int chip_index = i + 2 * (j + 3 * (k + 5 * l));
355 VERIFY_IS_EQUAL(chip.data()[chip_index], tensor(i,j,k,l,3));
361 typedef TensorEvaluator<decltype(tensor.
chip<0>(0)), DefaultDevice> Evaluator0;
362 auto chip0 = Evaluator0(tensor.
chip<0>(0), DefaultDevice());
363 VERIFY_IS_EQUAL(chip0.data(),
static_cast<float*
>(0));
365 typedef TensorEvaluator<decltype(tensor.
chip<1>(0)), DefaultDevice> Evaluator1;
366 auto chip1 = Evaluator1(tensor.
chip<1>(0), DefaultDevice());
367 VERIFY_IS_EQUAL(chip1.data(),
static_cast<float*
>(0));
369 typedef TensorEvaluator<decltype(tensor.
chip<2>(0)), DefaultDevice> Evaluator2;
370 auto chip2 = Evaluator2(tensor.
chip<2>(0), DefaultDevice());
371 VERIFY_IS_EQUAL(chip2.data(),
static_cast<float*
>(0));
373 typedef TensorEvaluator<decltype(tensor.
chip<3>(0)), DefaultDevice> Evaluator3;
374 auto chip3 = Evaluator3(tensor.
chip<3>(0), DefaultDevice());
375 VERIFY_IS_EQUAL(chip3.data(),
static_cast<float*
>(0));
383 typedef TensorEvaluator<decltype(tensor.
chip<0>(3)), DefaultDevice> Evaluator0;
384 auto chip = Evaluator0(tensor.
chip<0>(3), DefaultDevice());
385 for (
int i = 0; i < 7; ++i) {
386 for (
int j = 0; j < 5; ++j) {
387 for (
int k = 0; k < 3; ++k) {
388 for (
int l = 0; l < 2; ++l) {
389 int chip_index = l + 2 * (k + 3 * (j + 5 * i));
390 VERIFY_IS_EQUAL(chip.data()[chip_index], tensor(3,i,j,k,l));
396 typedef TensorEvaluator<decltype(tensor.
chip<1>(0)), DefaultDevice> Evaluator1;
397 auto chip1 = Evaluator1(tensor.
chip<1>(0), DefaultDevice());
398 VERIFY_IS_EQUAL(chip1.data(),
static_cast<float*
>(0));
400 typedef TensorEvaluator<decltype(tensor.
chip<2>(0)), DefaultDevice> Evaluator2;
401 auto chip2 = Evaluator2(tensor.
chip<2>(0), DefaultDevice());
402 VERIFY_IS_EQUAL(chip2.data(),
static_cast<float*
>(0));
404 typedef TensorEvaluator<decltype(tensor.
chip<3>(0)), DefaultDevice> Evaluator3;
405 auto chip3 = Evaluator3(tensor.
chip<3>(0), DefaultDevice());
406 VERIFY_IS_EQUAL(chip3.data(),
static_cast<float*
>(0));
408 typedef TensorEvaluator<decltype(tensor.
chip<4>(0)), DefaultDevice> Evaluator4;
409 auto chip4 = Evaluator4(tensor.
chip<4>(0), DefaultDevice());
410 VERIFY_IS_EQUAL(chip4.data(),
static_cast<float*
>(0));
415 CALL_SUBTEST(test_simple_chip<ColMajor>());
416 CALL_SUBTEST(test_simple_chip<RowMajor>());
417 CALL_SUBTEST(test_dynamic_chip<ColMajor>());
418 CALL_SUBTEST(test_dynamic_chip<RowMajor>());
419 CALL_SUBTEST(test_chip_in_expr<ColMajor>());
420 CALL_SUBTEST(test_chip_in_expr<RowMajor>());
421 CALL_SUBTEST(test_chip_as_lvalue<ColMajor>());
422 CALL_SUBTEST(test_chip_as_lvalue<RowMajor>());
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static void test_dynamic_chip()
void test_cxx11_tensor_chipping()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
static void test_chip_in_expr()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorChippingOp< DimId, const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > chip(const Index offset) const
static void test_chip_as_lvalue()
static void test_chip_raw_data_col_major()
static void test_simple_chip()
static void test_chip_raw_data_row_major()