MCPcopy Create free account
hub / github.com/Derious/cuMPC / sparse_permutations

Function sparse_permutations

dependence/eigen-3.4.0/test/sparse_permutations.cpp:44–213  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

42}
43
44template<int OtherStorage, typename SparseMatrixType> void sparse_permutations(const SparseMatrixType& ref)
45{
46 const Index rows = ref.rows();
47 const Index cols = ref.cols();
48 typedef typename SparseMatrixType::Scalar Scalar;
49 typedef typename SparseMatrixType::StorageIndex StorageIndex;
50 typedef SparseMatrix<Scalar, OtherStorage, StorageIndex> OtherSparseMatrixType;
51 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
52 typedef Matrix<StorageIndex,Dynamic,1> VectorI;
53// bool IsRowMajor1 = SparseMatrixType::IsRowMajor;
54// bool IsRowMajor2 = OtherSparseMatrixType::IsRowMajor;
55
56 double density = (std::max)(8./(rows*cols), 0.01);
57
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;
61
62 initSparse<Scalar>(density, mat_d, mat, 0);
63
64 up = mat.template triangularView<Upper>();
65 lo = mat.template triangularView<Lower>();
66
67 up_sym_d = mat_d.template selfadjointView<Upper>();
68 lo_sym_d = mat_d.template selfadjointView<Lower>();
69
70 VERIFY_IS_APPROX(mat, mat_d);
71 VERIFY_IS_APPROX(up, DenseMatrix(mat_d.template triangularView<Upper>()));
72 VERIFY_IS_APPROX(lo, DenseMatrix(mat_d.template triangularView<Lower>()));
73
74 PermutationMatrix<Dynamic> p, p_null;
75 VectorI pi;
76 randomPermutationVector(pi, cols);
77 p.indices() = pi;
78
79 VERIFY( is_sorted( ::eval(mat*p) ));
80 VERIFY( is_sorted( res = mat*p ));
81 VERIFY_TRANSPOSITION_COUNT( ::eval(mat*p), 0);
82 //VERIFY_TRANSPOSITION_COUNT( res = mat*p, IsRowMajor ? 1 : 0 );
83 res_d = mat_d*p;
84 VERIFY(res.isApprox(res_d) && "mat*p");
85
86 VERIFY( is_sorted( ::eval(p*mat) ));
87 VERIFY( is_sorted( res = p*mat ));
88 VERIFY_TRANSPOSITION_COUNT( ::eval(p*mat), 0);
89 res_d = p*mat_d;
90 VERIFY(res.isApprox(res_d) && "p*mat");
91
92 VERIFY( is_sorted( (mat*p).eval() ));
93 VERIFY( is_sorted( res = mat*p.inverse() ));
94 VERIFY_TRANSPOSITION_COUNT( ::eval(mat*p.inverse()), 0);
95 res_d = mat*p.inverse();
96 VERIFY(res.isApprox(res_d) && "mat*inv(p)");
97
98 VERIFY( is_sorted( (p*mat+p*mat).eval() ));
99 VERIFY( is_sorted( res = p.inverse()*mat ));
100 VERIFY_TRANSPOSITION_COUNT( ::eval(p.inverse()*mat), 0);
101 res_d = p.inverse()*mat_d;

Callers

nothing calls this directly

Calls 9

randomPermutationVectorFunction · 0.85
is_sortedFunction · 0.70
evalFunction · 0.70
rowsMethod · 0.45
colsMethod · 0.45
isApproxMethod · 0.45
evalMethod · 0.45
inverseMethod · 0.45
twistedByMethod · 0.45

Tested by

no test coverage detected