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

Function sparse_extra

dependence/eigen-3.4.0/unsupported/test/sparse_extra.cpp:85–163  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83}
84
85template<typename SparseMatrixType> void sparse_extra(const SparseMatrixType& ref)
86{
87 const Index rows = ref.rows();
88 const Index cols = ref.cols();
89 typedef typename SparseMatrixType::Scalar Scalar;
90 enum { Flags = SparseMatrixType::Flags };
91
92 double density = (std::max)(8./(rows*cols), 0.01);
93 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
94 typedef Matrix<Scalar,Dynamic,1> DenseVector;
95 Scalar eps = 1e-6;
96
97 SparseMatrixType m(rows, cols);
98 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
99 DenseVector vec1 = DenseVector::Random(rows);
100
101 std::vector<Vector2i> zeroCoords;
102 std::vector<Vector2i> nonzeroCoords;
103 initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords);
104
105 if (zeroCoords.size()==0 || nonzeroCoords.size()==0)
106 return;
107
108 // test coeff and coeffRef
109 for (int i=0; i<(int)zeroCoords.size(); ++i)
110 {
111 VERIFY_IS_MUCH_SMALLER_THAN( m.coeff(zeroCoords[i].x(),zeroCoords[i].y()), eps );
112 if(internal::is_same<SparseMatrixType,SparseMatrix<Scalar,Flags> >::value)
113 VERIFY_RAISES_ASSERT( m.coeffRef(zeroCoords[0].x(),zeroCoords[0].y()) = 5 );
114 }
115 VERIFY_IS_APPROX(m, refMat);
116
117 m.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
118 refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
119
120 VERIFY_IS_APPROX(m, refMat);
121
122 // random setter
123// {
124// m.setZero();
125// VERIFY_IS_NOT_APPROX(m, refMat);
126// SparseSetter<SparseMatrixType, RandomAccessPattern> w(m);
127// std::vector<Vector2i> remaining = nonzeroCoords;
128// while(!remaining.empty())
129// {
130// int i = internal::random<int>(0,remaining.size()-1);
131// w->coeffRef(remaining[i].x(),remaining[i].y()) = refMat.coeff(remaining[i].x(),remaining[i].y());
132// remaining[i] = remaining.back();
133// remaining.pop_back();
134// }
135// }
136// VERIFY_IS_APPROX(m, refMat);
137
138 VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdMapTraits> >(m,refMat,nonzeroCoords) ));
139 #ifdef EIGEN_UNORDERED_MAP_SUPPORT
140 VERIFY(( test_random_setter<RandomSetter<SparseMatrixType, StdUnorderedMapTraits> >(m,refMat,nonzeroCoords) ));
141 #endif
142 #ifdef EIGEN_GOOGLEHASH_SUPPORT

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