12 #define EIGEN_NO_DEPRECATED_WARNING 13 #include "sparse_basic.cpp" 14 #include "sparse_product.cpp" 15 #include <Eigen/SparseExtra> 17 template<
typename SetterType,
typename DenseType,
typename Scalar,
int Options>
18 bool test_random_setter(SparseMatrix<Scalar,Options>& sm,
const DenseType& ref,
const std::vector<Vector2i>& nonzeroCoords)
23 std::vector<Vector2i> remaining = nonzeroCoords;
24 while(!remaining.empty())
26 int i = internal::random<int>(0,
static_cast<int>(remaining.size())-1);
27 w(remaining[i].x(),remaining[i].y()) = ref.coeff(remaining[i].x(),remaining[i].y());
28 remaining[i] = remaining.back();
32 return sm.isApprox(ref);
35 template<
typename SetterType,
typename DenseType,
typename T>
36 bool test_random_setter(DynamicSparseMatrix<T>& sm,
const DenseType& ref,
const std::vector<Vector2i>& nonzeroCoords)
39 std::vector<Vector2i> remaining = nonzeroCoords;
40 while(!remaining.empty())
42 int i = internal::random<int>(0,
static_cast<int>(remaining.size())-1);
43 sm.coeffRef(remaining[i].x(),remaining[i].y()) = ref.coeff(remaining[i].x(),remaining[i].y());
44 remaining[i] = remaining.back();
47 return sm.isApprox(ref);
50 template<
typename SparseMatrixType>
void sparse_extra(
const SparseMatrixType& ref)
52 const Index rows = ref.rows();
53 const Index cols = ref.cols();
54 typedef typename SparseMatrixType::Scalar Scalar;
55 enum { Flags = SparseMatrixType::Flags };
57 double density = (
std::max)(8./(rows*cols), 0.01);
58 typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
59 typedef Matrix<Scalar,Dynamic,1> DenseVector;
62 SparseMatrixType m(rows, cols);
63 DenseMatrix refMat = DenseMatrix::Zero(rows, cols);
64 DenseVector vec1 = DenseVector::Random(rows);
66 std::vector<Vector2i> zeroCoords;
67 std::vector<Vector2i> nonzeroCoords;
68 initSparse<Scalar>(density, refMat, m, 0, &zeroCoords, &nonzeroCoords);
70 if (zeroCoords.size()==0 || nonzeroCoords.size()==0)
74 for (
int i=0; i<(int)zeroCoords.size(); ++i)
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 );
80 VERIFY_IS_APPROX(m, refMat);
82 m.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
83 refMat.coeffRef(nonzeroCoords[0].x(), nonzeroCoords[0].y()) = Scalar(5);
85 VERIFY_IS_APPROX(m, refMat);
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) ));
107 #ifdef _DENSE_HASH_MAP_H_ 108 VERIFY((
test_random_setter<RandomSetter<SparseMatrixType, GoogleDenseHashMapTraits> >(m,refMat,nonzeroCoords) ));
110 #ifdef _SPARSE_HASH_MAP_H_ 111 VERIFY((
test_random_setter<RandomSetter<SparseMatrixType, GoogleSparseHashMapTraits> >(m,refMat,nonzeroCoords) ));
134 for(
int i = 0; i < g_repeat; i++) {
135 int s = Eigen::internal::random<int>(1,50);
136 CALL_SUBTEST_1(
sparse_extra(SparseMatrix<double>(8, 8)) );
137 CALL_SUBTEST_2(
sparse_extra(SparseMatrix<std::complex<double> >(s, s)) );
138 CALL_SUBTEST_1(
sparse_extra(SparseMatrix<double>(s, s)) );
140 CALL_SUBTEST_3(
sparse_extra(DynamicSparseMatrix<double>(s, s)) );
144 CALL_SUBTEST_3( (sparse_product<DynamicSparseMatrix<float, ColMajor> >()) );
145 CALL_SUBTEST_3( (sparse_product<DynamicSparseMatrix<float, RowMajor> >()) );
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC half() max(const half &a, const half &b)
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
TFSIMD_FORCE_INLINE const tfScalar & w() const