array_reverse.cpp File Reference
#include "main.h"
#include <iostream>

Functions

template<typename MatrixType >
void reverse (const MatrixType &m)
 
template<int >
void array_reverse_extra ()
 
template<typename MatrixType >
EIGEN_DONT_INLINE void bug1684_job1 (MatrixType &m1, MatrixType &m2)
 
template<typename MatrixType >
EIGEN_DONT_INLINE void bug1684_job2 (MatrixType &m1, MatrixType &m2)
 
template<typename MatrixType >
EIGEN_DONT_INLINE void bug1684_job3 (MatrixType &m1, MatrixType &m2)
 
template<int >
void bug1684 ()
 
 EIGEN_DECLARE_TEST (array_reverse)
 

Function Documentation

◆ array_reverse_extra()

template<int >
void array_reverse_extra ( )
126  {
127  Vector4f x;
128  x << 1, 2, 3, 4;
129  Vector4f y;
130  y << 4, 3, 2, 1;
131  VERIFY(x.reverse()[1] == 3);
132  VERIFY(x.reverse() == y);
133 }
Scalar * y
Definition: level1_cplx_impl.h:128
#define VERIFY(a)
Definition: main.h:362
list x
Definition: plotDoE.py:28

References VERIFY, plotDoE::x, and y.

◆ bug1684()

template<int >
void bug1684 ( )
168  {
169  Matrix4f m1 = Matrix4f::Random();
170  Matrix4f m2 = Matrix4f::Random();
171  bug1684_job1(m1, m2);
172  VERIFY_IS_APPROX(m2, m1.rowwise().reverse().eval());
173  bug1684_job2(m1, m2);
174  VERIFY_IS_APPROX(m2, m1.rowwise().reverse().eval());
175  // This one still fail after our swap's workaround,
176  // but I expect users not to implement their own swap.
177  // bug1684_job3(m1,m2);
178  // VERIFY_IS_APPROX(m2, m1.rowwise().reverse().eval());
179 }
Matrix3d m1
Definition: IOFormat.cpp:2
MatrixType m2(n_dims)
EIGEN_DONT_INLINE void bug1684_job2(MatrixType &m1, MatrixType &m2)
Definition: array_reverse.cpp:147
EIGEN_DONT_INLINE void bug1684_job1(MatrixType &m1, MatrixType &m2)
Definition: array_reverse.cpp:140
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13

References bug1684_job1(), bug1684_job2(), m1, m2(), and VERIFY_IS_APPROX.

◆ bug1684_job1()

template<typename MatrixType >
EIGEN_DONT_INLINE void bug1684_job1 ( MatrixType m1,
MatrixType m2 
)
140  {
141  m2 = m1;
142  m2.col(0).swap(m2.col(3));
143  m2.col(1).swap(m2.col(2));
144 }

References m1, and m2().

Referenced by bug1684().

◆ bug1684_job2()

template<typename MatrixType >
EIGEN_DONT_INLINE void bug1684_job2 ( MatrixType m1,
MatrixType m2 
)
147  {
148  m2 = m1; // load m1/m2 in AVX registers
149  m1.col(0) = m2.col(3); // perform 128 bits moves
150  m1.col(1) = m2.col(2);
151  m1.col(2) = m2.col(1);
152  m1.col(3) = m2.col(0);
153 }

References m1, and m2().

Referenced by bug1684().

◆ bug1684_job3()

template<typename MatrixType >
EIGEN_DONT_INLINE void bug1684_job3 ( MatrixType m1,
MatrixType m2 
)
156  {
157  m2 = m1;
158  Vector4f tmp;
159  tmp = m2.col(0);
160  m2.col(0) = m2.col(3);
161  m2.col(3) = tmp;
162  tmp = m2.col(1);
163  m2.col(1) = m2.col(2);
164  m2.col(2) = tmp;
165 }
Eigen::Matrix< Scalar, Dynamic, Dynamic, ColMajor > tmp
Definition: level3_impl.h:365

