mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-03-01 18:26:24 +08:00
sparse module: makes -= and += operator working
Question 1: why are *=scalar and /=scalar working right away ? Same weirdness in DynamicSparseMatrix where operators += and -= work wihout having to redefine them ???
This commit is contained in:
parent
899e2ada15
commit
e7c48fac9b
@ -63,6 +63,9 @@ class DynamicSparseMatrix
|
||||
{
|
||||
public:
|
||||
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(DynamicSparseMatrix)
|
||||
// FIXME: why are these operator already alvailable ???
|
||||
// EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, +=)
|
||||
// EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(DynamicSparseMatrix, -=)
|
||||
typedef MappedSparseMatrix<Scalar,Flags> Map;
|
||||
|
||||
protected:
|
||||
|
@ -344,7 +344,7 @@ template<typename OtherDerived>
|
||||
EIGEN_STRONG_INLINE Derived &
|
||||
SparseMatrixBase<Derived>::operator-=(const SparseMatrixBase<OtherDerived> &other)
|
||||
{
|
||||
return *this = *this - other;
|
||||
return *this = derived() - other.derived();
|
||||
}
|
||||
|
||||
template<typename Derived>
|
||||
@ -360,7 +360,7 @@ template<typename OtherDerived>
|
||||
EIGEN_STRONG_INLINE Derived &
|
||||
SparseMatrixBase<Derived>::operator+=(const SparseMatrixBase<OtherDerived>& other)
|
||||
{
|
||||
return *this = *this + other;
|
||||
return *this = derived() + other.derived();
|
||||
}
|
||||
|
||||
template<typename ExpressionType>
|
||||
@ -399,7 +399,7 @@ template<typename ExpressionType>
|
||||
template<typename OtherDerived>
|
||||
inline ExpressionType& SparseCwise<ExpressionType>::operator*=(const SparseMatrixBase<OtherDerived> &other)
|
||||
{
|
||||
return m_matrix.const_cast_derived() = *this * other;
|
||||
return m_matrix.const_cast_derived() = _expression() * other.derived();
|
||||
}
|
||||
|
||||
// template<typename ExpressionType>
|
||||
|
@ -57,6 +57,12 @@ class SparseMatrix
|
||||
{
|
||||
public:
|
||||
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseMatrix)
|
||||
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseMatrix, +=)
|
||||
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseMatrix, -=)
|
||||
// FIXME: why are these operator already alvailable ???
|
||||
// EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, *=)
|
||||
// EIGEN_SPARSE_INHERIT_SCALAR_ASSIGNMENT_OPERATOR(SparseMatrix, /=)
|
||||
|
||||
typedef MappedSparseMatrix<Scalar,Flags> Map;
|
||||
|
||||
protected:
|
||||
|
@ -57,6 +57,8 @@ class SparseVector
|
||||
{
|
||||
public:
|
||||
EIGEN_SPARSE_GENERIC_PUBLIC_INTERFACE(SparseVector)
|
||||
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, +=)
|
||||
EIGEN_SPARSE_INHERIT_ASSIGNMENT_OPERATOR(SparseVector, -=)
|
||||
|
||||
protected:
|
||||
public:
|
||||
@ -117,14 +119,32 @@ class SparseVector
|
||||
/**
|
||||
*/
|
||||
inline void reserve(int reserveSize) { m_data.reserve(reserveSize); }
|
||||
|
||||
inline void startFill(int reserve)
|
||||
{
|
||||
setZero();
|
||||
m_data.reserve(reserve);
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
inline Scalar& fill(int r, int c)
|
||||
{
|
||||
ei_assert(r==0 || c==0);
|
||||
return fill(IsColVector ? r : c);
|
||||
}
|
||||
|
||||
inline Scalar& fill(int i)
|
||||
{
|
||||
m_data.append(0, i);
|
||||
return m_data.value(m_data.size()-1);
|
||||
}
|
||||
|
||||
inline Scalar& fillrand(int r, int c)
|
||||
{
|
||||
ei_assert(r==0 || c==0);
|
||||
return fillrand(IsColVector ? r : c);
|
||||
}
|
||||
|
||||
/** Like fill() but with random coordinates.
|
||||
*/
|
||||
@ -145,10 +165,18 @@ class SparseVector
|
||||
return m_data.value(id+1);
|
||||
}
|
||||
|
||||
inline void endFill() {}
|
||||
|
||||
void prune(Scalar reference, RealScalar epsilon = precision<RealScalar>())
|
||||
{
|
||||
m_data.prune(reference,epsilon);
|
||||
}
|
||||
|
||||
void resize(int rows, int cols)
|
||||
{
|
||||
ei_assert(rows==1 || cols==1);
|
||||
resize(IsColVector ? rows : cols);
|
||||
}
|
||||
|
||||
void resize(int newSize)
|
||||
{
|
||||
@ -161,6 +189,8 @@ class SparseVector
|
||||
inline SparseVector() : m_size(0) { resize(0); }
|
||||
|
||||
inline SparseVector(int size) : m_size(0) { resize(size); }
|
||||
|
||||
inline SparseVector(int rows, int cols) : m_size(0) { resize(rows,cols); }
|
||||
|
||||
template<typename OtherDerived>
|
||||
inline SparseVector(const MatrixBase<OtherDerived>& other)
|
||||
|
@ -235,7 +235,10 @@ template<typename SparseMatrixType> void sparse_basic(const SparseMatrixType& re
|
||||
|
||||
VERIFY_IS_APPROX(m1*=s1, refM1*=s1);
|
||||
VERIFY_IS_APPROX(m1/=s1, refM1/=s1);
|
||||
|
||||
|
||||
VERIFY_IS_APPROX(m1+=m2, refM1+=refM2);
|
||||
VERIFY_IS_APPROX(m1-=m2, refM1-=refM2);
|
||||
|
||||
refM4.setRandom();
|
||||
// sparse cwise* dense
|
||||
VERIFY_IS_APPROX(m3.cwise()*refM4, refM3.cwise()*refM4);
|
||||
|
@ -79,6 +79,9 @@ template<typename Scalar> void sparse_vector(int rows, int cols)
|
||||
|
||||
VERIFY_IS_APPROX(v1*=s1, refV1*=s1);
|
||||
VERIFY_IS_APPROX(v1/=s1, refV1/=s1);
|
||||
|
||||
VERIFY_IS_APPROX(v1+=v2, refV1+=refV2);
|
||||
VERIFY_IS_APPROX(v1-=v2, refV1-=refV2);
|
||||
|
||||
VERIFY_IS_APPROX(v1.dot(v2), refV1.dot(refV2));
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user