12 #include <Eigen/CXX11/Tensor> 20 TensorFixedSize<float, Sizes<> > scalar1;
21 TensorFixedSize<float, Sizes<>,
RowMajor> scalar2;
22 VERIFY_IS_EQUAL(scalar1.rank(), 0);
23 VERIFY_IS_EQUAL(scalar1.size(), 1);
24 VERIFY_IS_EQUAL(
array_prod(scalar1.dimensions()), 1);
30 TensorFixedSize<float, Sizes<> > copy = scalar1;
31 VERIFY_IS_NOT_EQUAL(scalar1.data(), copy.data());
32 VERIFY_IS_APPROX(scalar1(), copy());
34 VERIFY_IS_NOT_EQUAL(scalar1.data(), copy.data());
35 VERIFY_IS_APPROX(scalar1(), copy());
37 TensorFixedSize<float, Sizes<> > scalar3 = scalar1.sqrt();
38 TensorFixedSize<float, Sizes<>,
RowMajor> scalar4 = scalar2.sqrt();
39 VERIFY_IS_EQUAL(scalar3.rank(), 0);
40 VERIFY_IS_APPROX(scalar3(), sqrtf(7.0));
41 VERIFY_IS_APPROX(scalar4(), sqrtf(13.0));
43 scalar3 = scalar1 + scalar2;
44 VERIFY_IS_APPROX(scalar3(), 7.0
f + 13.0
f);
49 TensorFixedSize<float, Sizes<6> > vec1;
50 TensorFixedSize<float, Sizes<6>,
RowMajor> vec2;
52 VERIFY_IS_EQUAL((vec1.size()), 6);
56 vec1(0) = 4.0; vec2(0) = 0.0;
57 vec1(1) = 8.0; vec2(1) = 1.0;
58 vec1(2) = 15.0; vec2(2) = 2.0;
59 vec1(3) = 16.0; vec2(3) = 3.0;
60 vec1(4) = 23.0; vec2(4) = 4.0;
61 vec1(5) = 42.0; vec2(5) = 5.0;
64 TensorFixedSize<float, Sizes<6> > copy = vec1;
65 VERIFY_IS_NOT_EQUAL(vec1.data(), copy.data());
66 for (
int i = 0; i < 6; ++i) {
67 VERIFY_IS_APPROX(vec1(i), copy(i));
70 VERIFY_IS_NOT_EQUAL(vec1.data(), copy.data());
71 for (
int i = 0; i < 6; ++i) {
72 VERIFY_IS_APPROX(vec1(i), copy(i));
75 TensorFixedSize<float, Sizes<6> > vec3 = vec1.sqrt();
76 TensorFixedSize<float, Sizes<6>,
RowMajor> vec4 = vec2.sqrt();
78 VERIFY_IS_EQUAL((vec3.size()), 6);
79 VERIFY_IS_EQUAL(vec3.rank(), 1);
83 VERIFY_IS_APPROX(vec3(0), sqrtf(4.0));
84 VERIFY_IS_APPROX(vec3(1), sqrtf(8.0));
85 VERIFY_IS_APPROX(vec3(2), sqrtf(15.0));
86 VERIFY_IS_APPROX(vec3(3), sqrtf(16.0));
87 VERIFY_IS_APPROX(vec3(4), sqrtf(23.0));
88 VERIFY_IS_APPROX(vec3(5), sqrtf(42.0));
90 VERIFY_IS_APPROX(vec4(0), sqrtf(0.0));
91 VERIFY_IS_APPROX(vec4(1), sqrtf(1.0));
92 VERIFY_IS_APPROX(vec4(2), sqrtf(2.0));
93 VERIFY_IS_APPROX(vec4(3), sqrtf(3.0));
94 VERIFY_IS_APPROX(vec4(4), sqrtf(4.0));
95 VERIFY_IS_APPROX(vec4(5), sqrtf(5.0));
98 VERIFY_IS_APPROX(vec3(0), 4.0
f + 0.0
f);
99 VERIFY_IS_APPROX(vec3(1), 8.0
f + 1.0
f);
100 VERIFY_IS_APPROX(vec3(2), 15.0
f + 2.0
f);
101 VERIFY_IS_APPROX(vec3(3), 16.0
f + 3.0
f);
102 VERIFY_IS_APPROX(vec3(4), 23.0
f + 4.0
f);
103 VERIFY_IS_APPROX(vec3(5), 42.0
f + 5.0
f);
108 TensorFixedSize<float, Sizes<6> > vec1;
109 TensorFixedSize<float, Sizes<6>,
RowMajor> vec2;
111 vec1(0) = 4.0; vec2(0) = 0.0;
112 vec1(1) = 8.0; vec2(1) = 1.0;
113 vec1(2) = 15.0; vec2(2) = 2.0;
114 vec1(3) = 16.0; vec2(3) = 3.0;
115 vec1(4) = 23.0; vec2(4) = 4.0;
116 vec1(5) = 42.0; vec2(5) = 5.0;
119 TensorMap<TensorFixedSize<float, Sizes<6> > > vec3(data3, 6);
120 vec3 = vec1.sqrt() + vec2;
122 VERIFY_IS_APPROX(vec3(0), sqrtf(4.0));
123 VERIFY_IS_APPROX(vec3(1), sqrtf(8.0) + 1.0
f);
124 VERIFY_IS_APPROX(vec3(2), sqrtf(15.0) + 2.0
f);
125 VERIFY_IS_APPROX(vec3(3), sqrtf(16.0) + 3.0
f);
126 VERIFY_IS_APPROX(vec3(4), sqrtf(23.0) + 4.0
f);
127 VERIFY_IS_APPROX(vec3(5), sqrtf(42.0) + 5.0
f);
133 TensorMap<TensorFixedSize<float, Sizes<2, 3> > > mat1(data1,2,3);
135 TensorMap<TensorFixedSize<float, Sizes<2, 3>,
RowMajor> > mat2(data2,2,3);
137 VERIFY_IS_EQUAL((mat1.size()), 2*3);
138 VERIFY_IS_EQUAL(mat1.rank(), 2);
156 TensorFixedSize<float, Sizes<2, 3> > mat3;
157 TensorFixedSize<float, Sizes<2, 3>,
RowMajor> mat4;
161 VERIFY_IS_EQUAL((mat3.size()), 2*3);
165 VERIFY_IS_APPROX(mat3(0,0), 0.0
f);
166 VERIFY_IS_APPROX(mat3(0,1), 1.0
f);
167 VERIFY_IS_APPROX(mat3(0,2), 2.0
f);
168 VERIFY_IS_APPROX(mat3(1,0), 3.0
f);
169 VERIFY_IS_APPROX(mat3(1,1), 4.0
f);
170 VERIFY_IS_APPROX(mat3(1,2), 5.0
f);
172 VERIFY_IS_APPROX(mat4(0,0), 0.0
f);
173 VERIFY_IS_APPROX(mat4(0,1), 1.0
f);
174 VERIFY_IS_APPROX(mat4(0,2), 2.0
f);
175 VERIFY_IS_APPROX(mat4(1,0), 3.0
f);
176 VERIFY_IS_APPROX(mat4(1,1), 4.0
f);
177 VERIFY_IS_APPROX(mat4(1,2), 5.0
f);
182 TensorFixedSize<float, Sizes<2, 3, 7> > mat1;
183 TensorFixedSize<float, Sizes<2, 3, 7>,
RowMajor> mat2;
185 VERIFY_IS_EQUAL((mat1.size()), 2*3*7);
186 VERIFY_IS_EQUAL(mat1.rank(), 3);
192 for (
int i = 0; i < 2; ++i) {
193 for (
int j = 0; j < 3; ++j) {
194 for (
int k = 0; k < 7; ++k) {
202 TensorFixedSize<float, Sizes<2, 3, 7> > mat3;
204 TensorFixedSize<float, Sizes<2, 3, 7>,
RowMajor> mat4;
207 VERIFY_IS_EQUAL((mat3.size()), 2*3*7);
214 for (
int i = 0; i < 2; ++i) {
215 for (
int j = 0; j < 3; ++j) {
216 for (
int k = 0; k < 7; ++k) {
217 VERIFY_IS_APPROX(mat3(i,j,k), sqrtf(val));
218 VERIFY_IS_APPROX(mat4(i,j,k), sqrtf(val));
228 TensorFixedSize<float, Sizes<2, 3, 7> > mat1;
230 for (
int i = 0; i < 2; ++i) {
231 for (
int j = 0; j < 3; ++j) {
232 for (
int k = 0; k < 7; ++k) {
239 TensorFixedSize<float, Sizes<2, 3, 7> > mat3;
240 mat3 = mat1.pow(3.5
f);
243 for (
int i = 0; i < 2; ++i) {
244 for (
int j = 0; j < 3; ++j) {
245 for (
int k = 0; k < 7; ++k) {
246 VERIFY_IS_APPROX(mat3(i,j,k), powf(val, 3.5
f));
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE std::ptrdiff_t array_prod(const Sizes< Indices... > &)
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
static void test_tensor_map()
void test_cxx11_tensor_fixed_size()