sparse_ref.cpp File Reference
#include "main.h"
#include <Eigen/SparseCore>

Macros

#define EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN    { on_temporary_creation(); }
 
#define VERIFY_EVALUATION_COUNT(XPR, N)
 

Functions

void on_temporary_creation ()
 
template<typename PlainObjectType >
void check_const_correctness (const PlainObjectType &)
 
template<typename B >
EIGEN_DONT_INLINE void call_ref_1 (Ref< SparseMatrix< float > > a, const B &b)
 
template<typename B >
EIGEN_DONT_INLINE void call_ref_2 (const Ref< const SparseMatrix< float > > &a, const B &b)
 
template<typename B >
EIGEN_DONT_INLINE void call_ref_3 (const Ref< const SparseMatrix< float >, StandardCompressedFormat > &a, const B &b)
 
template<typename B >
EIGEN_DONT_INLINE void call_ref_4 (Ref< SparseVector< float > > a, const B &b)
 
template<typename B >
EIGEN_DONT_INLINE void call_ref_5 (const Ref< const SparseVector< float > > &a, const B &b)
 
void call_ref ()
 
 EIGEN_DECLARE_TEST (sparse_ref)
 

Variables

static long int nb_temporaries
 

Macro Definition Documentation

◆ EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN

#define EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN    { on_temporary_creation(); }

◆ VERIFY_EVALUATION_COUNT

