cxx11_tensor_inflation.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>

Functions

template<int DataLayout>
static void test_simple_inflation ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_inflation)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_inflation  )
72  {
73  CALL_SUBTEST(test_simple_inflation<ColMajor>());
74  CALL_SUBTEST(test_simple_inflation<RowMajor>());
75 }
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST.

◆ test_simple_inflation()

template<int DataLayout>
static void test_simple_inflation ( )
static
17  {
18  Tensor<float, 4, DataLayout> tensor(2, 3, 5, 7);
19  tensor.setRandom();
21 
22  strides[0] = 1;
23  strides[1] = 1;
24  strides[2] = 1;
25  strides[3] = 1;
26 
28  no_stride = tensor.inflate(strides);
29 
30  VERIFY_IS_EQUAL(no_stride.dimension(0), 2);
31  VERIFY_IS_EQUAL(no_stride.dimension(1), 3);
32  VERIFY_IS_EQUAL(no_stride.dimension(2), 5);
33  VERIFY_IS_EQUAL(no_stride.dimension(3), 7);
34 
35  for (int i = 0; i < 2; ++i) {
36  for (int j = 0; j < 3; ++j) {
37  for (int k = 0; k < 5; ++k) {
38  for (int l = 0; l < 7; ++l) {
39  VERIFY_IS_EQUAL(tensor(i, j, k, l), no_stride(i, j, k, l));
40  }
41  }
42  }
43  }
44 
45  strides[0] = 2;
46  strides[1] = 4;
47  strides[2] = 2;
48  strides[3] = 3;
50  inflated = tensor.inflate(strides);
51 
52  VERIFY_IS_EQUAL(inflated.dimension(0), 3);
53  VERIFY_IS_EQUAL(inflated.dimension(1), 9);
54  VERIFY_IS_EQUAL(inflated.dimension(2), 9);
55  VERIFY_IS_EQUAL(inflated.dimension(3), 19);
56 
57  for (int i = 0; i < 3; ++i) {
58  for (int j = 0; j < 9; ++j) {
59  for (int k = 0; k < 9; ++k) {
60  for (int l = 0; l < 19; ++l) {
61  if (i % 2 == 0 && j % 4 == 0 && k % 2 == 0 && l % 3 == 0) {
62  VERIFY_IS_EQUAL(inflated(i, j, k, l), tensor(i / 2, j / 4, k / 2, l / 3));
63  } else {
64  VERIFY_IS_EQUAL(0, inflated(i, j, k, l));
65  }
66  }
67  }
68  }
69  }
70 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
The tensor class.
Definition: Tensor.h:68
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
Definition: Tensor.h:99
char char char int int * k
Definition: level2_impl.h:374
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
EIGEN_ALWAYS_INLINE DSizes< IndexType, NumDims > strides(const DSizes< IndexType, NumDims > &dimensions)
Definition: TensorBlock.h:29
std::array< T, N > array
Definition: EmulateArray.h:231
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::dimension(), i, j, k, Eigen::TensorBase< Derived, AccessLevel >::setRandom(), Eigen::internal::strides(), and VERIFY_IS_EQUAL.