aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/sparse_basic.cpp
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2012-01-28 11:13:59 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2012-01-28 11:13:59 +0100
commit87138075dad1bcef1c496704f2cc3d6983156cbb (patch)
tree8b977e4b058c91fbbbb93691683f1af5c7554625 /test/sparse_basic.cpp
parentfc2d85d139afeab3fb36d5b2edcda5c33df95fd1 (diff)
add the possibility to assemble a SparseMatrix object from a random list of triplets that may contain duplicated elements. It works in linear time, with O(1) re-allocations.
Diffstat (limited to 'test/sparse_basic.cpp')
-rw-r--r--test/sparse_basic.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 6a3e19105..5b22876b0 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -325,6 +325,27 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
VERIFY_IS_APPROX(m2, refM2);
}
+ // test setFromTriplets
+ {
+ typedef Triplet<Scalar,Index> TripletType;
+ std::vector<TripletType> triplets;
+ int ntriplets = rows*cols;
+ triplets.reserve(ntriplets);
+ DenseMatrix refMat(rows,cols);
+ refMat.setZero();
+ for(int i=0;i<ntriplets;++i)
+ {
+ int i = internal::random<int>(0,rows-1);
+ int j = internal::random<int>(0,cols-1);
+ Scalar v = internal::random<Scalar>();
+ triplets.push_back(TripletType(i,j,v));
+ refMat(i,j) += v;
+ }
+ SparseMatrixType m(rows,cols);
+ m.setFromTriplets(triplets.begin(), triplets.end());
+ VERIFY_IS_APPROX(m, refMat);
+ }
+
// test triangularView
{
DenseMatrix refMat2(rows, rows), refMat3(rows, rows);