mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-12 19:59:05 +08:00
Optimize Sparse setIdentity and add a unit test
This commit is contained in:
parent
cf939f154f
commit
8e050bd681
@ -677,9 +677,10 @@ class SparseMatrix
|
|||||||
inline void setIdentity()
|
inline void setIdentity()
|
||||||
{
|
{
|
||||||
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
||||||
this->setZero();
|
this->m_data.resize(rows());
|
||||||
for (int j = 0; j < rows(); j++)
|
Eigen::Map<Matrix<Index, Dynamic, 1> >(&this->m_data.index(0), rows()).setLinSpaced(0, rows()-1);
|
||||||
this->insert(j,j) = Scalar(1.0);
|
Eigen::Map<Matrix<Scalar, Dynamic, 1> >(&this->m_data.value(0), rows()).setOnes();
|
||||||
|
Eigen::Map<Matrix<Index, Dynamic, 1> >(this->m_outerIndex, rows()+1).setLinSpaced(0, rows());
|
||||||
}
|
}
|
||||||
inline SparseMatrix& operator=(const SparseMatrix& other)
|
inline SparseMatrix& operator=(const SparseMatrix& other)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user