| 617 | |
| 618 | template<typename SparseMatrixType> |
| 619 | void big_sparse_triplet(Index rows, Index cols, double density) { |
| 620 | typedef typename SparseMatrixType::StorageIndex StorageIndex; |
| 621 | typedef typename SparseMatrixType::Scalar Scalar; |
| 622 | typedef Triplet<Scalar,Index> TripletType; |
| 623 | std::vector<TripletType> triplets; |
| 624 | double nelements = density * rows*cols; |
| 625 | VERIFY(nelements>=0 && nelements < NumTraits<StorageIndex>::highest()); |
| 626 | Index ntriplets = Index(nelements); |
| 627 | triplets.reserve(ntriplets); |
| 628 | Scalar sum = Scalar(0); |
| 629 | for(Index i=0;i<ntriplets;++i) |
| 630 | { |
| 631 | Index r = internal::random<Index>(0,rows-1); |
| 632 | Index c = internal::random<Index>(0,cols-1); |
| 633 | Scalar v = internal::random<Scalar>(); |
| 634 | triplets.push_back(TripletType(r,c,v)); |
| 635 | sum += v; |
| 636 | } |
| 637 | SparseMatrixType m(rows,cols); |
| 638 | m.setFromTriplets(triplets.begin(), triplets.end()); |
| 639 | VERIFY(m.nonZeros() <= ntriplets); |
| 640 | VERIFY_IS_APPROX(sum, m.sum()); |
| 641 | } |
| 642 | |
| 643 | |
| 644 | void test_sparse_basic() |