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

Macros

#define EIGEN_SCALAR_BINARY_OP_PLUGIN    { g_called |= (!internal::is_same<LhsScalar, RhsScalar>::value); }
 

Functions

template<typename MatrixType >
void linearStructure (const MatrixType &m)
 
template<typename MatrixType >
void real_complex (DenseIndex rows=MatrixType::RowsAtCompileTime, DenseIndex cols=MatrixType::ColsAtCompileTime)
 
template<int >
void linearstructure_overflow ()
 
 EIGEN_DECLARE_TEST (linearstructure)
 

Variables

static bool g_called
 

Macro Definition Documentation

◆ EIGEN_SCALAR_BINARY_OP_PLUGIN

#define EIGEN_SCALAR_BINARY_OP_PLUGIN    { g_called |= (!internal::is_same<LhsScalar, RhsScalar>::value); }

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( linearstructure  )
125  {
126  g_called = true;
127  VERIFY(g_called); // avoid `unneeded-internal-declaration` warning.
128  for (int i = 0; i < g_repeat; i++) {
130  CALL_SUBTEST_2(linearStructure(Matrix2f()));
131  CALL_SUBTEST_3(linearStructure(Vector3d()));
132  CALL_SUBTEST_4(linearStructure(Matrix4d()));
133  CALL_SUBTEST_5(linearStructure(MatrixXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2),
134  internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2))));
136  MatrixXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
138  MatrixXi(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
139  CALL_SUBTEST_8(linearStructure(MatrixXcd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2),
140  internal::random<int>(1, EIGEN_TEST_MAX_SIZE / 2))));
142  ArrayXXf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
144  ArrayXXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
145 
146  CALL_SUBTEST_11(real_complex<Matrix4cd>());
147  CALL_SUBTEST_11(real_complex<MatrixXcf>(10, 10));
148  CALL_SUBTEST_11(real_complex<ArrayXXcf>(10, 10));
149  }
150  CALL_SUBTEST_4(linearstructure_overflow<0>());
151 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
void linearStructure(const MatrixType &m)
Definition: linearstructure.cpp:18
static bool g_called
Definition: linearstructure.cpp:11
#define VERIFY(a)
Definition: main.h:362
static int g_repeat
Definition: main.h:191
#define CALL_SUBTEST_6(FUNC)
Definition: split_test_helper.h:34
#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_8(FUNC)
Definition: split_test_helper.h:46
#define CALL_SUBTEST_5(FUNC)
Definition: split_test_helper.h:28
#define CALL_SUBTEST_11(FUNC)
Definition: split_test_helper.h:64
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
#define CALL_SUBTEST_7(FUNC)
Definition: split_test_helper.h:40
#define CALL_SUBTEST_4(FUNC)
Definition: split_test_helper.h:22
#define CALL_SUBTEST_9(FUNC)
Definition: split_test_helper.h:52
#define CALL_SUBTEST_10(FUNC)
Definition: split_test_helper.h:58

References CALL_SUBTEST_1, CALL_SUBTEST_10, CALL_SUBTEST_11, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, CALL_SUBTEST_7, CALL_SUBTEST_8, CALL_SUBTEST_9, EIGEN_TEST_MAX_SIZE, g_called, Eigen::g_repeat, i, linearStructure(), and VERIFY.

◆ linearStructure()

