sparse_permutations.cpp File Reference
#include "sparse.h"

Macros

#define EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN    { nb_transposed_copies++; }
 
#define VERIFY_TRANSPOSITION_COUNT(XPR, N)
 
#define EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN    { nb_temporaries++; }
 
#define VERIFY_TEMPORARY_COUNT(XPR, N)
 

Functions

template<typename T >
bool is_sorted (const T &mat)
 
template<typename T >
internal::nested_eval< T, 1 >::type eval (const T &xpr)
 
template<int OtherStorage, typename SparseMatrixType >
void sparse_permutations (const SparseMatrixType &ref)
 
template<typename Scalar >
void sparse_permutations_all (int size)
 
 EIGEN_DECLARE_TEST (sparse_permutations)
 

Variables

static long int nb_transposed_copies
 
static long int nb_temporaries
 

Macro Definition Documentation

◆ EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN

#define EIGEN_SPARSE_CREATE_TEMPORARY_PLUGIN    { nb_temporaries++; }

◆ EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN

#define EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN    { nb_transposed_copies++; }

◆ VERIFY_TEMPORARY_COUNT

#define VERIFY_TEMPORARY_COUNT (   XPR,
  N 
)
Value:
{ \
nb_temporaries = 0; \
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_permutations.cpp:21

◆ VERIFY_TRANSPOSITION_COUNT

#define VERIFY_TRANSPOSITION_COUNT (   XPR,
  N 
)
Value:
{ \
nb_transposed_copies = 0; \
XPR; \
if (nb_transposed_copies != N) std::cerr << "nb_transposed_copies == " << nb_transposed_copies << "\n"; \
VERIFY((#XPR) && nb_transposed_copies == N); \
}
static long int nb_transposed_copies
Definition: sparse_permutations.cpp:10

Function Documentation

◆ EIGEN_DECLARE_TEST()

EIGEN_DECLARE_TEST ( sparse_permutations  )
229  {
230  for (int i = 0; i < g_repeat; i++) {
231  int s = Eigen::internal::random<int>(1, 50);
232  CALL_SUBTEST_1((sparse_permutations_all<double>(s)));
233  CALL_SUBTEST_2((sparse_permutations_all<std::complex<double> >(s)));
234  }
235 
236  VERIFY((internal::is_same<
237  internal::permutation_matrix_product<SparseMatrix<double>, OnTheRight, false, SparseShape>::ReturnType,
239  1>::type>::value));
240 
241  VERIFY((internal::is_same<
242  internal::permutation_matrix_product<SparseMatrix<double>, OnTheLeft, false, SparseShape>::ReturnType,
244  1>::type>::value));
245 }
int i
Definition: BiCGSTAB_step_by_step.cpp:9
Expression of the product of two arbitrary matrices or vectors.
Definition: Product.h:202
@ AliasFreeProduct
Definition: Constants.h:505
@ OnTheLeft
Definition: Constants.h:331
@ OnTheRight
Definition: Constants.h:333
RealScalar s
Definition: level1_cplx_impl.h:130
#define VERIFY(a)
Definition: main.h:362
squared absolute value
Definition: GlobalFunctions.h:87
static int g_repeat
Definition: main.h:191
type
Definition: compute_granudrum_aor.py:141
void sparse_permutations_all(int size)
Definition: sparse_permutations.cpp:222
#define CALL_SUBTEST_1(FUNC)
Definition: split_test_helper.h:4
#define CALL_SUBTEST_2(FUNC)
Definition: split_test_helper.h:10
Definition: Constants.h:570

References Eigen::AliasFreeProduct, CALL_SUBTEST_1, CALL_SUBTEST_2, Eigen::g_repeat, i, Eigen::OnTheLeft, Eigen::OnTheRight, s, sparse_permutations_all(), compute_granudrum_aor::type, Eigen::value, and VERIFY.

◆ eval()

template<typename T >
internal::nested_eval<T, 1>::type eval ( const T xpr)
Examples
/home/plath/mercurydpm2/mercurydpm/Eigen/unsupported/Eigen/CXX11/src/Tensor/TensorLayoutSwap.h.
47  {
48  VERIFY(int(internal::nested_eval<T, 1>::type::Flags & RowMajorBit) ==
49  int(internal::evaluator<T>::Flags & RowMajorBit));
50  return xpr;
51 }
const unsigned int RowMajorBit
Definition: Constants.h:70

References Eigen::RowMajorBit, and VERIFY.

Referenced by array_complex(), array_real(), block(), bug890(), CauchyBounds(), check_indexed_view(), check_symbolic_index(), Eigen::MatrixBase< Derived >::colPivHouseholderQr(), Eigen::MatrixBase< Derived >::completeOrthogonalDecomposition(), Eigen::MatrixPowerAtomic< MatrixType >::computePade(), determinant(), EIGEN_DECLARE_TEST(), Eigen::MatrixBase< Derived >::fullPivHouseholderQr(), Eigen::MatrixBase< Derived >::fullPivLu(), Eigen::MatrixBase< Derived >::householderQr(), Eigen::MatrixBase< Derived >::lu(), main(), matrixVisitor(), mixingtypes(), Eigen::MatrixBase< Derived >::partialPivLu(), product(), product_large_regressions(), product_selfadjoint(), qr_kahan_matrix(), MandelbrotThread::render(), Eigen::internal::default_inner_product_impl< Lhs, Rhs, Conj >::run(), Eigen::internal::TensorBlockAssignment< Scalar, NumDims, TensorBlockExpr, IndexType >::Run(), Eigen::TensorBase< Derived, AccessLevel >::setValues(), sparse_basic(), sparse_block(), sparse_permutations(), sparse_product(), symm(), test_evals(), test_forced_eval_sycl(), test_linear_but_not_vectorizable(), test_multidims(), test_simple(), testMatrixType(), transformations(), vectorwiseop_matrix(), VerifyBlockAssignment(), and VerifyBlockEvaluator().

◆ is_sorted()

template<typename T >
bool is_sorted ( const T mat)
35  {
36  for (Index k = 0; k < mat.outerSize(); ++k) {
37  Index prev = -1;
38  for (typename T::InnerIterator it(mat, k); it; ++it) {
39  if (prev >= it.index()) return false;
40  prev = it.index();
41  }
42  }
43  return true;
44 }
Index outerSize() const
Definition: SparseMatrix.h:166
char char char int int * k
Definition: level2_impl.h:374
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:83

References k, and Eigen::SparseMatrix< Scalar_, Options_, StorageIndex_ >::outerSize().

Referenced by Eigen::internal::inner_sort_impl< Derived, Comp, IsVector >::check(), Eigen::internal::inner_sort_impl< Derived, Comp, true >::check(), NurbsUtils::isKnotVectorMonotonic(), sparse_permutations(), and test_stl_iterators().

◆ sparse_permutations()

template<int OtherStorage, typename SparseMatrixType >
void sparse_permutations ( const SparseMatrixType &  ref)
54  {
55  const Index rows = ref.rows();
56  const Index cols = ref.cols();
57  typedef typename SparseMatrixType::Scalar Scalar;
58  typedef typename SparseMatrixType::StorageIndex StorageIndex;
59  typedef SparseMatrix<Scalar, OtherStorage, StorageIndex> OtherSparseMatrixType;
61  typedef Matrix<StorageIndex, Dynamic, 1> VectorI;
62  // bool IsRowMajor1 = SparseMatrixType::IsRowMajor;
63  // bool IsRowMajor2 = OtherSparseMatrixType::IsRowMajor;
64 
65  double density = (std::max)(8. / static_cast<double>(rows * cols), 0.01);
66 
67  SparseMatrixType mat(rows, cols), up(rows, cols), lo(rows, cols);
68  OtherSparseMatrixType res;
69  DenseMatrix mat_d = DenseMatrix::Zero(rows, cols), up_sym_d, lo_sym_d, res_d;
70 
71  initSparse<Scalar>(density, mat_d, mat, 0);
72 
73  up = mat.template triangularView<Upper>();
74  lo = mat.template triangularView<Lower>();
75 
76  up_sym_d = mat_d.template selfadjointView<Upper>();
77  lo_sym_d = mat_d.template selfadjointView<Lower>();
78 
79  VERIFY_IS_APPROX(mat, mat_d);
80  VERIFY_IS_APPROX(up, DenseMatrix(mat_d.template triangularView<Upper>()));
81  VERIFY_IS_APPROX(lo, DenseMatrix(mat_d.template triangularView<Lower>()));
82 
84  VectorI pi;
86  p.indices() = pi;
87 
88  VERIFY(is_sorted(::eval(mat * p)));
89  VERIFY(is_sorted(res = mat * p));
92  res_d = mat_d * p;
93  VERIFY(res.isApprox(res_d) && "mat*p");
94 
95  VERIFY(is_sorted(::eval(p * mat)));
96  VERIFY(is_sorted(res = p * mat));
99  res_d = p * mat_d;
100  VERIFY(res.isApprox(res_d) && "p*mat");
101 
102  VERIFY(is_sorted((mat * p).eval()));
103  VERIFY(is_sorted(res = mat * p.inverse()));
106  res_d = mat * p.inverse();
107  VERIFY(res.isApprox(res_d) && "mat*inv(p)");
108 
109  VERIFY(is_sorted((p * mat + p * mat).eval()));
110  VERIFY(is_sorted(res = p.inverse() * mat));
113  res_d = p.inverse() * mat_d;
114  VERIFY(res.isApprox(res_d) && "inv(p)*mat");
115 
116  //
117 
118  VERIFY(is_sorted((p * mat * p.inverse()).eval()));
119  VERIFY(is_sorted(res = mat.twistedBy(p)));
121  res_d = (p * mat_d) * p.inverse();
122  VERIFY(res.isApprox(res_d) && "p*mat*inv(p)");
123 
124  VERIFY(is_sorted(res = mat.template selfadjointView<Upper>().twistedBy(p_null)));
125  res_d = up_sym_d;
126  VERIFY(res.isApprox(res_d) && "full selfadjoint upper to full");
127 
128  VERIFY(is_sorted(res = mat.template selfadjointView<Lower>().twistedBy(p_null)));
129  res_d = lo_sym_d;
130  VERIFY(res.isApprox(res_d) && "full selfadjoint lower to full");
131 
132  VERIFY(is_sorted(res = up.template selfadjointView<Upper>().twistedBy(p_null)));
133  res_d = up_sym_d;
134  VERIFY(res.isApprox(res_d) && "upper selfadjoint to full");
135 
136  VERIFY(is_sorted(res = lo.template selfadjointView<Lower>().twistedBy(p_null)));
137  res_d = lo_sym_d;
138  VERIFY(res.isApprox(res_d) && "lower selfadjoint full");
139 
140  VERIFY(is_sorted(res = mat.template selfadjointView<Upper>()));
141  res_d = up_sym_d;
142  VERIFY(res.isApprox(res_d) && "full selfadjoint upper to full");
143 
144  VERIFY(is_sorted(res = mat.template selfadjointView<Lower>()));
145  res_d = lo_sym_d;
146  VERIFY(res.isApprox(res_d) && "full selfadjoint lower to full");
147 
148  VERIFY(is_sorted(res = up.template selfadjointView<Upper>()));
149  res_d = up_sym_d;
150  VERIFY(res.isApprox(res_d) && "upper selfadjoint to full");
151 
152  VERIFY(is_sorted(res = lo.template selfadjointView<Lower>()));
153  res_d = lo_sym_d;
154  VERIFY(res.isApprox(res_d) && "lower selfadjoint full");
155 
156  res.template selfadjointView<Upper>() = mat.template selfadjointView<Upper>();
157  res_d = up_sym_d.template triangularView<Upper>();
158  VERIFY(res.isApprox(res_d) && "full selfadjoint upper to upper");
159 
160  res.template selfadjointView<Lower>() = mat.template selfadjointView<Upper>();
161  res_d = up_sym_d.template triangularView<Lower>();
162  VERIFY(res.isApprox(res_d) && "full selfadjoint upper to lower");
163 
164  res.template selfadjointView<Upper>() = mat.template selfadjointView<Lower>();
165  res_d = lo_sym_d.template triangularView<Upper>();
166  VERIFY(res.isApprox(res_d) && "full selfadjoint lower to upper");
167 
168  res.template selfadjointView<Lower>() = mat.template selfadjointView<Lower>();
169  res_d = lo_sym_d.template triangularView<Lower>();
170  VERIFY(res.isApprox(res_d) && "full selfadjoint lower to lower");
171 
172  res.template selfadjointView<Upper>() = mat.template selfadjointView<Upper>().twistedBy(p);
173  res_d = ((p * up_sym_d) * p.inverse()).eval().template triangularView<Upper>();
174  VERIFY(res.isApprox(res_d) && "full selfadjoint upper twisted to upper");
175 
176  res.template selfadjointView<Upper>() = mat.template selfadjointView<Lower>().twistedBy(p);
177  res_d = ((p * lo_sym_d) * p.inverse()).eval().template triangularView<Upper>();
178  VERIFY(res.isApprox(res_d) && "full selfadjoint lower twisted to upper");
179 
180  res.template selfadjointView<Lower>() = mat.template selfadjointView<Lower>().twistedBy(p);
181  res_d = ((p * lo_sym_d) * p.inverse()).eval().template triangularView<Lower>();
182  VERIFY(res.isApprox(res_d) && "full selfadjoint lower twisted to lower");
183 
184  res.template selfadjointView<Lower>() = mat.template selfadjointView<Upper>().twistedBy(p);
185  res_d = ((p * up_sym_d) * p.inverse()).eval().template triangularView<Lower>();
186  VERIFY(res.isApprox(res_d) && "full selfadjoint upper twisted to lower");
187 
188  res.template selfadjointView<Upper>() = up.template selfadjointView<Upper>().twistedBy(p);
189  res_d = ((p * up_sym_d) * p.inverse()).eval().template triangularView<Upper>();
190  VERIFY(res.isApprox(res_d) && "upper selfadjoint twisted to upper");
191 
192  res.template selfadjointView<Upper>() = lo.template selfadjointView<Lower>().twistedBy(p);
193  res_d = ((p * lo_sym_d) * p.inverse()).eval().template triangularView<Upper>();
194  VERIFY(res.isApprox(res_d) && "lower selfadjoint twisted to upper");
195 
196  res.template selfadjointView<Lower>() = lo.template selfadjointView<Lower>().twistedBy(p);
197  res_d = ((p * lo_sym_d) * p.inverse()).eval().template triangularView<Lower>();
198  VERIFY(res.isApprox(res_d) && "lower selfadjoint twisted to lower");
199 
200  res.template selfadjointView<Lower>() = up.template selfadjointView<Upper>().twistedBy(p);
201  res_d = ((p * up_sym_d) * p.inverse()).eval().template triangularView<Lower>();
202  VERIFY(res.isApprox(res_d) && "upper selfadjoint twisted to lower");
203 
204  VERIFY(is_sorted(res = mat.template selfadjointView<Upper>().twistedBy(p)));
205  res_d = (p * up_sym_d) * p.inverse();
206  VERIFY(res.isApprox(res_d) && "full selfadjoint upper twisted to full");
207 
208  VERIFY(is_sorted(res = mat.template selfadjointView<Lower>().twistedBy(p)));
209  res_d = (p * lo_sym_d) * p.inverse();
210  VERIFY(res.isApprox(res_d) && "full selfadjoint lower twisted to full");
211 
212  VERIFY(is_sorted(res = up.template selfadjointView<Upper>().twistedBy(p)));
213  res_d = (p * up_sym_d) * p.inverse();
214  VERIFY(res.isApprox(res_d) && "upper selfadjoint twisted to full");
215 
216  VERIFY(is_sorted(res = lo.template selfadjointView<Lower>().twistedBy(p)));
217  res_d = (p * lo_sym_d) * p.inverse();
218  VERIFY(res.isApprox(res_d) && "lower selfadjoint twisted to full");
219 }
Matrix< Scalar, Dynamic, Dynamic > DenseMatrix
Definition: BenchSparseUtil.h:23
Eigen::SparseMatrix< double > mat
Definition: EigenUnitTest.cpp:10
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
Definition: PartialRedux_count.cpp:3
float * p
Definition: Tutorial_Map_using.cpp:9
int rows
Definition: Tutorial_commainit_02.cpp:1
int cols
Definition: Tutorial_commainit_02.cpp:1
SCALAR Scalar
Definition: bench_gemm.cpp:45
#define max(a, b)
Definition: datatypes.h:23
@ Lower
Definition: Constants.h:211
@ Upper
Definition: Constants.h:213
#define VERIFY_IS_APPROX(a, b)
Definition: integer_types.cpp:13
void inverse(const MatrixType &m)
Definition: inverse.cpp:64
EIGEN_DEVICE_FUNC bool isApprox(const Scalar &x, const Scalar &y, const typename NumTraits< Scalar >::Real &precision=NumTraits< Scalar >::dummy_precision())
Definition: MathFunctions.h:1923
void randomPermutationVector(PermutationVectorType &v, Index size)
Definition: random_matrix_helper.h:101
density
Definition: UniformPSDSelfTest.py:19
const Mdouble pi
Definition: ExtendedMath.h:23
std::string lower(std::string s)
returns the input string after converting upper-case characters to lower case
Definition: StringHelpers.cc:11
double Zero
Definition: pseudosolid_node_update_elements.cc:35
void selfadjoint(const MatrixType &m)
Definition: selfadjoint.cpp:17
bool is_sorted(const T &mat)
Definition: sparse_permutations.cpp:35
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Definition: sparse_permutations.cpp:47
#define VERIFY_TEMPORARY_COUNT(XPR, N)
Definition: sparse_permutations.cpp:24
#define VERIFY_TRANSPOSITION_COUNT(XPR, N)
Definition: sparse_permutations.cpp:13

References cols, UniformPSDSelfTest::density, eval(), is_sorted(), max, p, constants::pi, Eigen::randomPermutationVector(), res, rows, Eigen::SparseMatrixBase< Derived >::twistedBy(), VERIFY, VERIFY_IS_APPROX, VERIFY_TEMPORARY_COUNT, VERIFY_TRANSPOSITION_COUNT, and oomph::PseudoSolidHelper::Zero.

◆ sparse_permutations_all()

template<typename Scalar >
void sparse_permutations_all ( int  size)
222  {
223  CALL_SUBTEST((sparse_permutations<ColMajor>(SparseMatrix<Scalar, ColMajor>(size, size))));
224  CALL_SUBTEST((sparse_permutations<ColMajor>(SparseMatrix<Scalar, RowMajor>(size, size))));
225  CALL_SUBTEST((sparse_permutations<RowMajor>(SparseMatrix<Scalar, ColMajor>(size, size))));
226  CALL_SUBTEST((sparse_permutations<RowMajor>(SparseMatrix<Scalar, RowMajor>(size, size))));
227 }
Scalar Scalar int size
Definition: benchVecAdd.cpp:17
#define CALL_SUBTEST(FUNC)
Definition: main.h:382

References CALL_SUBTEST, and size.

Referenced by EIGEN_DECLARE_TEST().

Variable Documentation

◆ nb_temporaries

long int nb_temporaries
static

Referenced by EIGEN_DECLARE_TEST(), and use_n_times().

◆ nb_transposed_copies

long int nb_transposed_copies
static