gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_mixed_indices.cpp
Go to the documentation of this file.
1
// This file is part of Eigen, a lightweight C++ template library
2
// for linear algebra.
3
//
4
// Copyright (C) 2014 Benoit Steiner <benoit.steiner.goog@gmail.com>
5
//
6
// This Source Code Form is subject to the terms of the Mozilla
7
// Public License v. 2.0. If a copy of the MPL was not distributed
8
// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10
#include "
main.h
"
11
12
#include <Eigen/CXX11/Tensor>
13
14
15
static
void
test_simple
()
16
{
17
Tensor<float, 1, ColMajor>
vec1
(6);
18
Tensor<float, 1, ColMajor, int>
vec2(6);
19
20
vec1
(0) = 4.0; vec2(0) = 0.0;
21
vec1
(1) = 8.0; vec2(1) = 1.0;
22
vec1
(2) = 15.0; vec2(2) = 2.0;
23
vec1
(3) = 16.0; vec2(3) = 3.0;
24
vec1
(4) = 23.0; vec2(4) = 4.0;
25
vec1
(5) = 42.0; vec2(5) = 5.0;
26
27
float
data3[6];
28
TensorMap<Tensor<float, 1, ColMajor>
>
vec3
(data3, 6);
29
vec3 = vec1.sqrt();
30
float
data4[6];
31
TensorMap<Tensor<float, 1, ColMajor, int>
>
vec4
(data4, 6);
32
vec4 = vec2.square();
33
34
VERIFY_IS_APPROX
(
vec3
(0), sqrtf(4.0));
35
VERIFY_IS_APPROX
(
vec3
(1), sqrtf(8.0));
36
VERIFY_IS_APPROX
(
vec3
(2), sqrtf(15.0));
37
VERIFY_IS_APPROX
(
vec3
(3), sqrtf(16.0));
38
VERIFY_IS_APPROX
(
vec3
(4), sqrtf(23.0));
39
VERIFY_IS_APPROX
(
vec3
(5), sqrtf(42.0));
40
41
VERIFY_IS_APPROX
(
vec4
(0), 0.0
f
);
42
VERIFY_IS_APPROX
(
vec4
(1), 1.0
f
);
43
VERIFY_IS_APPROX
(
vec4
(2), 2.0
f
* 2.0
f
);
44
VERIFY_IS_APPROX
(
vec4
(3), 3.0f * 3.0f);
45
VERIFY_IS_APPROX
(
vec4
(4), 4.0f * 4.0f);
46
VERIFY_IS_APPROX
(
vec4
(5), 5.0f * 5.0f);
47
}
48
49
50
EIGEN_DECLARE_TEST
(cxx11_tensor_mixed_indices)
51
{
52
CALL_SUBTEST
(
test_simple
());
53
}
main.h
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_mixed_indices)
Definition:
cxx11_tensor_mixed_indices.cpp:50
VERIFY_IS_APPROX
#define VERIFY_IS_APPROX(a, b)
Definition:
integer_types.cpp:15
Eigen::TensorMap
A tensor expression mapping an existing array of data.
Definition:
TensorForwardDeclarations.h:52
tree::f
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
Definition:
testExpression.cpp:218
gtsam::vec4
static SO4::VectorN2 vec4(const Matrix4 &Q)
Definition:
SO4.cpp:140
test_simple
static void test_simple()
Definition:
cxx11_tensor_mixed_indices.cpp:15
vec1
RowVectorXd vec1(3)
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
gtsam::vec3
static Vector9 vec3(const Matrix3 &R)
Definition:
SO3.cpp:342
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:08