mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-11 19:29:02 +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()
|
||||
{
|
||||
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
||||
this->setZero();
|
||||
for (int j = 0; j < rows(); j++)
|
||||
this->insert(j,j) = Scalar(1.0);
|
||||
this->m_data.resize(rows());
|
||||
Eigen::Map<Matrix<Index, Dynamic, 1> >(&this->m_data.index(0), rows()).setLinSpaced(0, rows()-1);
|
||||
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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user