rvalue_types.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) 2013 Hauke Heibel <hauke.heibel@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/Core>
13 
14 using internal::UIntPtr;
15 
16 #if EIGEN_HAS_RVALUE_REFERENCES
17 template <typename MatrixType>
18 void rvalue_copyassign(const MatrixType& m)
19 {
20 
22 
23  // create a temporary which we are about to destroy by moving
24  MatrixType tmp = m;
25  UIntPtr src_address = reinterpret_cast<UIntPtr>(tmp.data());
26 
27  // move the temporary to n
28  MatrixType n = std::move(tmp);
29  UIntPtr dst_address = reinterpret_cast<UIntPtr>(n.data());
30 
31  if (MatrixType::RowsAtCompileTime==Dynamic|| MatrixType::ColsAtCompileTime==Dynamic)
32  {
33  // verify that we actually moved the guts
34  VERIFY_IS_EQUAL(src_address, dst_address);
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 }
41 #else
42 template <typename MatrixType>
44 #endif
45 
47 {
48  CALL_SUBTEST_1(rvalue_copyassign( MatrixXf::Random(50,50).eval() ));
49  CALL_SUBTEST_1(rvalue_copyassign( ArrayXXf::Random(50,50).eval() ));
50 
52  CALL_SUBTEST_1(rvalue_copyassign( Array<float,1,Dynamic>::Random(50).eval() ));
53 
55  CALL_SUBTEST_1(rvalue_copyassign( Array<float,Dynamic,1>::Random(50).eval() ));
56 
57  CALL_SUBTEST_2(rvalue_copyassign( Array<float,2,1>::Random().eval() ));
58  CALL_SUBTEST_2(rvalue_copyassign( Array<float,3,1>::Random().eval() ));
59  CALL_SUBTEST_2(rvalue_copyassign( Array<float,4,1>::Random().eval() ));
60 
61  CALL_SUBTEST_2(rvalue_copyassign( Array<float,2,2>::Random().eval() ));
62  CALL_SUBTEST_2(rvalue_copyassign( Array<float,3,3>::Random().eval() ));
63  CALL_SUBTEST_2(rvalue_copyassign( Array<float,4,4>::Random().eval() ));
64 }
Matrix3f m
int array[24]
SCALAR Scalar
Definition: bench_gemm.cpp:33
void rvalue_copyassign(const MatrixType &)
int n
MatrixXf MatrixType
std::size_t UIntPtr
Definition: Meta.h:51
void test_rvalue_types()
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:331
General-purpose arrays with easy API for coefficient-wise operations.
Definition: Array.h:45
internal::nested_eval< T, 1 >::type eval(const T &xpr)
const int Dynamic
Definition: Constants.h:21
The matrix class, also used for vectors and row-vectors.


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:43:53