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.
diff --git a/test/sparse_basic.cpp b/test/sparse_basic.cpp
index 6a3e191..5b22876 100644
--- a/test/sparse_basic.cpp
+++ b/test/sparse_basic.cpp
@@ -325,6 +325,27 @@
     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);