[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: kdesupport/eigen2
From: Gael Guennebaud <g.gael () free ! fr>
Date: 2009-01-23 13:59:33
Message-ID: 1232719173.605094.18726.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 915676 by ggael:
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 ???
M +3 -0 Eigen/src/Sparse/DynamicSparseMatrix.h
M +3 -3 Eigen/src/Sparse/SparseCwiseBinaryOp.h
M +6 -0 Eigen/src/Sparse/SparseMatrix.h
M +30 -0 Eigen/src/Sparse/SparseVector.h
M +4 -1 test/sparse_basic.cpp
M +3 -0 test/sparse_vector.cpp
--- trunk/kdesupport/eigen2/Eigen/src/Sparse/DynamicSparseMatrix.h #915675:915676
@@ -63,6 +63,9 @@
{
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:
--- trunk/kdesupport/eigen2/Eigen/src/Sparse/SparseCwiseBinaryOp.h #915675:915676
@@ -344,7 +344,7 @@
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 @@
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 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>
--- trunk/kdesupport/eigen2/Eigen/src/Sparse/SparseMatrix.h #915675:915676
@@ -57,6 +57,12 @@
{
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:
--- trunk/kdesupport/eigen2/Eigen/src/Sparse/SparseVector.h #915675:915676
@@ -57,6 +57,8 @@
{
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 @@
/**
*/
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 @@
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 @@
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)
--- trunk/kdesupport/eigen2/test/sparse_basic.cpp #915675:915676
@@ -235,7 +235,10 @@
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);
--- trunk/kdesupport/eigen2/test/sparse_vector.cpp #915675:915676
@@ -79,6 +79,9 @@
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));
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic