cxx11_tensor_move.cpp File Reference
#include "main.h"
#include <Eigen/CXX11/Tensor>
#include <utility>

Functions

static void calc_indices (int i, int &x, int &y, int &z)
 
static void test_move ()
 
 EIGEN_DECLARE_TEST (cxx11_tensor_move)
 

Function Documentation

◆ calc_indices()

static void calc_indices ( int  i,
int x,
int y,
int z 
)
static
18  {
19  x = i / 4;
20  y = (i % 4) / 2;
21  z = i % 2;
22 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Scalar * y
Definition: level1_cplx_impl.h:128
list x
Definition: plotDoE.py:28

References i, plotDoE::x, and y.

Referenced by test_move().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( cxx11_tensor_move  )
68 { CALL_SUBTEST(test_move()); }
static void test_move()
Definition: cxx11_tensor_move.cpp:24
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, and test_move().

◆ test_move()

static void test_move ( )
static
24  {
25  int x;
26  int y;
27  int z;
28 
29  Tensor<int, 3> tensor1(2, 2, 2);
30  Tensor<int, 3, RowMajor> tensor2(2, 2, 2);
31 
32  for (int i = 0; i < 8; i++) {
33  calc_indices(i, x, y, z);
34  tensor1(x, y, z) = i;
35  tensor2(x, y, z) = 2 * i;
36  }
37 
38  // Invokes the move constructor.
39  Tensor<int, 3> moved_tensor1 = std::move(tensor1);
40  Tensor<int, 3, RowMajor> moved_tensor2 = std::move(tensor2);
41 
42  VERIFY_IS_EQUAL(tensor1.size(), 0);
43  VERIFY_IS_EQUAL(tensor2.size(), 0);
44 
45  for (int i = 0; i < 8; i++) {
46  calc_indices(i, x, y, z);
47  VERIFY_IS_EQUAL(moved_tensor1(x, y, z), i);
48  VERIFY_IS_EQUAL(moved_tensor2(x, y, z), 2 * i);
49  }
50 
51  Tensor<int, 3> moved_tensor3(2, 2, 2);
52  Tensor<int, 3, RowMajor> moved_tensor4(2, 2, 2);
53 
54  moved_tensor3.setZero();
55  moved_tensor4.setZero();
56 
57  // Invokes the move assignment operator.
58  moved_tensor3 = std::move(moved_tensor1);
59  moved_tensor4 = std::move(moved_tensor2);
60 
61  for (int i = 0; i < 8; i++) {
62  calc_indices(i, x, y, z);
63  VERIFY_IS_EQUAL(moved_tensor3(x, y, z), i);
64  VERIFY_IS_EQUAL(moved_tensor4(x, y, z), 2 * i);
65  }
66 }
The tensor class.
Definition: Tensor.h:68
static void calc_indices(int i, int &x, int &y, int &z)
Definition: cxx11_tensor_move.cpp:18
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367

References calc_indices(), i, Eigen::TensorBase< Derived, AccessLevel >::setZero(), Eigen::Tensor< Scalar_, NumIndices_, Options_, IndexType_ >::size(), VERIFY_IS_EQUAL, plotDoE::x, and y.

Referenced by EIGEN_DECLARE_TEST().