12 #include <Eigen/CXX11/Tensor> 22 vec1(0) = 4.0; vec2(0) = 0.0;
23 vec1(1) = 8.0; vec2(1) = 1.0;
24 vec1(2) = 15.0; vec2(2) = 2.0;
25 vec1(3) = 16.0; vec2(3) = 3.0;
26 vec1(4) = 23.0; vec2(4) = 4.0;
27 vec1(5) = 42.0; vec2(5) = 5.0;
30 TensorMap<Tensor<float, 1>> vec3(data3, 6);
33 TensorMap<Tensor<float, 1, RowMajor>> vec4(data4, 6);
36 TensorMap<Tensor<float, 1, RowMajor>> vec5(data5, 6);
39 VERIFY_IS_APPROX(vec3(0), sqrtf(4.0));
40 VERIFY_IS_APPROX(vec3(1), sqrtf(8.0));
41 VERIFY_IS_APPROX(vec3(2), sqrtf(15.0));
42 VERIFY_IS_APPROX(vec3(3), sqrtf(16.0));
43 VERIFY_IS_APPROX(vec3(4), sqrtf(23.0));
44 VERIFY_IS_APPROX(vec3(5), sqrtf(42.0));
46 VERIFY_IS_APPROX(vec4(0), 0.0
f);
47 VERIFY_IS_APPROX(vec4(1), 1.0
f);
48 VERIFY_IS_APPROX(vec4(2), 2.0
f * 2.0
f);
49 VERIFY_IS_APPROX(vec4(3), 3.0f * 3.0f);
50 VERIFY_IS_APPROX(vec4(4), 4.0f * 4.0f);
51 VERIFY_IS_APPROX(vec4(5), 5.0f * 5.0f);
53 VERIFY_IS_APPROX(vec5(0), 0.0f);
54 VERIFY_IS_APPROX(vec5(1), 1.0f);
55 VERIFY_IS_APPROX(vec5(2), 2.0f * 2.0f * 2.0f);
56 VERIFY_IS_APPROX(vec5(3), 3.0f * 3.0f * 3.0f);
57 VERIFY_IS_APPROX(vec5(4), 4.0f * 4.0f * 4.0f);
58 VERIFY_IS_APPROX(vec5(5), 5.0f * 5.0f * 5.0f);
61 VERIFY_IS_APPROX(vec3(0), 4.0f + 0.0f);
62 VERIFY_IS_APPROX(vec3(1), 8.0f + 1.0f);
63 VERIFY_IS_APPROX(vec3(2), 15.0f + 2.0f);
64 VERIFY_IS_APPROX(vec3(3), 16.0f + 3.0f);
65 VERIFY_IS_APPROX(vec3(4), 23.0f + 4.0f);
66 VERIFY_IS_APPROX(vec3(5), 42.0f + 5.0f);
72 TensorMap<Tensor<float, 2>> mat1(data1, 2, 3);
74 TensorMap<Tensor<float, 2, RowMajor>> mat2(data2, 2, 3);
95 VERIFY_IS_APPROX(mat3(0,0), 0.0
f);
96 VERIFY_IS_APPROX(mat3(0,1), 1.0
f);
97 VERIFY_IS_APPROX(mat3(0,2), 2.0
f);
98 VERIFY_IS_APPROX(mat3(1,0), 3.0
f);
99 VERIFY_IS_APPROX(mat3(1,1), 4.0
f);
100 VERIFY_IS_APPROX(mat3(1,2), 5.0
f);
102 VERIFY_IS_APPROX(mat4(0,0), 0.0
f);
103 VERIFY_IS_APPROX(mat4(0,1), 1.0
f);
104 VERIFY_IS_APPROX(mat4(0,2), 2.0
f);
105 VERIFY_IS_APPROX(mat4(1,0), 3.0
f);
106 VERIFY_IS_APPROX(mat4(1,1), 4.0
f);
107 VERIFY_IS_APPROX(mat4(1,2), 5.0
f);
116 for (
int i = 0; i < 2; ++i) {
117 for (
int j = 0; j < 3; ++j) {
118 for (
int k = 0; k < 7; ++k) {
131 mat5 = mat1.inverse().log();
133 mat6 = mat2.pow(0.5
f) * 3.14f;
135 mat7 = mat1.cwiseMax(mat5 * 2.0
f).exp();
137 mat8 = (-mat2).
exp() * 3.14f;
141 mat10 = mat2 - 3.14f;
143 mat11 = mat2 / 3.14f;
146 for (
int i = 0; i < 2; ++i) {
147 for (
int j = 0; j < 3; ++j) {
148 for (
int k = 0; k < 7; ++k) {
149 VERIFY_IS_APPROX(mat3(i,j,k), val + val);
150 VERIFY_IS_APPROX(mat4(i,j,k), val * 3.14f);
151 VERIFY_IS_APPROX(mat5(i,j,k), logf(1.0f/val));
152 VERIFY_IS_APPROX(mat6(i,j,k), sqrtf(val) * 3.14f);
153 VERIFY_IS_APPROX(mat7(i,j,k), expf((
std::max)(val, mat5(i,j,k) * 2.0f)));
154 VERIFY_IS_APPROX(mat8(i,j,k), expf(-val) * 3.14f);
155 VERIFY_IS_APPROX(mat9(i,j,k), val + 3.14f);
156 VERIFY_IS_APPROX(mat10(i,j,k), val - 3.14f);
157 VERIFY_IS_APPROX(mat11(i,j,k), val / 3.14f);
171 for (
int i = 0; i < 2; ++i) {
172 for (
int j = 0; j < 3; ++j) {
173 for (
int k = 0; k < 7; ++k) {
179 mat2 = mat1.constant(3.14
f);
180 mat3 = mat1.cwiseMax(7.3
f).exp();
183 for (
int i = 0; i < 2; ++i) {
184 for (
int j = 0; j < 3; ++j) {
185 for (
int k = 0; k < 7; ++k) {
186 VERIFY_IS_APPROX(mat2(i,j,k), 3.14
f);
187 VERIFY_IS_APPROX(mat3(i,j,k), expf((
std::max)(val, 7.3
f)));
197 std::copy_n(std::begin({0, 1, 2, 3, 4, 5}), 6, vec.
data());
200 Tensor<bool, 1> bool1 = vec < vec.constant(1) || vec > vec.constant(4);
201 VERIFY_IS_EQUAL(bool1[0],
true);
202 VERIFY_IS_EQUAL(bool1[1],
false);
203 VERIFY_IS_EQUAL(bool1[2],
false);
204 VERIFY_IS_EQUAL(bool1[3],
false);
205 VERIFY_IS_EQUAL(bool1[4],
false);
206 VERIFY_IS_EQUAL(bool1[5],
true);
210 VERIFY_IS_EQUAL(bool2[0],
false);
211 VERIFY_IS_EQUAL(bool2[1],
true);
212 VERIFY_IS_EQUAL(bool2[2],
true);
213 VERIFY_IS_EQUAL(bool2[3],
true);
214 VERIFY_IS_EQUAL(bool2[4],
false);
215 VERIFY_IS_EQUAL(bool2[5],
false);
222 bool3 = vec < vec.constant(4) && bool2;
232 for (
int i = 0; i < 2; ++i) {
233 for (
int j = 0; j < 3; ++j) {
234 for (
int k = 0; k < 7; ++k) {
240 mat2 = mat1.inverse().unaryExpr(&asinf);
241 mat3 = mat1.unaryExpr(&tanhf);
244 for (
int i = 0; i < 2; ++i) {
245 for (
int j = 0; j < 3; ++j) {
246 for (
int k = 0; k < 7; ++k) {
247 VERIFY_IS_APPROX(mat2(i,j,k), asinf(1.0
f / mat1(i,j,k)));
248 VERIFY_IS_APPROX(mat3(i,j,k), tanhf(mat1(i,j,k)));
263 mat3 = mat1.cast<
double>();
264 for (
int i = 0; i < 2; ++i) {
265 for (
int j = 0; j < 3; ++j) {
266 for (
int k = 0; k < 7; ++k) {
267 VERIFY_IS_APPROX(mat3(i,j,k), mat1(i,j,k) ? 1.0 : 0.0);
272 mat3 = mat2.cast<
double>();
273 for (
int i = 0; i < 2; ++i) {
274 for (
int j = 0; j < 3; ++j) {
275 for (
int k = 0; k < 7; ++k) {
276 VERIFY_IS_APPROX(mat3(i,j,k), static_cast<double>(mat2(i,j,k)));
292 result = (selector > selector.constant(0.5
f)).select(mat1, mat2);
294 for (
int i = 0; i < 2; ++i) {
295 for (
int j = 0; j < 3; ++j) {
296 for (
int k = 0; k < 7; ++k) {
297 VERIFY_IS_APPROX(result(i,j,k), (selector(i,j,k) > 0.5
f) ? mat1(i,j,k) : mat2(i,j,k));
static void test_type_casting()
static void test_functors()
EIGEN_DEVICE_FUNC const ExpReturnType exp() const
static void test_select()
static int f(const TensorMap< Tensor< int, 3 > > &tensor)
void test_cxx11_tensor_expr()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
static void test_constants()
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Scalar * data()
static void test_boolean()