nesting_ops.cpp File Reference
#include "main.h"

Macros

#define TEST_ENABLE_TEMPORARY_TRACKING
 

Functions

template<int N, typename XprType >
void use_n_times (const XprType &xpr)
 
template<int N, typename ReferenceType , typename XprType >
bool verify_eval_type (const XprType &, const ReferenceType &)
 
template<typename MatrixType >
void run_nesting_ops_1 (const MatrixType &_m)
 
template<typename MatrixType >
void run_nesting_ops_2 (const MatrixType &_m)
 
 EIGEN_DECLARE_TEST (nesting_ops)
 

Macro Definition Documentation

◆ TEST_ENABLE_TEMPORARY_TRACKING

#define TEST_ENABLE_TEMPORARY_TRACKING

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( nesting_ops  )
89  {
90  CALL_SUBTEST_1(run_nesting_ops_1(MatrixXf::Random(25, 25)));
91  CALL_SUBTEST_2(run_nesting_ops_1(MatrixXcd::Random(25, 25)));
92  CALL_SUBTEST_3(run_nesting_ops_1(Matrix4f::Random()));
93  CALL_SUBTEST_4(run_nesting_ops_1(Matrix2d::Random()));
94 
95  Index s = internal::random<int>(1, EIGEN_TEST_MAX_SIZE);
96  CALL_SUBTEST_1(run_nesting_ops_2(MatrixXf(s, s)));
97  CALL_SUBTEST_2(run_nesting_ops_2(MatrixXcd(s, s)));
98  CALL_SUBTEST_3(run_nesting_ops_2(Matrix4f()));
99  CALL_SUBTEST_4(run_nesting_ops_2(Matrix2d()));
101 }
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
RealScalar s
Definition: level1_cplx_impl.h:130
#define TEST_SET_BUT_UNUSED_VARIABLE(X)
Definition: main.h:139
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void run_nesting_ops_2(const MatrixType &_m)
Definition: nesting_ops.cpp:47
void run_nesting_ops_1(const MatrixType &_m)
Definition: nesting_ops.cpp:31
#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_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, EIGEN_TEST_MAX_SIZE, run_nesting_ops_1(), run_nesting_ops_2(), s, and TEST_SET_BUT_UNUSED_VARIABLE.

◆ run_nesting_ops_1()

template<typename MatrixType >
void run_nesting_ops_1 ( const MatrixType _m)
31  {
33 
34  // Make really sure that we are in debug mode!
36 
37  // The only intention of these tests is to ensure that this code does
38  // not trigger any asserts or segmentation faults... more to come.
39  VERIFY_IS_APPROX((m.transpose() * m).diagonal().sum(), (m.transpose() * m).diagonal().sum());
40  VERIFY_IS_APPROX((m.transpose() * m).diagonal().array().abs().sum(),
41  (m.transpose() * m).diagonal().array().abs().sum());
42 
43  VERIFY_IS_APPROX((m.transpose() * m).array().abs().sum(), (m.transpose() * m).array().abs().sum());
44 }
#define eigen_assert(x)
Definition: Macros.h:910
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY_RAISES_ASSERT(a)
Definition: main.h:329
std::conditional_t< Evaluate, PlainObject, typename ref_selector< T >::type > type
Definition: XprHelper.h:549

References eigen_assert, m, VERIFY_IS_APPROX, and VERIFY_RAISES_ASSERT.

Referenced by EIGEN_DECLARE_TEST().

◆ run_nesting_ops_2()

