extend unit tests to check rectangular matrices for sparse*diagonal products

This commit is contained in:
Gael Guennebaud 2012-10-02 23:03:06 +02:00
parent 62b1f75a86
commit f30ca7ed7e

View File

@ -43,7 +43,7 @@ template<typename SparseMatrixType> void sparse_product()
typedef typename SparseMatrixType::Scalar Scalar; typedef typename SparseMatrixType::Scalar Scalar;
enum { Flags = SparseMatrixType::Flags }; enum { Flags = SparseMatrixType::Flags };
double density = (std::max)(8./(rows*cols), 0.01); double density = (std::max)(8./(rows*cols), 0.1);
typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix; typedef Matrix<Scalar,Dynamic,Dynamic> DenseMatrix;
typedef Matrix<Scalar,Dynamic,1> DenseVector; typedef Matrix<Scalar,Dynamic,1> DenseVector;
@ -121,17 +121,18 @@ template<typename SparseMatrixType> void sparse_product()
// test matrix - diagonal product // test matrix - diagonal product
{ {
DenseMatrix refM2 = DenseMatrix::Zero(rows, rows); DenseMatrix refM2 = DenseMatrix::Zero(rows, cols);
DenseMatrix refM3 = DenseMatrix::Zero(rows, rows); DenseMatrix refM3 = DenseMatrix::Zero(rows, cols);
DiagonalMatrix<Scalar,Dynamic> d1(DenseVector::Random(rows)); DiagonalMatrix<Scalar,Dynamic> d1(DenseVector::Random(cols));
SparseMatrixType m2(rows, rows); DiagonalMatrix<Scalar,Dynamic> d2(DenseVector::Random(rows));
SparseMatrixType m3(rows, rows); SparseMatrixType m2(rows, cols);
SparseMatrixType m3(rows, cols);
initSparse<Scalar>(density, refM2, m2); initSparse<Scalar>(density, refM2, m2);
initSparse<Scalar>(density, refM3, m3); initSparse<Scalar>(density, refM3, m3);
VERIFY_IS_APPROX(m3=m2*d1, refM3=refM2*d1); VERIFY_IS_APPROX(m3=m2*d1, refM3=refM2*d1);
VERIFY_IS_APPROX(m3=m2.transpose()*d1, refM3=refM2.transpose()*d1); VERIFY_IS_APPROX(m3=m2.transpose()*d2, refM3=refM2.transpose()*d2);
VERIFY_IS_APPROX(m3=d1*m2, refM3=d1*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());
} }
// test self adjoint products // test self adjoint products