12 #include <Eigen/CXX11/Tensor> 22 TensorMap<Tensor<const int, 0> > scalar3(scalar1.
data());
23 TensorMap<Tensor<const int, 0, RowMajor> > scalar4(scalar2.
data());
28 VERIFY_IS_EQUAL(scalar1.
rank(), 0);
29 VERIFY_IS_EQUAL(scalar1.
size(), 1);
31 VERIFY_IS_EQUAL(scalar3(), 7);
32 VERIFY_IS_EQUAL(scalar4(), 13);
40 TensorMap<Tensor<const int, 1> > vec3(vec1.
data(), 6);
41 TensorMap<Tensor<const int, 1, RowMajor> > vec4(vec2.
data(), 6);
43 vec1(0) = 4; vec2(0) = 0;
44 vec1(1) = 8; vec2(1) = 1;
45 vec1(2) = 15; vec2(2) = 2;
46 vec1(3) = 16; vec2(3) = 3;
47 vec1(4) = 23; vec2(4) = 4;
48 vec1(5) = 42; vec2(5) = 5;
50 VERIFY_IS_EQUAL(vec1.
rank(), 1);
51 VERIFY_IS_EQUAL(vec1.
size(), 6);
54 VERIFY_IS_EQUAL(vec3(0), 4);
55 VERIFY_IS_EQUAL(vec3(1), 8);
56 VERIFY_IS_EQUAL(vec3(2), 15);
57 VERIFY_IS_EQUAL(vec3(3), 16);
58 VERIFY_IS_EQUAL(vec3(4), 23);
59 VERIFY_IS_EQUAL(vec3(5), 42);
61 VERIFY_IS_EQUAL(vec4(0), 0);
62 VERIFY_IS_EQUAL(vec4(1), 1);
63 VERIFY_IS_EQUAL(vec4(2), 2);
64 VERIFY_IS_EQUAL(vec4(3), 3);
65 VERIFY_IS_EQUAL(vec4(4), 4);
66 VERIFY_IS_EQUAL(vec4(5), 5);
88 TensorMap<Tensor<const int, 2> > mat3(mat1.
data(), 2, 3);
89 TensorMap<Tensor<const int, 2, RowMajor> > mat4(mat2.
data(), 2, 3);
91 VERIFY_IS_EQUAL(mat3.rank(), 2);
92 VERIFY_IS_EQUAL(mat3.size(), 6);
93 VERIFY_IS_EQUAL(mat3.dimension(0), 2);
94 VERIFY_IS_EQUAL(mat3.dimension(1), 3);
96 VERIFY_IS_EQUAL(mat4.rank(), 2);
97 VERIFY_IS_EQUAL(mat4.size(), 6);
98 VERIFY_IS_EQUAL(mat4.dimension(0), 2);
99 VERIFY_IS_EQUAL(mat4.dimension(1), 3);
101 VERIFY_IS_EQUAL(mat3(0,0), 0);
102 VERIFY_IS_EQUAL(mat3(0,1), 1);
103 VERIFY_IS_EQUAL(mat3(0,2), 2);
104 VERIFY_IS_EQUAL(mat3(1,0), 3);
105 VERIFY_IS_EQUAL(mat3(1,1), 4);
106 VERIFY_IS_EQUAL(mat3(1,2), 5);
108 VERIFY_IS_EQUAL(mat4(0,0), 0);
109 VERIFY_IS_EQUAL(mat4(0,1), 1);
110 VERIFY_IS_EQUAL(mat4(0,2), 2);
111 VERIFY_IS_EQUAL(mat4(1,0), 3);
112 VERIFY_IS_EQUAL(mat4(1,1), 4);
113 VERIFY_IS_EQUAL(mat4(1,2), 5);
122 for (
int i = 0; i < 2; ++i) {
123 for (
int j = 0; j < 3; ++j) {
124 for (
int k = 0; k < 7; ++k) {
132 TensorMap<Tensor<const int, 3> > mat3(mat1.
data(), 2, 3, 7);
133 TensorMap<Tensor<const int, 3, RowMajor> > mat4(mat2.
data(), 2, 3, 7);
135 VERIFY_IS_EQUAL(mat3.rank(), 3);
136 VERIFY_IS_EQUAL(mat3.size(), 2*3*7);
137 VERIFY_IS_EQUAL(mat3.dimension(0), 2);
138 VERIFY_IS_EQUAL(mat3.dimension(1), 3);
139 VERIFY_IS_EQUAL(mat3.dimension(2), 7);
141 VERIFY_IS_EQUAL(mat4.rank(), 3);
142 VERIFY_IS_EQUAL(mat4.size(), 2*3*7);
143 VERIFY_IS_EQUAL(mat4.dimension(0), 2);
144 VERIFY_IS_EQUAL(mat4.dimension(1), 3);
145 VERIFY_IS_EQUAL(mat4.dimension(2), 7);
148 for (
int i = 0; i < 2; ++i) {
149 for (
int j = 0; j < 3; ++j) {
150 for (
int k = 0; k < 7; ++k) {
151 VERIFY_IS_EQUAL(mat3(i,j,k), val);
152 VERIFY_IS_EQUAL(mat4(i,j,k), val);
166 for (
int i = 0; i < 2; ++i) {
167 for (
int j = 0; j < 3; ++j) {
168 for (
int k = 0; k < 7; ++k) {
176 TensorMap<Tensor<int, 3> > mat3(mat1);
177 TensorMap<Tensor<int, 3, RowMajor> > mat4(mat2);
179 VERIFY_IS_EQUAL(mat3.rank(), 3);
180 VERIFY_IS_EQUAL(mat3.size(), 2*3*7);
181 VERIFY_IS_EQUAL(mat3.dimension(0), 2);
182 VERIFY_IS_EQUAL(mat3.dimension(1), 3);
183 VERIFY_IS_EQUAL(mat3.dimension(2), 7);
185 VERIFY_IS_EQUAL(mat4.rank(), 3);
186 VERIFY_IS_EQUAL(mat4.size(), 2*3*7);
187 VERIFY_IS_EQUAL(mat4.dimension(0), 2);
188 VERIFY_IS_EQUAL(mat4.dimension(1), 3);
189 VERIFY_IS_EQUAL(mat4.dimension(2), 7);
192 for (
int i = 0; i < 2; ++i) {
193 for (
int j = 0; j < 3; ++j) {
194 for (
int k = 0; k < 7; ++k) {
195 VERIFY_IS_EQUAL(mat3(i,j,k), val);
196 VERIFY_IS_EQUAL(mat4(i,j,k), val);
202 TensorFixedSize<int, Sizes<2,3,7> > mat5;
205 for (
int i = 0; i < 2; ++i) {
206 for (
int j = 0; j < 3; ++j) {
207 for (
int k = 0; k < 7; ++k) {
208 array<ptrdiff_t, 3> coords;
218 TensorMap<TensorFixedSize<int, Sizes<2,3,7> > > mat6(mat5);
220 VERIFY_IS_EQUAL(mat6.rank(), 3);
221 VERIFY_IS_EQUAL(mat6.size(), 2*3*7);
222 VERIFY_IS_EQUAL(mat6.dimension(0), 2);
223 VERIFY_IS_EQUAL(mat6.dimension(1), 3);
224 VERIFY_IS_EQUAL(mat6.dimension(2), 7);
227 for (
int i = 0; i < 2; ++i) {
228 for (
int j = 0; j < 3; ++j) {
229 for (
int k = 0; k < 7; ++k) {
230 VERIFY_IS_EQUAL(mat6(i,j,k), val);
240 EIGEN_STATIC_ASSERT((internal::array_size<Sizes<> >::value == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
241 EIGEN_STATIC_ASSERT((internal::array_size<DSizes<int, 0> >::value == 0), YOU_MADE_A_PROGRAMMING_MISTAKE);
251 for (
int i = 0; i < 2; ++i) {
252 for (
int j = 0; j < 3; ++j) {
253 for (
int k = 0; k < 7; ++k) {
260 TensorMap<Tensor<int, 3> > map(tensor);
262 int sum2 =
f(tensor);
264 VERIFY_IS_EQUAL(sum1, sum2);
265 VERIFY_IS_EQUAL(sum1, 861);
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
#define EIGEN_STATIC_ASSERT(CONDITION, MSG)
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index rank() const
static void test_from_tensor()
void test_cxx11_tensor_map()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
static void test_casting()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const