12 #define EIGEN_SPARSE_TRANSPOSED_COPY_PLUGIN {nb_transposed_copies++;} 13 #define VERIFY_TRANSPOSITION_COUNT(XPR,N) {\ 14 nb_transposed_copies = 0; \ 16 if(nb_transposed_copies!=N) std::cerr << "nb_transposed_copies == " << nb_transposed_copies << "\n"; \ 17 VERIFY( (#XPR) && nb_transposed_copies==N ); \ 24 for(
Index k = 0; k<mat.outerSize(); ++k)
27 for(
typename T::InnerIterator it(mat,k); it; ++it)
40 VERIFY(
int(internal::nested_eval<T,1>::type::Flags&
RowMajorBit) ==
int(internal::evaluator<T>::Flags&RowMajorBit) );
49 typedef typename SparseMatrixType::StorageIndex StorageIndex;
58 SparseMatrixType
mat(rows, cols), up(rows,cols), lo(rows,cols);
59 OtherSparseMatrixType
res;
60 DenseMatrix mat_d = DenseMatrix::Zero(rows, cols), up_sym_d, lo_sym_d, res_d;
62 initSparse<Scalar>(density, mat_d,
mat, 0);
64 up = mat.template triangularView<Upper>();
67 up_sym_d = mat_d.template selfadjointView<Upper>();
68 lo_sym_d = mat_d.template selfadjointView<Lower>();
84 VERIFY(res.isApprox(res_d) &&
"mat*p");
90 VERIFY(res.isApprox(res_d) &&
"p*mat");
95 res_d = mat*p.inverse();
96 VERIFY(res.isApprox(res_d) &&
"mat*inv(p)");
101 res_d = p.inverse()*mat_d;
102 VERIFY(res.isApprox(res_d) &&
"inv(p)*mat");
107 res_d = (p * mat_d) * p.inverse();
108 VERIFY(res.isApprox(res_d) &&
"p*mat*inv(p)");
111 VERIFY(
is_sorted( res = mat.template selfadjointView<Upper>().twistedBy(p_null) ));
113 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper to full");
115 VERIFY(
is_sorted( res = mat.template selfadjointView<Lower>().twistedBy(p_null) ));
117 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower to full");
120 VERIFY(
is_sorted( res = up.template selfadjointView<Upper>().twistedBy(p_null) ));
122 VERIFY(res.isApprox(res_d) &&
"upper selfadjoint to full");
124 VERIFY(
is_sorted( res = lo.template selfadjointView<Lower>().twistedBy(p_null) ));
126 VERIFY(res.isApprox(res_d) &&
"lower selfadjoint full");
131 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper to full");
135 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower to full");
139 VERIFY(res.isApprox(res_d) &&
"upper selfadjoint to full");
143 VERIFY(res.isApprox(res_d) &&
"lower selfadjoint full");
146 res.template selfadjointView<Upper>() = mat.template selfadjointView<Upper>();
147 res_d = up_sym_d.template triangularView<Upper>();
148 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper to upper");
150 res.template selfadjointView<Lower>() = mat.template selfadjointView<Upper>();
152 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper to lower");
154 res.template selfadjointView<Upper>() = mat.template selfadjointView<Lower>();
155 res_d = lo_sym_d.template triangularView<Upper>();
156 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower to upper");
158 res.template selfadjointView<Lower>() = mat.template selfadjointView<Lower>();
160 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower to lower");
164 res.template selfadjointView<Upper>() = mat.template selfadjointView<Upper>().twistedBy(p);
165 res_d = ((p * up_sym_d) * p.inverse()).
eval().template triangularView<Upper>();
166 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper twisted to upper");
168 res.template selfadjointView<Upper>() = mat.template selfadjointView<Lower>().twistedBy(p);
169 res_d = ((p * lo_sym_d) * p.inverse()).
eval().template triangularView<Upper>();
170 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower twisted to upper");
172 res.template selfadjointView<Lower>() = mat.template selfadjointView<Lower>().twistedBy(p);
174 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower twisted to lower");
176 res.template selfadjointView<Lower>() = mat.template selfadjointView<Upper>().twistedBy(p);
178 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper twisted to lower");
181 res.template selfadjointView<Upper>() = up.template selfadjointView<Upper>().twistedBy(p);
182 res_d = ((p * up_sym_d) * p.inverse()).
eval().template triangularView<Upper>();
183 VERIFY(res.isApprox(res_d) &&
"upper selfadjoint twisted to upper");
185 res.template selfadjointView<Upper>() = lo.template selfadjointView<Lower>().twistedBy(p);
186 res_d = ((p * lo_sym_d) * p.inverse()).
eval().template triangularView<Upper>();
187 VERIFY(res.isApprox(res_d) &&
"lower selfadjoint twisted to upper");
189 res.template selfadjointView<Lower>() = lo.template selfadjointView<Lower>().twistedBy(p);
191 VERIFY(res.isApprox(res_d) &&
"lower selfadjoint twisted to lower");
193 res.template selfadjointView<Lower>() = up.template selfadjointView<Upper>().twistedBy(p);
195 VERIFY(res.isApprox(res_d) &&
"upper selfadjoint twisted to lower");
198 VERIFY(
is_sorted( res = mat.template selfadjointView<Upper>().twistedBy(p) ));
199 res_d = (p * up_sym_d) * p.inverse();
200 VERIFY(res.isApprox(res_d) &&
"full selfadjoint upper twisted to full");
202 VERIFY(
is_sorted( res = mat.template selfadjointView<Lower>().twistedBy(p) ));
203 res_d = (p * lo_sym_d) * p.inverse();
204 VERIFY(res.isApprox(res_d) &&
"full selfadjoint lower twisted to full");
206 VERIFY(
is_sorted( res = up.template selfadjointView<Upper>().twistedBy(p) ));
207 res_d = (p * up_sym_d) * p.inverse();
208 VERIFY(res.isApprox(res_d) &&
"upper selfadjoint twisted to full");
210 VERIFY(
is_sorted( res = lo.template selfadjointView<Lower>().twistedBy(p) ));
211 res_d = (p * lo_sym_d) * p.inverse();
212 VERIFY(res.isApprox(res_d) &&
"lower selfadjoint twisted to full");
226 int s = Eigen::internal::random<int>(1,50);
Matrix< Scalar, Dynamic, Dynamic > DenseMatrix
bool is_sorted(const T &mat)
Expression of the product of two arbitrary matrices or vectors.
A versatible sparse matrix representation.
static long int nb_transposed_copies
void randomPermutationVector(PermutationVectorType &v, Index size)
const unsigned int RowMajorBit
cout<< "Here is the matrix m:"<< endl<< m<< endl;Matrix< ptrdiff_t, 3, 1 > res
#define VERIFY_IS_APPROX(a, b)
#define CALL_SUBTEST_1(FUNC)
const IndicesType & indices() const
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Reference counting helper.
#define CALL_SUBTEST(FUNC)
A triangularView< Lower >().adjoint().solveInPlace(B)
#define VERIFY_TRANSPOSITION_COUNT(XPR, N)
void sparse_permutations_all(int size)
#define CALL_SUBTEST_2(FUNC)
internal::nested_eval< T, 1 >::type eval(const T &xpr)
Generic expression where a coefficient-wise unary operator is applied to an expression.
void sparse_permutations(const SparseMatrixType &ref)
EIGEN_DECLARE_TEST(sparse_permutations)