mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-08-03 18:50:39 +08:00
bug #1088: fix setIdenity for non-compressed sparse-matrix
This commit is contained in:
parent
89a222ce50
commit
f8b88d21a6
@ -691,7 +691,8 @@ class SparseMatrix
|
|||||||
m_data.swap(other.m_data);
|
m_data.swap(other.m_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Sets *this to the identity matrix */
|
/** Sets *this to the identity matrix.
|
||||||
|
* This function also turns the matrix into compressed mode, and drop any reserved memory. */
|
||||||
inline void setIdentity()
|
inline void setIdentity()
|
||||||
{
|
{
|
||||||
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
eigen_assert(rows() == cols() && "ONLY FOR SQUARED MATRICES");
|
||||||
@ -699,6 +700,8 @@ class SparseMatrix
|
|||||||
Eigen::Map<Matrix<Index, Dynamic, 1> >(&this->m_data.index(0), rows()).setLinSpaced(0, rows()-1);
|
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<Scalar, Dynamic, 1> >(&this->m_data.value(0), rows()).setOnes();
|
||||||
Eigen::Map<Matrix<Index, Dynamic, 1> >(this->m_outerIndex, rows()+1).setLinSpaced(0, rows());
|
Eigen::Map<Matrix<Index, Dynamic, 1> >(this->m_outerIndex, rows()+1).setLinSpaced(0, rows());
|
||||||
|
std::free(m_innerNonZeros);
|
||||||
|
m_innerNonZeros = 0;
|
||||||
}
|
}
|
||||||
inline SparseMatrix& operator=(const SparseMatrix& other)
|
inline SparseMatrix& operator=(const SparseMatrix& other)
|
||||||
{
|
{
|
||||||
|
@ -529,6 +529,20 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
|||||||
SparseMatrixType m1(rows, rows);
|
SparseMatrixType m1(rows, rows);
|
||||||
m1.setIdentity();
|
m1.setIdentity();
|
||||||
VERIFY_IS_APPROX(m1, refMat1);
|
VERIFY_IS_APPROX(m1, refMat1);
|
||||||
|
for(int k=0; k<rows*rows/4; ++k)
|
||||||
|
{
|
||||||
|
Index i = internal::random<Index>(0,rows-1);
|
||||||
|
Index j = internal::random<Index>(0,rows-1);
|
||||||
|
Index v = internal::random<Scalar>();
|
||||||
|
m1.coeffRef(i,j) = v;
|
||||||
|
refMat1.coeffRef(i,j) = v;
|
||||||
|
VERIFY_IS_APPROX(m1, refMat1);
|
||||||
|
if(internal::random<Index>(0,10)<2)
|
||||||
|
m1.makeCompressed();
|
||||||
|
}
|
||||||
|
m1.setIdentity();
|
||||||
|
refMat1.setIdentity();
|
||||||
|
VERIFY_IS_APPROX(m1, refMat1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user