aboutsummaryrefslogtreecommitdiffhomepage
path: root/Eigen
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2013-05-03 14:28:37 +0200
committerGravatar Gael Guennebaud <g.gael@free.fr>2013-05-03 14:28:37 +0200
commitfcdbfabf7a712299edaed206dafaada0d8f72b92 (patch)
tree6c792de8aa73fca04bb24b9813e9f3241bf0b144 /Eigen
parentaa8b8976075823636b7a266cb6307dbba2ee2705 (diff)
Fix setFromTripplet with empty inputs
Diffstat (limited to 'Eigen')
-rw-r--r--Eigen/src/SparseCore/SparseMatrix.h29
1 files changed, 16 insertions, 13 deletions
diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h
index dc57f77fc..e9e285f35 100644
--- a/Eigen/src/SparseCore/SparseMatrix.h
+++ b/Eigen/src/SparseCore/SparseMatrix.h
@@ -911,19 +911,22 @@ void set_from_triplets(const InputIterator& begin, const InputIterator& end, Spa
typedef typename SparseMatrixType::Scalar Scalar;
SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor> trMat(mat.rows(),mat.cols());
- // pass 1: count the nnz per inner-vector
- VectorXi wi(trMat.outerSize());
- wi.setZero();
- for(InputIterator it(begin); it!=end; ++it)
- wi(IsRowMajor ? it->col() : it->row())++;
-
- // pass 2: insert all the elements into trMat
- trMat.reserve(wi);
- for(InputIterator it(begin); it!=end; ++it)
- trMat.insertBackUncompressed(it->row(),it->col()) = it->value();
-
- // pass 3:
- trMat.sumupDuplicates();
+ if(begin<end)
+ {
+ // pass 1: count the nnz per inner-vector
+ VectorXi wi(trMat.outerSize());
+ wi.setZero();
+ for(InputIterator it(begin); it!=end; ++it)
+ wi(IsRowMajor ? it->col() : it->row())++;
+
+ // pass 2: insert all the elements into trMat
+ trMat.reserve(wi);
+ for(InputIterator it(begin); it!=end; ++it)
+ trMat.insertBackUncompressed(it->row(),it->col()) = it->value();
+
+ // pass 3:
+ trMat.sumupDuplicates();
+ }
// pass 4: transposed copy -> implicit sorting
mat = trMat;