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

Macros

#define TEST_ENABLE_TEMPORARY_TRACKING
 

Functions

template<typename MatrixType >
void permutationmatrices (const MatrixType &m)
 
template<typename T >
void bug890 ()
 
 EIGEN_DECLARE_TEST (permutationmatrices)
 

Macro Definition Documentation

◆ TEST_ENABLE_TEMPORARY_TRACKING

#define TEST_ENABLE_TEMPORARY_TRACKING

Function Documentation

◆ bug890()

template<typename T >
void bug890 ( )
150  {
153  typedef Stride<Dynamic, Dynamic> S;
155  typedef PermutationMatrix<Dynamic> Perm;
156 
157  VectorType v1(2), v2(2), op(4), rhs(2);
158  v1 << 666, 667;
159  op << 1, 0, 0, 1;
160  rhs << 42, 42;
161 
162  Perm P(2);
163  P.indices() << 1, 0;
164 
165  MapType(v1.data(), 2, 1, S(1, 1)) = P * MapType(rhs.data(), 2, 1, S(1, 1));
166  VERIFY_IS_APPROX(v1, (P * rhs).eval());
167 
168  MapType(v1.data(), 2, 1, S(1, 1)) = P.inverse() * MapType(rhs.data(), 2, 1, S(1, 1));
169  VERIFY_IS_APPROX(v1, (P.inverse() * rhs).eval());
170 }
Map< MatrixType > MapType
Definition: Tutorial_Map_using.cpp:2
Map< RowVectorXf > v2(M2.data(), M2.size())
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
A matrix or vector expression mapping an existing array of data.
Definition: Map.h:96
The matrix class, also used for vectors and row-vectors.
Definition: Eigen/Eigen/src/Core/Matrix.h:186
Permutation matrix.
Definition: PermutationMatrix.h:280
Holds strides information for Map.
Definition: Stride.h:55
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
char char * op
Definition: level2_impl.h:374
double P
Uniform pressure.
Definition: TwenteMeshGluing.cpp:77
@ S
Definition: quadtree.h:62
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
Definition: fft_test_shared.h:66

References eval(), op, Global_Physical_Variables::P, oomph::QuadTreeNames::S, v1(), v2(), and VERIFY_IS_APPROX.

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( permutationmatrices  )
172  {
173  for (int i = 0; i < g_repeat; i++) {
175  CALL_SUBTEST_2(permutationmatrices(Matrix3f()));
177  CALL_SUBTEST_4(permutationmatrices(Matrix4d()));
180  internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
182  MatrixXcf(internal::random<int>(1, EIGEN_TEST_MAX_SIZE), internal::random<int>(1, EIGEN_TEST_MAX_SIZE))));
183  }
184  CALL_SUBTEST_5(bug890<double>());
185 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
#define EIGEN_TEST_MAX_SIZE
Definition: boostmultiprec.cpp:16
static int g_repeat
Definition: main.h:191
void permutationmatrices(const MatrixType &m)
Definition: permutationmatrices.cpp:16
#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_7(FUNC)
Definition: split_test_helper.h:40
#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, CALL_SUBTEST_7, EIGEN_TEST_MAX_SIZE, Eigen::g_repeat, i, and permutationmatrices().

◆ permutationmatrices()