#define VERIFY_EVALUATION_COUNT (   XPR,
  N 
)
Value:
{ \
nb_temporaries = 0; \
CALL_SUBTEST(XPR); \
if (nb_temporaries != N) std::cerr << "nb_temporaries == " << nb_temporaries << "\n"; \
VERIFY((#XPR) && nb_temporaries == N); \
}
@ N
Definition: constructor.cpp:22
static long int nb_temporaries
Definition: sparse_ref.cpp:15

Function Documentation

◆ call_ref()

void call_ref ( )
72  {
73  SparseMatrix<float> A = MatrixXf::Random(10, 10).sparseView(0.5, 1);
74  SparseMatrix<float, RowMajor> B = MatrixXf::Random(10, 10).sparseView(0.5, 1);
75  SparseMatrix<float> C = MatrixXf::Random(10, 10).sparseView(0.5, 1);
76  C.reserve(VectorXi::Constant(C.outerSize(), 2));
77  const SparseMatrix<float> &Ac(A);
78  Block<SparseMatrix<float> > Ab(A, 0, 1, 3, 3);
79  const Block<SparseMatrix<float> > Abc(A, 0, 1, 3, 3);
80  SparseVector<float> vc = VectorXf::Random(10).sparseView(0.5, 1);
81  SparseVector<float, RowMajor> vr = VectorXf::Random(10).sparseView(0.5, 1);
82  SparseMatrix<float> AA = A * A;
83 
85  // VERIFY_EVALUATION_COUNT( call_ref_1(Ac, Ac), 0); // does not compile on purpose
88  VERIFY_EVALUATION_COUNT(call_ref_2(A.transpose(), A.transpose()), 1);
89  VERIFY_EVALUATION_COUNT(call_ref_3(A.transpose(), A.transpose()), 1);
92  VERIFY_EVALUATION_COUNT(call_ref_2(A + A, 2 * Ac), 1);
93  VERIFY_EVALUATION_COUNT(call_ref_3(A + A, 2 * Ac), 1);
96  VERIFY_EVALUATION_COUNT(call_ref_2(B.transpose(), B.transpose()), 0);
97  VERIFY_EVALUATION_COUNT(call_ref_3(B.transpose(), B.transpose()), 0);
100 
101  VERIFY(!C.isCompressed());
103 
105  VERIFY_IS_APPROX(Ar + Ar, A + A);
108 
110  VERIFY_EVALUATION_COUNT(call_ref_1(Br.transpose(), Br.transpose()), 0);
112  VERIFY_EVALUATION_COUNT(call_ref_2(Br.transpose(), Br.transpose()), 0);
113 
115  // VERIFY_EVALUATION_COUNT( call_ref_1(Arc, Arc), 0); // does not compile on purpose
116  VERIFY_EVALUATION_COUNT(call_ref_2(Arc, Arc), 0);
117 
118  VERIFY_EVALUATION_COUNT(call_ref_2(A.middleCols(1, 3), A.middleCols(1, 3)), 0);
119 
120  VERIFY_EVALUATION_COUNT(call_ref_2(A.col(2), A.col(2)), 0);
124 
125  VERIFY_EVALUATION_COUNT(call_ref_2(A.block(1, 1, 3, 3), A.block(1, 1, 3, 3)),
126  1); // should be 0 (allocate starts/nnz only)
127 
132  VERIFY_EVALUATION_COUNT(call_ref_4(A.col(2), A.col(2)), 0);
133  VERIFY_EVALUATION_COUNT(call_ref_5(A.col(2), A.col(2)), 0);
134  // VERIFY_EVALUATION_COUNT( call_ref_4(A.row(2), A.row(2).transpose()), 1); // does not compile on purpose
135  VERIFY_EVALUATION_COUNT(call_ref_5(A.row(2), A.row(2).transpose()), 1);
136 }
Matrix< SCALARA, Dynamic, Dynamic, opt_A > A
Definition: bench_gemm.cpp:47
Expression of a fixed-size or dynamic-size block.
Definition: Block.h:110
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
A matrix or vector expression mapping an existing expression.
Definition: Ref.h:264
TransposeReturnType transpose()
Definition: SparseMatrixBase.h:358
A versatible sparse matrix representation.
Definition: SparseMatrix.h:121
a sparse vector class
Definition: SparseVector.h:62
Definition: matrices.h:74
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
#define VERIFY(a)
Definition: main.h:362
EIGEN_DONT_INLINE void call_ref_4(Ref< SparseVector< float > > a, const B &b)
Definition: sparse_ref.cpp:63
EIGEN_DONT_INLINE void call_ref_3(const Ref< const SparseMatrix< float >, StandardCompressedFormat > &a, const B &b)
Definition: sparse_ref.cpp:57
#define VERIFY_EVALUATION_COUNT(XPR, N)
Definition: sparse_ref.cpp:28
EIGEN_DONT_INLINE void call_ref_1(Ref< SparseMatrix< float > > a, const B &b)
Definition: sparse_ref.cpp:47
EIGEN_DONT_INLINE void call_ref_5(const Ref< const SparseVector< float > > &a, const B &b)
Definition: sparse_ref.cpp:68
EIGEN_DONT_INLINE void call_ref_2(const Ref< const SparseMatrix< float > > &a, const B &b)
Definition: sparse_ref.cpp:52

References call_ref_1(), call_ref_2(), call_ref_3(), call_ref_4(), call_ref_5(), Eigen::SparseMatrixBase< Derived >::transpose(), VERIFY, VERIFY_EVALUATION_COUNT, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ call_ref_1()

template<typename B >
EIGEN_DONT_INLINE void call_ref_1 ( Ref< SparseMatrix< float > >  a,
const B b 
)
47  {
48  VERIFY_IS_EQUAL(a.toDense(), b.toDense());
49 }
Scalar * b
Definition: benchVecAdd.cpp:17
const Scalar * a
Definition: level2_cplx_impl.h:32
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:367

References a, b, and VERIFY_IS_EQUAL.

Referenced by call_ref().

◆ call_ref_2()

template<typename B >
EIGEN_DONT_INLINE void call_ref_2 ( const Ref< const SparseMatrix< float > > &  a,
const B b 
)
52  {
53  VERIFY_IS_EQUAL(a.toDense(), b.toDense());
54 }

References a, b, and VERIFY_IS_EQUAL.

Referenced by call_ref().

◆ call_ref_3()

template<typename B >
EIGEN_DONT_INLINE void call_ref_3 ( const Ref< const SparseMatrix< float >, StandardCompressedFormat > &  a,
const B b 
)
57  {
58  VERIFY(a.isCompressed());
59  VERIFY_IS_EQUAL(a.toDense(), b.toDense());
60 }

References a, b, VERIFY, and VERIFY_IS_EQUAL.

Referenced by call_ref().

◆ call_ref_4()

template<typename B >
EIGEN_DONT_INLINE void call_ref_4 ( Ref< SparseVector< float > >  a,
const B b 
)
63  {
64  VERIFY_IS_EQUAL(a.toDense(), b.toDense());
65 }

References a, b, and VERIFY_IS_EQUAL.

Referenced by call_ref().

◆ call_ref_5()

template<typename B >
EIGEN_DONT_INLINE void call_ref_5 ( const Ref< const SparseVector< float > > &  a,
const B b 
)
68  {
69  VERIFY_IS_EQUAL(a.toDense(), b.toDense());
70 }

References a, b, and VERIFY_IS_EQUAL.

Referenced by call_ref().

◆ check_const_correctness()

template<typename PlainObjectType >
void check_const_correctness ( const PlainObjectType &  )
37  {
38  // verify that ref-to-const don't have LvalueBit
39  typedef std::add_const_t<PlainObjectType> ConstPlainObjectType;
40  VERIFY(!(internal::traits<Ref<ConstPlainObjectType> >::Flags & LvalueBit));
41  VERIFY(!(internal::traits<Ref<ConstPlainObjectType, Aligned> >::Flags & LvalueBit));
44 }
const unsigned int LvalueBit
Definition: Constants.h:148
Extend namespace for flags.
Definition: fsi_chan_precond_driver.cc:56

References Eigen::LvalueBit, and VERIFY.

Referenced by EIGEN_DECLARE_TEST().

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( sparse_ref  )
138  {
139  for (int i = 0; i < g_repeat; i++) {
143 
146  }
147 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
static int g_repeat
Definition: main.h:191
void call_ref()
Definition: sparse_ref.cpp:72
void check_const_correctness(const PlainObjectType &)
Definition: sparse_ref.cpp:37
#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

References call_ref(), CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, check_const_correctness(), Eigen::g_repeat, and i.

◆ on_temporary_creation()

void on_temporary_creation ( )
inline
17  {
18  // here's a great place to set a breakpoint when debugging failures in this test!
20 }

References nb_temporaries.

Variable Documentation

◆ nb_temporaries

long int nb_temporaries
static

Referenced by on_temporary_creation().