conservative_resize.cpp File Reference
#include "main.h"
#include <Eigen/Core>
#include "AnnoyingScalar.h"

Functions

template<typename Scalar , int Storage>
void run_matrix_tests ()
 
template<typename Scalar >
void run_vector_tests ()
 
template<int >
void noncopyable ()
 
 EIGEN_DECLARE_TEST (conservative_resize)
 

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( conservative_resize  )
136  {
137  for (int i = 0; i < g_repeat; ++i) {
138  CALL_SUBTEST_1((run_matrix_tests<int, Eigen::RowMajor>()));
139  CALL_SUBTEST_1((run_matrix_tests<int, Eigen::ColMajor>()));
140  CALL_SUBTEST_2((run_matrix_tests<float, Eigen::RowMajor>()));
141  CALL_SUBTEST_2((run_matrix_tests<float, Eigen::ColMajor>()));
142  CALL_SUBTEST_3((run_matrix_tests<double, Eigen::RowMajor>()));
143  CALL_SUBTEST_3((run_matrix_tests<double, Eigen::ColMajor>()));
144  CALL_SUBTEST_4((run_matrix_tests<std::complex<float>, Eigen::RowMajor>()));
145  CALL_SUBTEST_4((run_matrix_tests<std::complex<float>, Eigen::ColMajor>()));
146  CALL_SUBTEST_5((run_matrix_tests<std::complex<double>, Eigen::RowMajor>()));
147  CALL_SUBTEST_5((run_matrix_tests<std::complex<double>, Eigen::ColMajor>()));
148  CALL_SUBTEST_1((run_matrix_tests<int, Eigen::RowMajor | Eigen::DontAlign>()));
149 
150  CALL_SUBTEST_1((run_vector_tests<int>()));
151  CALL_SUBTEST_2((run_vector_tests<float>()));
152  CALL_SUBTEST_3((run_vector_tests<double>()));
153  CALL_SUBTEST_4((run_vector_tests<std::complex<float> >()));
154  CALL_SUBTEST_5((run_vector_tests<std::complex<double> >()));
155 
156 #ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW
158 #endif
159  CALL_SUBTEST_6((run_vector_tests<AnnoyingScalar>()));
160  CALL_SUBTEST_6((noncopyable<0>()));
161  }
162 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
static bool dont_throw
Definition: AnnoyingScalar.h:127
void run_vector_tests()
Definition: conservative_resize.cpp:58
void run_matrix_tests()
Definition: conservative_resize.cpp:18
@ ColMajor
Definition: Constants.h:318
@ RowMajor
Definition: Constants.h:320
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_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

References CALL_SUBTEST_1, CALL_SUBTEST_2, CALL_SUBTEST_3, CALL_SUBTEST_4, CALL_SUBTEST_5, CALL_SUBTEST_6, Eigen::ColMajor, AnnoyingScalar::dont_throw, Eigen::g_repeat, i, Eigen::RowMajor, run_matrix_tests(), and run_vector_tests().

◆ noncopyable()

template<int >
void noncopyable ( )
109  {
112 
113  {
114 #ifndef EIGEN_TEST_ANNOYING_SCALAR_DONT_THROW
116 #endif
117  int n = 50;
118  VectorType v0(n), v1(n);
119  MatrixType m0(n, n), m1(n, n), m2(n, n);
120  v0.setOnes();
121  v1.setOnes();
122  m0.setOnes();
123  m1.setOnes();
124  m2.setOnes();
125  VERIFY(m0 == m1);
126  m0.conservativeResize(2 * n, 2 * n);
127  VERIFY(m0.topLeftCorner(n, n) == m1);
128 
129  VERIFY(v0.head(n) == v1);
130  v0.conservativeResize(2 * n);
131  VERIFY(v0.head(n) == v1);
132  }
133  VERIFY(AnnoyingScalar::instances == 0 && "global memory leak detected in noncopyable");
134 }
const unsigned n
Definition: CG3DPackingUnitTest.cpp:11
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixType m2(n_dims)
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
MatrixXf MatrixType
Definition: benchmark-blocking-sizes.cpp:52
static int instances
Definition: AnnoyingScalar.h:124
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
Definition: fft_test_shared.h:66

References AnnoyingScalar::dont_throw, AnnoyingScalar::instances, m1, m2(), n, v1(), and VERIFY.

◆ run_matrix_tests()

template<typename Scalar , int Storage>
void run_matrix_tests ( )
18  {
20 
21  MatrixType m, n;
22 
23  // boundary cases ...
24  m = n = MatrixType::Random(50, 50);
25  m.conservativeResize(1, 50);
26  VERIFY_IS_APPROX(m, n.block(0, 0, 1, 50));
27 
28  m = n = MatrixType::Random(50, 50);
29  m.conservativeResize(50, 1);
30  VERIFY_IS_APPROX(m, n.block(0, 0, 50, 1));
31 
32  m = n = MatrixType::Random(50, 50);
33  m.conservativeResize(50, 50);
34  VERIFY_IS_APPROX(m, n.block(0, 0, 50, 50));
35 
36  // random shrinking ...
37  for (int i = 0; i < 25; ++i) {
38  const Index rows = internal::random<Index>(1, 50);
39  const Index cols = internal::random<Index>(1, 50);
40  m = n = MatrixType::Random(50, 50);
41  m.conservativeResize(rows, cols);
42  VERIFY_IS_APPROX(m, n.block(0, 0, rows, cols));
43  }
44 
45  // random growing with zeroing ...
46  for (int i = 0; i < 25; ++i) {
47  const Index rows = internal::random<Index>(50, 75);
48  const Index cols = internal::random<Index>(50, 75);
49  m = n = MatrixType::Random(50, 50);
50  m.conservativeResizeLike(MatrixType::Zero(rows, cols));
51  VERIFY_IS_APPROX(m.block(0, 0, n.rows(), n.cols()), n);
52  VERIFY(rows <= 50 || m.block(50, 0, rows - 50, cols).sum() == Scalar(0));
53  VERIFY(cols <= 50 || m.block(0, 50, rows, cols - 50).sum() == Scalar(0));
54  }
55 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
#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
double Zero
Definition: pseudosolid_node_update_elements.cc:35

References cols, i, m, n, rows, VERIFY, VERIFY_IS_APPROX, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().

◆ run_vector_tests()

template<typename Scalar >
void run_vector_tests ( )
58  {
60 
61  VectorType m, n;
62 
63  // boundary cases ...
64  m = n = VectorType::Random(50);
65  m.conservativeResize(1);
66  VERIFY_IS_APPROX(m, n.segment(0, 1));
67 
68  m = n = VectorType::Random(50);
69  m.conservativeResize(50);
70  VERIFY_IS_APPROX(m, n.segment(0, 50));
71 
72  m = n = VectorType::Random(50);
73  m.conservativeResize(m.rows(), 1);
74  VERIFY_IS_APPROX(m, n.segment(0, 1));
75 
76  m = n = VectorType::Random(50);
77  m.conservativeResize(m.rows(), 50);
78  VERIFY_IS_APPROX(m, n.segment(0, 50));
79 
80  // random shrinking ...
81  for (int i = 0; i < 50; ++i) {
82  const int size = internal::random<int>(1, 50);
83  m = n = VectorType::Random(50);
84  m.conservativeResize(size);
85  VERIFY_IS_APPROX(m, n.segment(0, size));
86 
87  m = n = VectorType::Random(50);
88  m.conservativeResize(m.rows(), size);
89  VERIFY_IS_APPROX(m, n.segment(0, size));
90  }
91 
92  // random growing with zeroing ...
93  for (int i = 0; i < 50; ++i) {
94  const int size = internal::random<int>(50, 100);
95  m = n = VectorType::Random(50);
96  m.conservativeResizeLike(VectorType::Zero(size));
97  VERIFY_IS_APPROX(m.segment(0, 50), n);
98  VERIFY(size <= 50 || m.segment(50, size - 50).sum() == Scalar(0));
99 
100  m = n = VectorType::Random(50);
101  m.conservativeResizeLike(Matrix<Scalar, Dynamic, Dynamic>::Zero(1, size));
102  VERIFY_IS_APPROX(m.segment(0, 50), n);
103  VERIFY(size <= 50 || m.segment(50, size - 50).sum() == Scalar(0));
104  }
105 }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17

References i, m, n, size, VERIFY, VERIFY_IS_APPROX, and oomph::PseudoSolidHelper::Zero.

Referenced by EIGEN_DECLARE_TEST().