mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-07-26 14:54:30 +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;
|
typedef typename SparseMatrixType::Scalar Scalar;
|
||||||
SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor> trMat(mat.rows(),mat.cols());
|
SparseMatrix<Scalar,IsRowMajor?ColMajor:RowMajor> trMat(mat.rows(),mat.cols());
|
||||||
|
|
||||||
// pass 1: count the nnz per inner-vector
|
if(begin<end)
|
||||||
VectorXi wi(trMat.outerSize());
|
{
|
||||||
wi.setZero();
|
// pass 1: count the nnz per inner-vector
|
||||||
for(InputIterator it(begin); it!=end; ++it)
|
VectorXi wi(trMat.outerSize());
|
||||||
wi(IsRowMajor ? it->col() : it->row())++;
|
wi.setZero();
|
||||||
|
for(InputIterator it(begin); it!=end; ++it)
|
||||||
|
wi(IsRowMajor ? it->col() : it->row())++;
|
||||||
|
|
||||||
// pass 2: insert all the elements into trMat
|
// pass 2: insert all the elements into trMat
|
||||||
trMat.reserve(wi);
|
trMat.reserve(wi);
|
||||||
for(InputIterator it(begin); it!=end; ++it)
|
for(InputIterator it(begin); it!=end; ++it)
|
||||||
trMat.insertBackUncompressed(it->row(),it->col()) = it->value();
|
trMat.insertBackUncompressed(it->row(),it->col()) = it->value();
|
||||||
|
|
||||||
// pass 3:
|
// pass 3:
|
||||||
trMat.sumupDuplicates();
|
trMat.sumupDuplicates();
|
||||||
|
}
|
||||||
|
|
||||||
// pass 4: transposed copy -> implicit sorting
|
// pass 4: transposed copy -> implicit sorting
|
||||||
mat = trMat;
|
mat = trMat;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user