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

Function sparse_basic

dependence/eigen-3.4.0/test/sparse_basic.cpp:24–681  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22#include "sparse.h"
23
24template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& ref)
25{
26 typedef typename SparseMatrixType::StorageIndex StorageIndex;
27 typedef Matrix<StorageIndex,2,1> Vector2;
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 enum { Flags = SparseMatrixType::Flags };
37
38 double density = (std::max)(8./(rows*cols), 0.01);
39 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
40 typedef Matrix<Scalar,Dynamic,1> DenseVector;
41 Scalar eps = 1e-6;
42
43 Scalar s1 = internal::random<Scalar>();
44 {
45 SparseMatrixType m(rows, cols);
46 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
47 DenseVector vec1 = DenseVector::Random(rows);
48
49 std::vector<Vector2> zeroCoords;
50 std::vector<Vector2> nonzeroCoords;
51 initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords);
52
53 // test coeff and coeffRef
54 for (std::size_t i=0; i<zeroCoords.size(); ++i)
55 {
56 VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(zeroCoords[i].x(),zeroCoords[i].y()), eps );
57 if(internal::is_same<SparseMatrixType,SparseMatrix<Scalar,Flags> >::value)
58 VERIFY_RAISES_ASSERT( m.coeffRef(zeroCoords[i].x(),zeroCoords[i].y()) = 5 );
59 }
60 VERIFY_IS_APPROX(m, refMat);
61
62 if(!nonzeroCoords.empty()) {
63 m.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
64 refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
65 }
66
67 VERIFY_IS_APPROX(m, refMat);
68
69 // test assertion
70 VERIFY_RAISES_ASSERT( m.coeffRef(-1,1) = 0 );
71 VERIFY_RAISES_ASSERT( m.coeffRef(0,m.cols()) = 0 );
72 }
73
74 // test insert (inner random)
75 {
76 DenseMatrix m1(rows,cols);
77 m1.setZero();
78 SparseMatrixType m2(rows,cols);
79 bool call_reserve = internal::random<int>()%2;
80 Index nnz = internal::random<int>(1,int(rows)/2);
81 if(call_reserve)

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 15

makeCompressedMethod · 0.80
realMethod · 0.80
coeffsMethod · 0.80
sparseViewMethod · 0.80
lazyProductMethod · 0.80
asDiagonalMethod · 0.80
absFunction · 0.70
rowsMethod · 0.45
colsMethod · 0.45
sizeMethod · 0.45
coeffMethod · 0.45
xMethod · 0.45

Tested by

no test coverage detected