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

Function sparse_extra

external/eigen/unsupported/test/sparse_extra.cpp:40–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& ref)
41{
42 const Index rows = ref.rows();
43 const Index cols = ref.cols();
44 typedef typename SparseMatrixType::Scalar Scalar;
45 enum { Flags = SparseMatrixType::Flags };
46
47 double density = (std::max)(8./(rows*cols), 0.01);
48 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
49 typedef Matrix<Scalar,Dynamic,1> DenseVector;
50 Scalar eps = 1e-6;
51
52 SparseMatrixType m(rows, cols);
53 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
54 DenseVector vec1 = DenseVector::Random(rows);
55
56 std::vector<Vector2i> zeroCoords;
57 std::vector<Vector2i> nonzeroCoords;
58 initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords);
59
60 if (zeroCoords.size()==0 || nonzeroCoords.size()==0)
61 return;
62
63 // test coeff and coeffRef
64 for (int i=0; i<(int)zeroCoords.size(); ++i)
65 {
66 VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(zeroCoords[i].x(),zeroCoords[i].y()), eps );
67 if(internal::is_same<SparseMatrixType,SparseMatrix<Scalar,Flags> >::value)
68 VERIFY_RAISES_ASSERT( m.coeffRef(zeroCoords[0].x(),zeroCoords[0].y()) = 5 );
69 }
70 VERIFY_IS_APPROX(m, refMat);
71
72 m.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
73 refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
74
75 VERIFY_IS_APPROX(m, refMat);
76
77 // random setter
78// {
79// m.setZero();
80// VERIFY_IS_NOT_APPROX(m, refMat);
81// SparseSetter<SparseMatrixType, RandomAccessPattern> w(m);
82// std::vector<Vector2i> remaining = nonzeroCoords;
83// while(!remaining.empty())
84// {
85// int i = internal::random<int>(0,remaining.size()-1);
86// w->coeffRef(remaining[i].x(),remaining[i].y()) = refMat.coeff(remaining[i].x(),remaining[i].y());
87// remaining[i] = remaining.back();
88// remaining.pop_back();
89// }
90// }
91// VERIFY_IS_APPROX(m, refMat);
92
93 VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdMapTraits> >(m,refMat,nonzeroCoords) ));
94 VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) ));
95 #ifdef EIGEN_GOOGLEHASH_SUPPORT
96 VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
97 VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));

Callers 1

EIGEN_DECLARE_TESTFunction · 0.85

Calls 7

rowsMethod · 0.45
colsMethod · 0.45
sizeMethod · 0.45
coeffMethod · 0.45
xMethod · 0.45
yMethod · 0.45
coeffRefMethod · 0.45

Tested by

no test coverage detected