mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-06-04 18:54:00 +08:00
fix dense=sparse*diagonal (there was an issue in the values returned by the .outer() function of the related iterators)
This commit is contained in:
parent
f30ca7ed7e
commit
fec6df1f7d
@ -126,11 +126,15 @@ class sparse_diagonal_product_inner_iterator_selector
|
|||||||
SparseInnerVectorSet<Rhs,1>,
|
SparseInnerVectorSet<Rhs,1>,
|
||||||
typename Lhs::DiagonalVectorType>::InnerIterator Base;
|
typename Lhs::DiagonalVectorType>::InnerIterator Base;
|
||||||
typedef typename Lhs::Index Index;
|
typedef typename Lhs::Index Index;
|
||||||
|
Index m_outer;
|
||||||
public:
|
public:
|
||||||
inline sparse_diagonal_product_inner_iterator_selector(
|
inline sparse_diagonal_product_inner_iterator_selector(
|
||||||
const SparseDiagonalProductType& expr, Index outer)
|
const SparseDiagonalProductType& expr, Index outer)
|
||||||
: Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0)
|
: Base(expr.rhs().innerVector(outer) .cwiseProduct(expr.lhs().diagonal()), 0), m_outer(outer)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
inline Index outer() const { return m_outer; }
|
||||||
|
inline Index col() const { return m_outer; }
|
||||||
};
|
};
|
||||||
|
|
||||||
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType>
|
template<typename Lhs, typename Rhs, typename SparseDiagonalProductType>
|
||||||
@ -160,11 +164,15 @@ class sparse_diagonal_product_inner_iterator_selector
|
|||||||
SparseInnerVectorSet<Lhs,1>,
|
SparseInnerVectorSet<Lhs,1>,
|
||||||
Transpose<const typename Rhs::DiagonalVectorType> >::InnerIterator Base;
|
Transpose<const typename Rhs::DiagonalVectorType> >::InnerIterator Base;
|
||||||
typedef typename Lhs::Index Index;
|
typedef typename Lhs::Index Index;
|
||||||
|
Index m_outer;
|
||||||
public:
|
public:
|
||||||
inline sparse_diagonal_product_inner_iterator_selector(
|
inline sparse_diagonal_product_inner_iterator_selector(
|
||||||
const SparseDiagonalProductType& expr, Index outer)
|
const SparseDiagonalProductType& expr, Index outer)
|
||||||
: Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().diagonal().transpose()), 0)
|
: Base(expr.lhs().innerVector(outer) .cwiseProduct(expr.rhs().diagonal().transpose()), 0), m_outer(outer)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
inline Index outer() const { return m_outer; }
|
||||||
|
inline Index row() const { return m_outer; }
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace internal
|
} // end namespace internal
|
||||||
|
@ -123,6 +123,7 @@ template<typename SparseMatrixType> void sparse_product()
|
|||||||
{
|
{
|
||||||
DenseMatrix refM2 = DenseMatrix::Zero(rows, cols);
|
DenseMatrix refM2 = DenseMatrix::Zero(rows, cols);
|
||||||
DenseMatrix refM3 = DenseMatrix::Zero(rows, cols);
|
DenseMatrix refM3 = DenseMatrix::Zero(rows, cols);
|
||||||
|
DenseMatrix d3 = DenseMatrix::Zero(rows, cols);
|
||||||
DiagonalMatrix<Scalar,Dynamic> d1(DenseVector::Random(cols));
|
DiagonalMatrix<Scalar,Dynamic> d1(DenseVector::Random(cols));
|
||||||
DiagonalMatrix<Scalar,Dynamic> d2(DenseVector::Random(rows));
|
DiagonalMatrix<Scalar,Dynamic> d2(DenseVector::Random(rows));
|
||||||
SparseMatrixType m2(rows, cols);
|
SparseMatrixType m2(rows, cols);
|
||||||
@ -133,6 +134,12 @@ template<typename SparseMatrixType> void sparse_product()
|
|||||||
VERIFY_IS_APPROX(m3=m2.transpose()*d2, refM3=refM2.transpose()*d2);
|
VERIFY_IS_APPROX(m3=m2.transpose()*d2, refM3=refM2.transpose()*d2);
|
||||||
VERIFY_IS_APPROX(m3=d2*m2, refM3=d2*refM2);
|
VERIFY_IS_APPROX(m3=d2*m2, refM3=d2*refM2);
|
||||||
VERIFY_IS_APPROX(m3=d1*m2.transpose(), refM3=d1*refM2.transpose());
|
VERIFY_IS_APPROX(m3=d1*m2.transpose(), refM3=d1*refM2.transpose());
|
||||||
|
|
||||||
|
// evaluate to a dense matrix to check the .row() and .col() iterator functions
|
||||||
|
VERIFY_IS_APPROX(d3=m2*d1, refM3=refM2*d1);
|
||||||
|
VERIFY_IS_APPROX(d3=m2.transpose()*d2, refM3=refM2.transpose()*d2);
|
||||||
|
VERIFY_IS_APPROX(d3=d2*m2, refM3=d2*refM2);
|
||||||
|
VERIFY_IS_APPROX(d3=d1*m2.transpose(), refM3=d1*refM2.transpose());
|
||||||
}
|
}
|
||||||
|
|
||||||
// test self adjoint products
|
// test self adjoint products
|
||||||
|
Loading…
x
Reference in New Issue
Block a user