diff options
author | 2013-05-22 10:43:12 +0200 | |
---|---|---|
committer | 2013-05-22 10:43:12 +0200 | |
commit | 8e050bd68163a64e0252eed66e215baafb6c11ca (patch) | |
tree | 220c362d8b30b0fb2324f0877071b5fd2cb96c00 /Eigen | |
parent | cf939f154fe1ec9904276f5f3f2dbdbc8e98156a (diff) |
Optimize Sparse setIdentity and add a unit test
Diffstat (limited to 'Eigen')
-rw-r--r-- | Eigen/src/SparseCore/SparseMatrix.h | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/Eigen/src/SparseCore/SparseMatrix.h b/Eigen/src/SparseCore/SparseMatrix.h index d93dffb48..072578132 100644 --- a/Eigen/src/SparseCore/SparseMatrix.h +++ b/Eigen/src/SparseCore/SparseMatrix.h @@ -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) { |