aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2010-12-31 17:26:48 +0100
committerGravatar Gael Guennebaud <g.gael@free.fr>2010-12-31 17:26:48 +0100
commit902af035d36530c3cb174aa98a48dc13810ff42d (patch)
tree03f289cfb009a644c2cc8fc879505041eda98c31
parent11e253bc101d804c1e2dfea90f3c8256700324d4 (diff)
parent25efcdd0426545fb4c9a7f5af039827ee174809e (diff)
merge
-rw-r--r--Eigen/src/Sparse/SparseDenseProduct.h37
-rw-r--r--test/sparse_product.cpp37
2 files changed, 27 insertions, 47 deletions
diff --git a/Eigen/src/Sparse/SparseDenseProduct.h b/Eigen/src/Sparse/SparseDenseProduct.h
index a95f989ce..0f77aa5be 100644
--- a/Eigen/src/Sparse/SparseDenseProduct.h
+++ b/Eigen/src/Sparse/SparseDenseProduct.h
@@ -169,31 +169,14 @@ class SparseTimeDenseProduct
enum { LhsIsRowMajor = (_Lhs::Flags&RowMajorBit)==RowMajorBit };
for(Index j=0; j<m_lhs.outerSize(); ++j)
{
- if(LhsIsRowMajor)
- {
-// Block<Dest,1,Dest::ColsAtCompileTime> dest_j(dest.row(LhsIsRowMajor ? j : 0)); // this does not work in all cases. Why?
- Block<Dest,1,Dest::ColsAtCompileTime> dest_j(dest, LhsIsRowMajor ? j : 0);
- for(LhsInnerIterator it(m_lhs,j); it ;++it)
- {
- dest_j += (alpha*it.value()) * m_rhs.row(it.index());
- }
- }
- else if(Rhs::ColsAtCompileTime==1)
- {
- typename Rhs::Scalar rhs_j = alpha * m_rhs.coeff(j,0);
- for(LhsInnerIterator it(m_lhs,j); it ;++it)
- {
- dest.coeffRef(it.index()) += it.value() * rhs_j;
- }
- }
- else
- {
- for(LhsInnerIterator it(m_lhs,j); it ;++it)
- {
- dest.row(it.index()) += (alpha*it.value()) * m_rhs.row(j);
- }
- }
-
+ typename Rhs::Scalar rhs_j = alpha * m_rhs.coeff(LhsIsRowMajor ? 0 : j,0);
+ typename Dest::RowXpr dest_j(dest.row(LhsIsRowMajor ? j : 0));
+ for(LhsInnerIterator it(m_lhs,j); it ;++it)
+ {
+ if(LhsIsRowMajor) dest_j += (alpha*it.value()) * m_rhs.row(it.index());
+ else if(Rhs::ColsAtCompileTime==1) dest.coeffRef(it.index()) += it.value() * rhs_j;
+ else dest.row(it.index()) += (alpha*it.value()) * m_rhs.row(j);
+ }
}
}
@@ -204,8 +187,8 @@ class SparseTimeDenseProduct
// dense = dense * sparse
namespace internal {
- template<typename Lhs, typename Rhs>
- struct traits<DenseTimeSparseProduct<Lhs,Rhs> >
+template<typename Lhs, typename Rhs>
+struct traits<DenseTimeSparseProduct<Lhs,Rhs> >
: traits<ProductBase<DenseTimeSparseProduct<Lhs,Rhs>, Lhs, Rhs> >
{
typedef Dense StorageKind;
diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp
index da4ecc306..90ec3781e 100644
--- a/test/sparse_product.cpp
+++ b/test/sparse_product.cpp
@@ -140,26 +140,23 @@ template<typename SparseMatrixType> void sparse_product(const SparseMatrixType&
// New test for Bug in SparseTimeDenseProduct
template<typename SparseMatrixType, typename DenseMatrixType> void sparse_product_regression_test()
{
- // This code does not compile with afflicted versions of the bug
-/* SparseMatrixType sm1(3,2);
- DenseMatrixType m2(2,2);
- sm1.setZero();
- m2.setZero();
-
- DenseMatrixType m3 = sm1*m2;
- */
-
-
- // This code produces a segfault with afflicted versions of another SparseTimeDenseProduct
- // bug
-
- SparseMatrixType sm2(20000,2);
- DenseMatrixType m3(2,2);
- sm2.setZero();
- m3.setZero();
- DenseMatrixType m4(sm2*m3);
-
- VERIFY_IS_APPROX( m4(0,0), 0.0 );
+ // This code does not compile with afflicted versions of the bug
+ SparseMatrixType sm1(3,2);
+ DenseMatrixType m2(2,2);
+ sm1.setZero();
+ m2.setZero();
+
+ DenseMatrixType m3 = sm1*m2;
+
+
+ // This code produces a segfault with afflicted versions of another SparseTimeDenseProduct
+ // bug
+
+ SparseMatrixType sm2(20000,2);
+ sm2.setZero();
+ DenseMatrixType m4(sm2*m2);
+
+ VERIFY_IS_APPROX( m4(0,0), 0.0 );
}
void test_sparse_product()