References m1, m2(), and tmp.

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( array_reverse  )
181  {
182  for (int i = 0; i < g_repeat; i++) {
184  CALL_SUBTEST_2(reverse(Matrix2f()));
185  CALL_SUBTEST_3(reverse(Matrix4f()));
186  CALL_SUBTEST_4(reverse(Matrix4d()));
188  MatrixXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
190  MatrixXi(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
192  MatrixXcd(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
195  internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
196  CALL_SUBTEST_3(bug1684<0>());
197  }
198  CALL_SUBTEST_3(array_reverse_extra<0>());
199 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
void reverse(const MatrixType &m)
Definition: array_reverse.cpp:17
#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
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_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

References CALL_SUBTEST_1, 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, Eigen::g_repeat, i, and reverse().

◆ reverse()

template<typename MatrixType >
void reverse ( const MatrixType m)
17  {
18  typedef typename MatrixType::Scalar Scalar;
20 
21  Index rows = m.rows();
22  Index cols = m.cols();
23 
24  // this test relies a lot on Random.h, and there's not much more that we can do
25  // to test it, hence I consider that we will have tested Random.h
26  MatrixType m1 = MatrixType::Random(rows, cols), m2;
27  VectorType v1 = VectorType::Random(rows);
28 
29  MatrixType m1_r = m1.reverse();
30  // Verify that MatrixBase::reverse() works
31  for (int i = 0; i < rows; i++) {
32  for (int j = 0; j < cols; j++) {
33  VERIFY_IS_APPROX(m1_r(i, j), m1(rows - 1 - i, cols - 1 - j));
34  }
35  }
36 
37  Reverse<MatrixType> m1_rd(m1);
38  // Verify that a Reverse default (in both directions) of an expression works
39  for (int i = 0; i < rows; i++) {
40  for (int j = 0; j < cols; j++) {
41  VERIFY_IS_APPROX(m1_rd(i, j), m1(rows - 1 - i, cols - 1 - j));
42  }
43  }
44 
46  // Verify that a Reverse in both directions of an expression works
47  for (int i = 0; i < rows; i++) {
48  for (int j = 0; j < cols; j++) {
49  VERIFY_IS_APPROX(m1_rb(i, j), m1(rows - 1 - i, cols - 1 - j));
50  }
51  }
52 
54  // Verify that a Reverse in the vertical directions of an expression works
55  for (int i = 0; i < rows; i++) {
56  for (int j = 0; j < cols; j++) {
57  VERIFY_IS_APPROX(m1_rv(i, j), m1(rows - 1 - i, j));
58  }
59  }
60 
62  // Verify that a Reverse in the horizontal directions of an expression works
63  for (int i = 0; i < rows; i++) {
64  for (int j = 0; j < cols; j++) {
65  VERIFY_IS_APPROX(m1_rh(i, j), m1(i, cols - 1 - j));
66  }
67  }
68 
69  VectorType v1_r = v1.reverse();
70  // Verify that a VectorType::reverse() of an expression works
71  for (int i = 0; i < rows; i++) {
72  VERIFY_IS_APPROX(v1_r(i), v1(rows - 1 - i));
73  }
74 
75  MatrixType m1_cr = m1.colwise().reverse();
76  // Verify that PartialRedux::reverse() works (for colwise())
77  for (int i = 0; i < rows; i++) {
78  for (int j = 0; j < cols; j++) {
79  VERIFY_IS_APPROX(m1_cr(i, j), m1(rows - 1 - i, j));
80  }
81  }
82 
83  MatrixType m1_rr = m1.rowwise().reverse();
84  // Verify that PartialRedux::reverse() works (for rowwise())
85  for (int i = 0; i < rows; i++) {
86  for (int j = 0; j < cols; j++) {
87  VERIFY_IS_APPROX(m1_rr(i, j), m1(i, cols - 1 - j));
88  }
89  }
90 
91  Scalar x = internal::random<Scalar>();
92 
93  Index r = internal::random<Index>(0, rows - 1), c = internal::random<Index>(0, cols - 1);
94 
95  m1.reverse()(r, c) = x;
96  VERIFY_IS_APPROX(x, m1(rows - 1 - r, cols - 1 - c));
97 
98  m2 = m1;
99  m2.reverseInPlace();
100  VERIFY_IS_APPROX(m2, m1.reverse().eval());
101 
102  m2 = m1;
103  m2.col(0).reverseInPlace();
104  VERIFY_IS_APPROX(m2.col(0), m1.col(0).reverse().eval());
105 
106  m2 = m1;
107  m2.row(0).reverseInPlace();
108  VERIFY_IS_APPROX(m2.row(0), m1.row(0).reverse().eval());
109 
110  m2 = m1;
111  m2.rowwise().reverseInPlace();
112  VERIFY_IS_APPROX(m2, m1.rowwise().reverse().eval());
113 
114  m2 = m1;
115  m2.colwise().reverseInPlace();
116  VERIFY_IS_APPROX(m2, m1.colwise().reverse().eval());
117 
118  m1.colwise().reverse()(r, c) = x;
119  VERIFY_IS_APPROX(x, m1(rows - 1 - r, c));
120 
121  m1.rowwise().reverse()(r, c) = x;
122  VERIFY_IS_APPROX(x, m1(r, cols - 1 - c));
123 }
M1<< 1, 2, 3, 4, 5, 6, 7, 8, 9;Map< RowVectorXf > v1(M1.data(), M1.size())
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
Expression of the reverse of a vector or matrix.
Definition: Reverse.h:65
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
Definition: fft_test_shared.h:66
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References calibrate::c, cols, i, j, m, m1, m2(), UniformPSDSelfTest::r, rows, v1(), VERIFY_IS_APPROX, and plotDoE::x.

Referenced by Eigen::TensorEvaluator< const TensorReverseOp< ReverseDimensions, ArgType >, Device >::block(), check_indexed_view(), check_tutorial_examples(), dotcw(), dotuw(), EIGEN_DECLARE_TEST(), NurbsSurface::flipOrientation(), oomph::TriangleMeshPolyLine::reverse(), Eigen::DenseBase< Derived >::reverseInPlace(), Eigen::HouseholderSequence< VectorsType, CoeffsType, Side >::setReverseFlag(), swap(), test_eval_tensor_reverse(), test_execute_reverse_rvalue(), and testVectorType().