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

Function sparse_block

dependence/eigen-3.4.0/test/sparse_block.cpp:27–291  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25}
26
27template<typename SparseMatrixType> void sparse_block(const SparseMatrixType& ref)
28{
29 const Index rows = ref.rows();
30 const Index cols = ref.cols();
31 const Index inner = ref.innerSize();
32 const Index outer = ref.outerSize();
33
34 typedef typename SparseMatrixType::Scalar Scalar;
35 typedef typename SparseMatrixType::RealScalar RealScalar;
36 typedef typename SparseMatrixType::StorageIndex StorageIndex;
37
38 double density = (std::max)(8./(rows*cols), 0.01);
39 typedef Matrix<Scalar,Dynamic,Dynamic,SparseMatrixType::IsRowMajor?RowMajor:ColMajor> DenseMatrix;
40 typedef Matrix<Scalar,Dynamic,1> DenseVector;
41 typedef Matrix<Scalar,1,Dynamic> RowDenseVector;
42 typedef SparseVector<Scalar> SparseVectorType;
43
44 Scalar s1 = internal::random<Scalar>();
45 {
46 SparseMatrixType m(rows, cols);
47 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
48 initSparse<Scalar>(density, refMat, m);
49
50 VERIFY_IS_APPROX(m, refMat);
51
52 // test InnerIterators and Block expressions
53 for (int t=0; t<10; ++t)
54 {
55 Index j = internal::random<Index>(0,cols-2);
56 Index i = internal::random<Index>(0,rows-2);
57 Index w = internal::random<Index>(1,cols-j);
58 Index h = internal::random<Index>(1,rows-i);
59
60 VERIFY_IS_APPROX(m.block(i,j,h,w), refMat.block(i,j,h,w));
61 for(Index c=0; c<w; c++)
62 {
63 VERIFY_IS_APPROX(m.block(i,j,h,w).col(c), refMat.block(i,j,h,w).col(c));
64 for(Index r=0; r<h; r++)
65 {
66 VERIFY_IS_APPROX(m.block(i,j,h,w).col(c).coeff(r), refMat.block(i,j,h,w).col(c).coeff(r));
67 VERIFY_IS_APPROX(m.block(i,j,h,w).coeff(r,c), refMat.block(i,j,h,w).coeff(r,c));
68 }
69 }
70 for(Index r=0; r<h; r++)
71 {
72 VERIFY_IS_APPROX(m.block(i,j,h,w).row(r), refMat.block(i,j,h,w).row(r));
73 for(Index c=0; c<w; c++)
74 {
75 VERIFY_IS_APPROX(m.block(i,j,h,w).row(r).coeff(c), refMat.block(i,j,h,w).row(r).coeff(c));
76 VERIFY_IS_APPROX(m.block(i,j,h,w).coeff(r,c), refMat.block(i,j,h,w).coeff(r,c));
77 }
78 }
79
80 VERIFY_IS_APPROX(m.middleCols(j,w), refMat.middleCols(j,w));
81 VERIFY_IS_APPROX(m.middleRows(i,h), refMat.middleRows(i,h));
82 for(Index r=0; r<h; r++)
83 {
84 VERIFY_IS_APPROX(m.middleCols(j,w).row(r), refMat.middleCols(j,w).row(r));

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 15

innervecFunction · 0.85
makeCompressedMethod · 0.80
realClass · 0.70
rowsMethod · 0.45
colsMethod · 0.45
innerSizeMethod · 0.45
outerSizeMethod · 0.45
blockMethod · 0.45
colMethod · 0.45
coeffMethod · 0.45
rowMethod · 0.45
coeffRefMethod · 0.45

Tested by

no test coverage detected