mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-25 14:24:31 +08:00
Fix setFromTripplet with empty inputs
This commit is contained in:
parent
aa8b897607
commit
fcdbfabf7a
@ -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())++;
|
||||
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 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 3:
|
||||
trMat.sumupDuplicates();
|
||||
}
|
||||
|
||||
// pass 4: transposed copy -> implicit sorting
|
||||
mat = trMat;
|
||||
|
Loading…
x
Reference in New Issue
Block a user