MCPcopy Create free account
hub / github.com/avaxman/Directional / sparse_basic

Function sparse_basic

external/eigen/test/sparse_basic.cpp:24–948  ·  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 typedef Matrix<Scalar, Dynamic, Dynamic, SparseMatrixType::IsRowMajor ? RowMajor : ColMajor> CompatibleDenseMatrix;
42 Scalar eps = 1e-6;
43
44 Scalar s1 = internal::random<Scalar>();
45 {
46 SparseMatrixType m(rows, cols);
47 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
48 DenseVector vec1 = DenseVector::Random(rows);
49
50 std::vector<Vector2> zeroCoords;
51 std::vector<Vector2> nonzeroCoords;
52 initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords);
53
54 // test coeff and coeffRef
55 for (std::size_t i=0; i<zeroCoords.size(); ++i)
56 {
57 VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(zeroCoords[i].x(),zeroCoords[i].y()), eps );
58 if(internal::is_same<SparseMatrixType,SparseMatrix<Scalar,Flags> >::value)
59 VERIFY_RAISES_ASSERT( m.coeffRef(zeroCoords[i].x(),zeroCoords[i].y()) = 5 );
60 }
61 VERIFY_IS_APPROX(m, refMat);
62
63 if(!nonzeroCoords.empty()) {
64 m.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
65 refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
66 }
67
68 VERIFY_IS_APPROX(m, refMat);
69
70 // test assertion
71 VERIFY_RAISES_ASSERT( m.coeffRef(-1,1) = 0 );
72 VERIFY_RAISES_ASSERT( m.coeffRef(0,m.cols()) = 0 );
73 }
74
75 // test insert (inner random)
76 {
77 DenseMatrix m1(rows,cols);
78 m1.setZero();
79 SparseMatrixType m2(rows,cols);
80 bool call_reserve = internal::random<int>()%2;
81 Index nnz = internal::random<int>(1,int(rows)/2);

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 15

shuffleFunction · 0.85
triplet_compClass · 0.85
makeCompressedMethod · 0.80
removeOuterVectorsMethod · 0.80
realMethod · 0.80
coeffsMethod · 0.80
innerIndicesAreSortedMethod · 0.80
insertFromTripletsMethod · 0.80
setFromSortedTripletsMethod · 0.80
sparseViewMethod · 0.80

Tested by

no test coverage detected