template<typename MatrixType >
void run_nesting_ops_2 ( const MatrixType _m)
47  {
48  typedef typename MatrixType::Scalar Scalar;
49  Index rows = _m.rows();
50  Index cols = _m.cols();
51  MatrixType m1 = MatrixType::Random(rows, cols);
53 
54  if ((MatrixType::SizeAtCompileTime == Dynamic)) {
55  VERIFY_EVALUATION_COUNT(use_n_times<1>(m1 + m1 * m1), 1);
56  VERIFY_EVALUATION_COUNT(use_n_times<10>(m1 + m1 * m1), 1);
57 
58  VERIFY_EVALUATION_COUNT(use_n_times<1>(m1.template triangularView<Lower>().solve(m1.col(0))), 1);
59  VERIFY_EVALUATION_COUNT(use_n_times<10>(m1.template triangularView<Lower>().solve(m1.col(0))), 1);
60 
61  VERIFY_EVALUATION_COUNT(use_n_times<1>(Scalar(2) * m1.template triangularView<Lower>().solve(m1.col(0))),
62  2); // FIXME could be one by applying the scaling in-place on the solve result
63  VERIFY_EVALUATION_COUNT(use_n_times<1>(m1.col(0) + m1.template triangularView<Lower>().solve(m1.col(0))),
64  2); // FIXME could be one by adding m1.col() inplace
65  VERIFY_EVALUATION_COUNT(use_n_times<10>(m1.col(0) + m1.template triangularView<Lower>().solve(m1.col(0))), 2);
66  }
67 
68  {
69  VERIFY(verify_eval_type<10>(m1, m1));
71  VERIFY(verify_eval_type<3>(2 * m1, 2 * m1));
72  VERIFY(verify_eval_type<4>(2 * m1, m1));
73  } else {
74  VERIFY(verify_eval_type<2>(2 * m1, 2 * m1));
75  VERIFY(verify_eval_type<3>(2 * m1, m1));
76  }
77  VERIFY(verify_eval_type<2>(m1 + m1, m1 + m1));
78  VERIFY(verify_eval_type<3>(m1 + m1, m1));
79  VERIFY(verify_eval_type<1>(m1 * m1.transpose(), m2));
80  VERIFY(verify_eval_type<1>(m1 * (m1 + m1).transpose(), m2));
81  VERIFY(verify_eval_type<2>(m1 * m1.transpose(), m2));
82  VERIFY(verify_eval_type<1>(m1 + m1 * m1, m1));
83 
84  VERIFY(verify_eval_type<1>(m1.template triangularView<Lower>().solve(m1), m1));
85  VERIFY(verify_eval_type<1>(m1 + m1.template triangularView<Lower>().solve(m1), m1));
86  }
87 }
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixType m2(n_dims)
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
#define VERIFY(a)
Definition: main.h:362
const int Dynamic
Definition: Constants.h:25
void transpose()
Definition: skew_symmetric_matrix3.cpp:135
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217
#define VERIFY_EVALUATION_COUNT(XPR, N)
Definition: test/sparse_product.cpp:28

References cols, Eigen::Dynamic, m1, m2(), rows, anonymous_namespace{skew_symmetric_matrix3.cpp}::transpose(), VERIFY, and VERIFY_EVALUATION_COUNT.

Referenced by EIGEN_DECLARE_TEST().

◆ use_n_times()

template<int N, typename XprType >
void use_n_times ( const XprType xpr)
16  {
18  typename XprType::PlainObject res(mat.rows(), mat.cols());
19  nb_temporaries--; // remove res
20  res.setZero();
21  for (int i = 0; i < N; ++i) res += mat;
22 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
Index cols() const
Definition: SparseMatrix.h:161
Index rows() const
Definition: SparseMatrix.h:159
@ N
Definition: constructor.cpp:22
static long int nb_temporaries
Definition: sparse_permutations.cpp:21

References Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::cols(), i, N, nb_temporaries, res, and Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::rows().

◆ verify_eval_type()

template<int N, typename ReferenceType , typename XprType >
bool verify_eval_type ( const XprType ,
const ReferenceType &   
)
25  {
26  typedef typename internal::nested_eval<XprType, N>::type EvalType;
27  return internal::is_same<internal::remove_all_t<EvalType>, internal::remove_all_t<ReferenceType>>::value;
28 }
squared absolute value
Definition: GlobalFunctions.h:87

References Eigen::value.