14 double densityMat = (
std::max)(8./(rows*cols), 0.01);
15 double densityVec = (
std::max)(8./(rows), 0.1);
22 SparseMatrixType
m1(rows,rows);
23 SparseVectorType
v1(rows),
v2(rows),
v3(rows);
24 DenseMatrix refM1 = DenseMatrix::Zero(rows, rows);
25 DenseVector refV1 = DenseVector::Random(rows),
26 refV2 = DenseVector::Random(rows),
27 refV3 = DenseVector::Random(rows);
29 std::vector<int> zerocoords, nonzerocoords;
30 initSparse<Scalar>(densityVec, refV1,
v1, &zerocoords, &nonzerocoords);
31 initSparse<Scalar>(densityMat, refM1,
m1);
33 initSparse<Scalar>(densityVec, refV2,
v2);
34 initSparse<Scalar>(densityVec, refV3,
v3);
36 Scalar s1 = internal::random<Scalar>();
39 for (
unsigned int i=0;
i<zerocoords.size(); ++
i)
45 VERIFY(
int(nonzerocoords.size()) == v1.nonZeros());
47 for (
typename SparseVectorType::InnerIterator it(v1); it; ++it,++
j)
49 VERIFY(nonzerocoords[j]==it.index());
50 VERIFY(it.value()==v1.coeff(it.index()));
51 VERIFY(it.value()==refV1.coeff(it.index()));
58 SparseVectorType v4(rows);
59 DenseVector v5 = DenseVector::Zero(rows);
60 for(
int k=0; k<
rows; ++k)
62 int i = internal::random<int>(0,rows-1);
63 Scalar v = internal::random<Scalar>();
70 v1.coeffRef(nonzerocoords[0]) =
Scalar(5);
71 refV1.coeffRef(nonzerocoords[0]) =
Scalar(5);
91 int i = internal::random<int>(0,rows-1);
102 VERIFY_IS_APPROX((v1 = v1.transpose()), (refV1 = refV1.transpose().eval()));
106 SparseMatrixType mv1;
118 std::vector<StorageIndex> inc;
127 StorageIndex incRows = inc[
i];
128 SparseVectorType
vec1(rows);
129 DenseVector refVec1 = DenseVector::Zero(rows);
130 initSparse<Scalar>(densityVec, refVec1,
vec1);
132 vec1.conservativeResize(rows+incRows);
133 refVec1.conservativeResize(rows+incRows);
134 if (incRows > 0) refVec1.tail(incRows).setZero();
140 vec1.insert(vec1.rows()-1) = refVec1(refVec1.rows()-1) = 1;
151 int r = Eigen::internal::random<int>(1,500),
c = Eigen::internal::random<int>(1,500);
152 if(Eigen::internal::random<int>(0,4) == 0) {
157 CALL_SUBTEST_1(( sparse_vector<double,int>(8, 8) ));
158 CALL_SUBTEST_2((
sparse_vector<std::complex<double>,
int>(r,
c) ));
159 CALL_SUBTEST_1(( sparse_vector<double,long int>(r,
c) ));
160 CALL_SUBTEST_1(( sparse_vector<double,short>(r,
c) ));
Matrix< Scalar, Dynamic, Dynamic > DenseMatrix
A versatible sparse matrix representation.
Matrix< Scalar, Dynamic, 1 > DenseVector
#define VERIFY_IS_APPROX(a, b)
Array< double, 1, 3 > e(1./3., 0.5, 2.)
void sparse_vector(int rows, int cols)
#define VERIFY_IS_MUCH_SMALLER_THAN(a, b)
void test_sparse_vector()
#define EIGEN_UNUSED_VARIABLE(var)