template<typename MatrixType >
void permutationmatrices ( const MatrixType m)
16  {
17  typedef typename MatrixType::Scalar Scalar;
18  enum { Rows = MatrixType::RowsAtCompileTime, Cols = MatrixType::ColsAtCompileTime, Options = MatrixType::Options };
19  typedef PermutationMatrix<Rows> LeftPermutationType;
20  typedef Transpositions<Rows> LeftTranspositionsType;
21  typedef Matrix<int, Rows, 1> LeftPermutationVectorType;
22  typedef Map<LeftPermutationType> MapLeftPerm;
23  typedef PermutationMatrix<Cols> RightPermutationType;
24  typedef Transpositions<Cols> RightTranspositionsType;
25  typedef Matrix<int, Cols, 1> RightPermutationVectorType;
26  typedef Map<RightPermutationType> MapRightPerm;
27 
28  Index rows = m.rows();
29  Index cols = m.cols();
30 
31  MatrixType m_original = MatrixType::Random(rows, cols);
32  LeftPermutationVectorType lv;
34  LeftPermutationType lp(lv);
35  RightPermutationVectorType rv;
37  RightPermutationType rp(rv);
38  LeftTranspositionsType lt(lv);
39  RightTranspositionsType rt(rv);
40  MatrixType m_permuted = MatrixType::Random(rows, cols);
41 
42  VERIFY_EVALUATION_COUNT(m_permuted = lp * m_original * rp, 1); // 1 temp for sub expression "lp * m_original"
43 
44  for (int i = 0; i < rows; i++)
45  for (int j = 0; j < cols; j++) VERIFY_IS_APPROX(m_permuted(lv(i), j), m_original(i, rv(j)));
46 
49 
50  VERIFY_IS_APPROX(m_permuted, lm * m_original * rm);
51 
52  m_permuted = m_original;
53  VERIFY_EVALUATION_COUNT(m_permuted = lp * m_permuted * rp, 1);
54  VERIFY_IS_APPROX(m_permuted, lm * m_original * rm);
55 
56  LeftPermutationType lpi;
57  lpi = lp.inverse();
58  VERIFY_IS_APPROX(lpi * m_permuted, lp.inverse() * m_permuted);
59 
60  VERIFY_IS_APPROX(lp.inverse() * m_permuted * rp.inverse(), m_original);
61  VERIFY_IS_APPROX(lv.asPermutation().inverse() * m_permuted * rv.asPermutation().inverse(), m_original);
63  MapLeftPerm(lv.data(), lv.size()).inverse() * m_permuted * MapRightPerm(rv.data(), rv.size()).inverse(),
64  m_original);
65 
66  VERIFY((lp * lp.inverse()).toDenseMatrix().isIdentity());
67  VERIFY((lv.asPermutation() * lv.asPermutation().inverse()).toDenseMatrix().isIdentity());
68  VERIFY(
69  (MapLeftPerm(lv.data(), lv.size()) * MapLeftPerm(lv.data(), lv.size()).inverse()).toDenseMatrix().isIdentity());
70 
71  LeftPermutationVectorType lv2;
73  LeftPermutationType lp2(lv2);
75  VERIFY_IS_APPROX((lp * lp2).toDenseMatrix().template cast<Scalar>(), lm * lm2);
76  VERIFY_IS_APPROX((lv.asPermutation() * lv2.asPermutation()).toDenseMatrix().template cast<Scalar>(), lm * lm2);
78  (MapLeftPerm(lv.data(), lv.size()) * MapLeftPerm(lv2.data(), lv2.size())).toDenseMatrix().template cast<Scalar>(),
79  lm * lm2);
80 
81  LeftPermutationType identityp;
82  identityp.setIdentity(rows);
83  VERIFY_IS_APPROX(m_original, identityp * m_original);
84 
85  // check inplace permutations
86  m_permuted = m_original;
87  VERIFY_EVALUATION_COUNT(m_permuted.noalias() = lp.inverse() * m_permuted, 1); // 1 temp to allocate the mask
88  VERIFY_IS_APPROX(m_permuted, lp.inverse() * m_original);
89 
90  m_permuted = m_original;
91  VERIFY_EVALUATION_COUNT(m_permuted.noalias() = m_permuted * rp.inverse(), 1); // 1 temp to allocate the mask
92  VERIFY_IS_APPROX(m_permuted, m_original * rp.inverse());
93 
94  m_permuted = m_original;
95  VERIFY_EVALUATION_COUNT(m_permuted.noalias() = lp * m_permuted, 1); // 1 temp to allocate the mask
96  VERIFY_IS_APPROX(m_permuted, lp * m_original);
97 
98  m_permuted = m_original;
99  VERIFY_EVALUATION_COUNT(m_permuted.noalias() = m_permuted * rp, 1); // 1 temp to allocate the mask
100  VERIFY_IS_APPROX(m_permuted, m_original * rp);
101 
102  if (rows > 1 && cols > 1) {
103  lp2 = lp;
104  Index i = internal::random<Index>(0, rows - 1);
105  Index j;
106  do j = internal::random<Index>(0, rows - 1);
107  while (j == i);
108  lp2.applyTranspositionOnTheLeft(i, j);
109  lm = lp;
110  lm.row(i).swap(lm.row(j));
111  VERIFY_IS_APPROX(lm, lp2.toDenseMatrix().template cast<Scalar>());
112 
113  RightPermutationType rp2 = rp;
114  i = internal::random<Index>(0, cols - 1);
115  do j = internal::random<Index>(0, cols - 1);
116  while (j == i);
117  rp2.applyTranspositionOnTheRight(i, j);
118  rm = rp;
119  rm.col(i).swap(rm.col(j));
120  VERIFY_IS_APPROX(rm, rp2.toDenseMatrix().template cast<Scalar>());
121  }
122 
123  {
124  // simple compilation check
126  Matrix<Scalar, Cols, Cols> B = rp.transpose();
127  VERIFY_IS_APPROX(A, B.transpose());
128  }
129 
130  m_permuted = m_original;
131  lp = lt;
132  rp = rt;
133  VERIFY_EVALUATION_COUNT(m_permuted = lt * m_permuted * rt, 1);
134  VERIFY_IS_APPROX(m_permuted, lp * m_original * rp.transpose());
135 
136  VERIFY_IS_APPROX(lt.inverse() * m_permuted * rt.inverse(), m_original);
137 
138  // Check inplace transpositions
139  m_permuted = m_original;
140  VERIFY_IS_APPROX(m_permuted = lt * m_permuted, lp * m_original);
141  m_permuted = m_original;
142  VERIFY_IS_APPROX(m_permuted = lt.inverse() * m_permuted, lp.inverse() * m_original);
143  m_permuted = m_original;
144  VERIFY_IS_APPROX(m_permuted = m_permuted * rt, m_original * rt);
145  m_permuted = m_original;
146  VERIFY_IS_APPROX(m_permuted = m_permuted * rt.inverse(), m_original * rt.inverse());
147 }
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
Represents a sequence of transpositions (row/column interchange)
Definition: Transpositions.h:141
Definition: matrices.h:74
int * m
Definition: level2_cplx_impl.h:294
#define VERIFY(a)
Definition: main.h:362
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83
void randomPermutationVector(PermutationVectorType &v, Index size)
Definition: random_matrix_helper.h:101
#define VERIFY_EVALUATION_COUNT(XPR, N)
Definition: test/sparse_product.cpp:28
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2

References cols, i, j, m, Eigen::randomPermutationVector(), rows, Eigen::PlainObjectBase< Derived >::swap(), VERIFY, VERIFY_EVALUATION_COUNT, and VERIFY_IS_APPROX.

Referenced by EIGEN_DECLARE_TEST().