rvalue_types.cpp File Reference
#include "main.h"
#include "MovableScalar.h"
#include "SafeScalar.h"
#include <Eigen/Core>

Macros

#define EIGEN_RUNTIME_NO_MALLOC
 

Functions

template<typename MatrixType >
void rvalue_copyassign (const MatrixType &m)
 
template<typename TranspositionsType >
void rvalue_transpositions (Index rows)
 
template<typename MatrixType >
void rvalue_move (const MatrixType &m)
 
 EIGEN_DECLARE_TEST (rvalue_types)
 

Macro Definition Documentation

◆ EIGEN_RUNTIME_NO_MALLOC

#define EIGEN_RUNTIME_NO_MALLOC

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( rvalue_types  )
107  {
108  for (int i = 0; i < g_repeat; i++) {
109  CALL_SUBTEST_1(rvalue_copyassign(MatrixXf::Random(50, 50).eval()));
110  CALL_SUBTEST_1(rvalue_copyassign(ArrayXXf::Random(50, 50).eval()));
111 
114 
117 
121 
125 
127  internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
129  internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
133  internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
134 
138  }
139 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:48
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Represents a sequence of transpositions (row/column interchange)
Definition: Transpositions.h:141
Definition: SafeScalar.h:4
static int g_repeat
Definition: main.h:191
const int Dynamic
Definition: Constants.h:25
void rvalue_move(const MatrixType &m)
Definition: rvalue_types.cpp:74
void rvalue_transpositions(Index rows)
Definition: rvalue_types.cpp:43
void rvalue_copyassign(const MatrixType &m)
Definition: rvalue_types.cpp:19
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
#define CALL_SUBTEST_3(FUNC)
Definition: split_test_helper.h:16
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
Definition: MovableScalar.h:15

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, Eigen::Dynamic, EIGEN_TEST_MAX_SIZE, eval(), Eigen::g_repeat, i, rvalue_copyassign(), rvalue_move(), and rvalue_transpositions().

◆ rvalue_copyassign()

template<typename MatrixType >
void rvalue_copyassign ( const MatrixType m)
19  {
21 
22  // create a temporary which we are about to destroy by moving
23  MatrixType tmp = m;
24  std::uintptr_t src_address = reinterpret_cast<std::uintptr_t>(tmp.data());
25 
26  Eigen::internal::set_is_malloc_allowed(false); // moving from an rvalue reference shall never allocate
27  // move the temporary to n
28  MatrixType n = std::move(tmp);
29  std::uintptr_t dst_address = reinterpret_cast<std::uintptr_t>(n.data());
30  if (MatrixType::RowsAtCompileTime == Dynamic || MatrixType::ColsAtCompileTime == Dynamic) {
31  // verify that we actually moved the guts
32  VERIFY_IS_EQUAL(src_address, dst_address);
33  VERIFY_IS_EQUAL(tmp.size(), 0);
34  VERIFY_IS_EQUAL(reinterpret_cast<std::uintptr_t>(tmp.data()), std::uintptr_t(0));
35  }
36 
37  // verify that the content did not change
38  Scalar abs_diff = (m - n).array().abs().sum();
39  VERIFY_IS_EQUAL(abs_diff, Scalar(0));
40  Eigen::internal::set_is_malloc_allowed(true);
41 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
constexpr EIGEN_DEVICE_FUNC const Scalar * data() const
Definition: PlainObjectBase.h:273
int * m
Definition: level2_cplx_impl.h:294
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367
std::array< T, N > array
Definition: EmulateArray.h:231

References Eigen::PlainObjectBase< Derived >::data(), Eigen::Dynamic, m, n, tmp, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ rvalue_move()

template<typename MatrixType >
void rvalue_move ( const MatrixType m)
74  {
75  // lvalue reference is copied
76  MatrixType b(m);
78 
79  // lvalue reference is copied
80  MatrixType c{m};
82 
83  // lvalue reference is copied
84  MatrixType d = m;
85  VERIFY_IS_EQUAL(d, m);
86 
87  // rvalue reference is moved - copy constructor.
88  MatrixType e_src(m);
89  VERIFY_IS_EQUAL(e_src, m);
90  MatrixType e_dst(std::move(e_src));
91  VERIFY_IS_EQUAL(e_dst, m);
92 
93  // rvalue reference is moved - copy constructor.
94  MatrixType f_src(m);
95  VERIFY_IS_EQUAL(f_src, m);
96  MatrixType f_dst = std::move(f_src);
97  VERIFY_IS_EQUAL(f_dst, m);
98 
99  // rvalue reference is moved - copy assignment.
100  MatrixType g_src(m);
101  VERIFY_IS_EQUAL(g_src, m);
102  MatrixType g_dst;
103  g_dst = std::move(g_src);
104  VERIFY_IS_EQUAL(g_dst, m);
105 }
Scalar * b
Definition: benchVecAdd.cpp:17
int c
Definition: calibrate.py:100

References b, calibrate::c, m, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().

◆ rvalue_transpositions()

template<typename TranspositionsType >
void rvalue_transpositions ( Index  rows)
43  {
44  typedef typename TranspositionsType::IndicesType PermutationVectorType;
45 
46  PermutationVectorType vec;
48  TranspositionsType t0(vec);
49 
50  Eigen::internal::set_is_malloc_allowed(false); // moving from an rvalue reference shall never allocate
51 
52  std::uintptr_t t0_address = reinterpret_cast<std::uintptr_t>(t0.indices().data());
53 
54  // Move constructors:
55  TranspositionsType t1 = std::move(t0);
56  std::uintptr_t t1_address = reinterpret_cast<std::uintptr_t>(t1.indices().data());
57  VERIFY_IS_EQUAL(t0_address, t1_address);
58  // t0 must be de-allocated:
59  VERIFY_IS_EQUAL(t0.size(), 0);
60  VERIFY_IS_EQUAL(reinterpret_cast<std::uintptr_t>(t0.indices().data()), std::uintptr_t(0));
61 
62  // Move assignment:
63  t0 = std::move(t1);
64  t0_address = reinterpret_cast<std::uintptr_t>(t0.indices().data());
65  VERIFY_IS_EQUAL(t0_address, t1_address);
66  // t1 must be de-allocated:
67  VERIFY_IS_EQUAL(t1.size(), 0);
68  VERIFY_IS_EQUAL(reinterpret_cast<std::uintptr_t>(t1.indices().data()), std::uintptr_t(0));
69 
70  Eigen::internal::set_is_malloc_allowed(true);
71 }
int rows
Definition: Tutorial_commainit_02.cpp:1
void randomPermutationVector(PermutationVectorType &v, Index size)
Definition: random_matrix_helper.h:101

References Eigen::randomPermutationVector(), rows, and VERIFY_IS_EQUAL.

Referenced by EIGEN_DECLARE_TEST().