gtsam
3rdparty
Eigen
unsupported
test
cxx11_tensor_move.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) 2017 Viktor Csomor <viktor.csomor@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
#include <utility>
14
15
using
Eigen::Tensor
;
16
using
Eigen::RowMajor
;
17
18
static
void
calc_indices
(
int
i
,
int
&
x
,
int
&
y
,
int
&
z
)
19
{
20
x = i / 4;
21
y = (i % 4) / 2;
22
z = i % 2;
23
}
24
25
static
void
test_move
()
26
{
27
int
x
;
28
int
y
;
29
int
z
;
30
31
Tensor<int,3>
tensor1(2, 2, 2);
32
Tensor<int,3,RowMajor>
tensor2(2, 2, 2);
33
34
for
(
int
i
= 0;
i
< 8;
i
++)
35
{
36
calc_indices
(
i
, x, y, z);
37
tensor1(x,y,z) =
i
;
38
tensor2(x,y,z) = 2 *
i
;
39
}
40
41
// Invokes the move constructor.
42
Tensor<int,3>
moved_tensor1 = std::move(tensor1);
43
Tensor<int,3,RowMajor>
moved_tensor2 = std::move(tensor2);
44
45
VERIFY_IS_EQUAL
(tensor1.
size
(), 0);
46
VERIFY_IS_EQUAL
(tensor2.
size
(), 0);
47
48
for
(
int
i
= 0;
i
< 8;
i
++)
49
{
50
calc_indices
(
i
, x, y, z);
51
VERIFY_IS_EQUAL
(moved_tensor1(x,y,z),
i
);
52
VERIFY_IS_EQUAL
(moved_tensor2(x,y,z), 2 *
i
);
53
}
54
55
Tensor<int,3>
moved_tensor3(2,2,2);
56
Tensor<int,3,RowMajor>
moved_tensor4(2,2,2);
57
58
moved_tensor3.
setZero
();
59
moved_tensor4.
setZero
();
60
61
// Invokes the move assignment operator.
62
moved_tensor3 = std::move(moved_tensor1);
63
moved_tensor4 = std::move(moved_tensor2);
64
65
for
(
int
i
= 0;
i
< 8;
i
++)
66
{
67
calc_indices
(
i
, x, y, z);
68
VERIFY_IS_EQUAL
(moved_tensor3(x,y,z),
i
);
69
VERIFY_IS_EQUAL
(moved_tensor4(x,y,z), 2 *
i
);
70
}
71
}
72
73
EIGEN_DECLARE_TEST
(cxx11_tensor_move)
74
{
75
CALL_SUBTEST
(
test_move
());
76
}
calc_indices
static void calc_indices(int i, int &x, int &y, int &z)
Definition:
cxx11_tensor_move.cpp:18
Eigen::Tensor::size
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Index size() const
Definition:
Tensor.h:103
EIGEN_DECLARE_TEST
EIGEN_DECLARE_TEST(cxx11_tensor_move)
Definition:
cxx11_tensor_move.cpp:73
y
Scalar * y
Definition:
level1_cplx_impl.h:124
test_move
static void test_move()
Definition:
cxx11_tensor_move.cpp:25
main.h
VERIFY_IS_EQUAL
#define VERIFY_IS_EQUAL(a, b)
Definition:
main.h:386
CALL_SUBTEST
#define CALL_SUBTEST(FUNC)
Definition:
main.h:399
Eigen::RowMajor
Definition:
Constants.h:321
pybind_wrapper_test_script.z
z
Definition:
pybind_wrapper_test_script.py:61
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition:
gnuplot_common_settings.hh:12
i
int i
Definition:
BiCGSTAB_step_by_step.cpp:9
Eigen::TensorBase< Tensor< Scalar_, NumIndices_, Options_, IndexType_ > >::setZero
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE Tensor< Scalar_, NumIndices_, Options_, IndexType_ > & setZero()
Definition:
TensorBase.h:988
Eigen::Tensor
The tensor class.
Definition:
Tensor.h:63
gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:08