Main Page
Related Pages
Modules
Namespaces
Classes
Files
Examples
File List
File Members
gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_layout_swap.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
using
Eigen::Tensor
;
15
16
static
void
test_simple_swap
()
17
{
18
Tensor<float, 3, ColMajor>
tensor(2,3,7);
19
tensor.
setRandom
();
20
21
Tensor<float, 3, RowMajor>
tensor2 = tensor.
swap_layout
();
22
VERIFY_IS_EQUAL
(tensor.
dimension
(0), tensor2.
dimension
(2));
23
VERIFY_IS_EQUAL
(tensor.
dimension
(1), tensor2.
dimension
(1));
24
VERIFY_IS_EQUAL
(tensor.
dimension
(2), tensor2.
dimension
(0));
25
26
for
(
int
i
= 0;
i
< 2; ++
i
) {
27
for
(
int
j
= 0;
j
< 3; ++
j
) {
28
for
(
int
k = 0; k < 7; ++k) {
29
VERIFY_IS_EQUAL
(tensor(
i
,
j
,k), tensor2(k,
j
,
i
));
30
}
31
}
32
}
33
}
34
35
36
static
void
test_swap_as_lvalue
()
37
{
38
Tensor<float, 3, ColMajor>
tensor(2,3,7);
39
tensor.
setRandom
();
40
41
Tensor<float, 3, RowMajor>
tensor2(7,3,2);
42
tensor2.
swap_layout
() = tensor;
43
VERIFY_IS_EQUAL
(tensor.
dimension
(0), tensor2.
dimension
(2));
44
VERIFY_IS_EQUAL
(tensor.
dimension
(1), tensor2.
dimension
(1));
45
VERIFY_IS_EQUAL
(tensor.
dimension
(2), tensor2.
dimension
(0));
46
47
for
(
int
i
= 0;
i
< 2; ++
i
) {
48
for
(
int
j
= 0;
j
< 3; ++
j
) {
49
for
(
int
k = 0; k < 7; ++k) {
50
VERIFY_IS_EQUAL
(tensor(
i
,
j
,k), tensor2(k,
j
,
i
));
51
}
52
}
53
}
54
}
55
56
57
void
test_cxx11_tensor_layout_swap
()
58
{
59
CALL_SUBTEST
(
test_simple_swap
());
60
CALL_SUBTEST
(
test_swap_as_lvalue
());
61
}
test_swap_as_lvalue
static void test_swap_as_lvalue()
Definition:
cxx11_tensor_layout_swap.cpp:36
Eigen::Tensor::dimension
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index dimension(std::size_t n) const
Definition:
Tensor.h:101
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::setRandom
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setRandom()
Definition:
TensorBase.h:850
main.h
test_simple_swap
static void test_simple_swap()
Definition:
cxx11_tensor_layout_swap.cpp:16
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:331
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::swap_layout
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE const TensorLayoutSwapOp< const Tensor< Scalar_, NumIndices_, Options_, IndexType_ > > swap_layout() const
Definition:
TensorBase.h:887
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:342
test_cxx11_tensor_layout_swap
void test_cxx11_tensor_layout_swap()
Definition:
cxx11_tensor_layout_swap.cpp:57
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
j
std::ptrdiff_t j
Definition:
tut_arithmetic_redux_minmax.cpp:2
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
gtsam
Author(s):
autogenerated on Sat May 8 2021 02:41:55