template<typename MatrixType >
void linearStructure ( const MatrixType m)
18  {
19  using std::abs;
20  /* this test covers the following files:
21  CwiseUnaryOp.h, CwiseBinaryOp.h, SelfCwiseBinaryOp.h
22  */
23  typedef typename MatrixType::Scalar Scalar;
24  typedef typename MatrixType::RealScalar RealScalar;
25 
26  Index rows = m.rows();
27  Index cols = m.cols();
28 
29  // this test relies a lot on Random.h, and there's not much more that we can do
30  // to test it, hence I consider that we will have tested Random.h
31  MatrixType m1 = MatrixType::Random(rows, cols), m2 = MatrixType::Random(rows, cols), m3(rows, cols);
32 
33  Scalar s1 = internal::random<Scalar>();
34  while (abs(s1) < RealScalar(1e-3)) s1 = internal::random<Scalar>();
35 
36  Index r = internal::random<Index>(0, rows - 1), c = internal::random<Index>(0, cols - 1);
37 
38  VERIFY_IS_APPROX(-(-m1), m1);
39  VERIFY_IS_APPROX(m1 + m1, 2 * m1);
40  VERIFY_IS_APPROX(m1 + m2 - m1, m2);
41  VERIFY_IS_APPROX(-m2 + m1 + m2, m1);
42  VERIFY_IS_APPROX(m1 * s1, s1 * m1);
43  VERIFY_IS_APPROX((m1 + m2) * s1, s1 * m1 + s1 * m2);
44  VERIFY_IS_APPROX((-m1 + m2) * s1, -s1 * m1 + s1 * m2);
45  m3 = m2;
46  m3 += m1;
47  VERIFY_IS_APPROX(m3, m1 + m2);
48  m3 = m2;
49  m3 -= m1;
50  VERIFY_IS_APPROX(m3, m2 - m1);
51  m3 = m2;
52  m3 *= s1;
53  VERIFY_IS_APPROX(m3, s1 * m2);
55  m3 = m2;
56  m3 /= s1;
57  VERIFY_IS_APPROX(m3, m2 / s1);
58  }
59 
60  // again, test operator() to check const-qualification
61  VERIFY_IS_APPROX((-m1)(r, c), -(m1(r, c)));
62  VERIFY_IS_APPROX((m1 - m2)(r, c), (m1(r, c)) - (m2(r, c)));
63  VERIFY_IS_APPROX((m1 + m2)(r, c), (m1(r, c)) + (m2(r, c)));
64  VERIFY_IS_APPROX((s1 * m1)(r, c), s1 * (m1(r, c)));
65  VERIFY_IS_APPROX((m1 * s1)(r, c), (m1(r, c)) * s1);
66  if (!NumTraits<Scalar>::IsInteger) VERIFY_IS_APPROX((m1 / s1)(r, c), (m1(r, c)) / s1);
67 
68  // use .block to disable vectorization and compare to the vectorized version
69  VERIFY_IS_APPROX(m1 + m1.block(0, 0, rows, cols), m1 + m1);
70  VERIFY_IS_APPROX(m1.cwiseProduct(m1.block(0, 0, rows, cols)), m1.cwiseProduct(m1));
71  VERIFY_IS_APPROX(m1 - m1.block(0, 0, rows, cols), m1 - m1);
72  VERIFY_IS_APPROX(m1.block(0, 0, rows, cols) * s1, m1 * s1);
73 }
AnnoyingScalar abs(const AnnoyingScalar &x)
Definition: AnnoyingScalar.h:135
Array< double, 1, 3 > e(1./3., 0.5, 2.)
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
NumTraits< Scalar >::Real RealScalar
Definition: bench_gemm.cpp:46
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
int * m
Definition: level2_cplx_impl.h:294
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
r
Definition: UniformPSDSelfTest.py:20
int c
Definition: calibrate.py:100
Holds information about the various numeric (i.e. scalar) types allowed by Eigen.
Definition: NumTraits.h:217

References abs(), calibrate::c, cols, e(), m, m1, m2(), UniformPSDSelfTest::r, rows, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().

◆ linearstructure_overflow()

template<int >
void linearstructure_overflow ( )
114  {
115  // make sure that /=scalar and /scalar do not overflow
116  // rational: 1.0/4.94e-320 overflow, but m/4.94e-320 should not
117  Matrix4d m2, m3;
118  m3 = m2 = Matrix4d::Random() * 1e-20;
119  m2 = m2 / 4.9e-320;
120  VERIFY_IS_APPROX(m2.cwiseQuotient(m2), Matrix4d::Ones());
121  m3 /= 4.9e-320;
122  VERIFY_IS_APPROX(m3.cwiseQuotient(m3), Matrix4d::Ones());
123 }

References e(), m2(), and VERIFY_IS_APPROX.

◆ real_complex()

template<typename MatrixType >
void real_complex ( DenseIndex  rows = MatrixType::RowsAtCompileTime,
DenseIndex  cols = MatrixType::ColsAtCompileTime 
)
77  {
78  typedef typename MatrixType::Scalar Scalar;
79  typedef typename MatrixType::RealScalar RealScalar;
80 
81  RealScalar s = internal::random<RealScalar>();
82  MatrixType m1 = MatrixType::Random(rows, cols);
83 
84  g_called = false;
85  VERIFY_IS_APPROX(s * m1, Scalar(s) * m1);
86  VERIFY(g_called && "real * matrix<complex> not properly optimized");
87 
88  g_called = false;
89  VERIFY_IS_APPROX(m1 * s, m1 * Scalar(s));
90  VERIFY(g_called && "matrix<complex> * real not properly optimized");
91 
92  g_called = false;
93  VERIFY_IS_APPROX(m1 / s, m1 / Scalar(s));
94  VERIFY(g_called && "matrix<complex> / real not properly optimized");
95 
96  g_called = false;
97  VERIFY_IS_APPROX(s + m1.array(), Scalar(s) + m1.array());
98  VERIFY(g_called && "real + matrix<complex> not properly optimized");
99 
100  g_called = false;
101  VERIFY_IS_APPROX(m1.array() + s, m1.array() + Scalar(s));
102  VERIFY(g_called && "matrix<complex> + real not properly optimized");
103 
104  g_called = false;
105  VERIFY_IS_APPROX(s - m1.array(), Scalar(s) - m1.array());
106  VERIFY(g_called && "real - matrix<complex> not properly optimized");
107 
108  g_called = false;
109  VERIFY_IS_APPROX(m1.array() - s, m1.array() - Scalar(s));
110  VERIFY(g_called && "matrix<complex> - real not properly optimized");
111 }
RealScalar s
Definition: level1_cplx_impl.h:130

References cols, g_called, m1, rows, s, VERIFY, and VERIFY_IS_APPROX.

Variable Documentation

◆ g_called

bool g_called
static

Referenced by EIGEN_DECLARE_TEST(), and real_complex().