MCPcopy Create free account
hub / github.com/PX4/eigen / sparse_extra

Function sparse_extra

unsupported/test/sparse_extra.cpp:50–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

test_sparse_extraFunction · 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