mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-19 16:19:37 +08:00
fix assignment of a row-major sparse vector to a column major sparse one
This commit is contained in:
parent
e4cea957df
commit
7f04845023
@ -53,7 +53,7 @@ struct traits<SparseVector<_Scalar, _Options, _Index> >
|
|||||||
ColsAtCompileTime = IsColVector ? 1 : Dynamic,
|
ColsAtCompileTime = IsColVector ? 1 : Dynamic,
|
||||||
MaxRowsAtCompileTime = RowsAtCompileTime,
|
MaxRowsAtCompileTime = RowsAtCompileTime,
|
||||||
MaxColsAtCompileTime = ColsAtCompileTime,
|
MaxColsAtCompileTime = ColsAtCompileTime,
|
||||||
Flags = _Options | NestByRefBit | LvalueBit,
|
Flags = _Options | NestByRefBit | LvalueBit | (IsColVector ? 0 : RowMajorBit),
|
||||||
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
CoeffReadCost = NumTraits<Scalar>::ReadCost,
|
||||||
SupportedAccessPatterns = InnerRandomAccessPattern
|
SupportedAccessPatterns = InnerRandomAccessPattern
|
||||||
};
|
};
|
||||||
@ -242,9 +242,9 @@ class SparseVector
|
|||||||
inline SparseVector& operator=(const SparseMatrixBase<OtherDerived>& other)
|
inline SparseVector& operator=(const SparseMatrixBase<OtherDerived>& other)
|
||||||
{
|
{
|
||||||
if (int(RowsAtCompileTime)!=int(OtherDerived::RowsAtCompileTime))
|
if (int(RowsAtCompileTime)!=int(OtherDerived::RowsAtCompileTime))
|
||||||
return Base::operator=(other.transpose());
|
return assign(other.transpose());
|
||||||
else
|
else
|
||||||
return Base::operator=(other);
|
return assign(other);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
#ifndef EIGEN_PARSED_BY_DOXYGEN
|
||||||
@ -311,6 +311,33 @@ class SparseVector
|
|||||||
# ifdef EIGEN_SPARSEVECTOR_PLUGIN
|
# ifdef EIGEN_SPARSEVECTOR_PLUGIN
|
||||||
# include EIGEN_SPARSEVECTOR_PLUGIN
|
# include EIGEN_SPARSEVECTOR_PLUGIN
|
||||||
# endif
|
# endif
|
||||||
|
|
||||||
|
protected:
|
||||||
|
template<typename OtherDerived>
|
||||||
|
EIGEN_DONT_INLINE SparseVector& assign(const SparseMatrixBase<OtherDerived>& _other)
|
||||||
|
{
|
||||||
|
const OtherDerived& other(_other.derived());
|
||||||
|
const bool needToTranspose = (Flags & RowMajorBit) != (OtherDerived::Flags & RowMajorBit);
|
||||||
|
if(needToTranspose)
|
||||||
|
{
|
||||||
|
Index size = other.innerSize();
|
||||||
|
Index nnz = other.nonZeros();
|
||||||
|
resize(size);
|
||||||
|
reserve(nnz);
|
||||||
|
for(Index i=0; i<size; ++i)
|
||||||
|
{
|
||||||
|
typename OtherDerived::InnerIterator it(other, i);
|
||||||
|
if(it)
|
||||||
|
insert(i) = it.value();
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// there is no special optimization
|
||||||
|
return Base::operator=(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Scalar, int _Options, typename _Index>
|
template<typename Scalar, int _Options, typename _Index>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user