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

Function big_sparse_triplet

test/sparse_basic.cpp:619–641  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

617
618template<typename SparseMatrixType>
619void 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
644void test_sparse_basic()

Callers

nothing calls this directly

Calls 7

beginMethod · 0.80
endMethod · 0.80
reserveMethod · 0.45
push_backMethod · 0.45
setFromTripletsMethod · 0.45
nonZerosMethod · 0.45
sumMethod · 0.45

Tested by

no test coverage detected