diff options
author | Gael Guennebaud <g.gael@free.fr> | 2009-04-05 16:30:10 +0000 |
---|---|---|
committer | Gael Guennebaud <g.gael@free.fr> | 2009-04-05 16:30:10 +0000 |
commit | 5b1d0cebc5c30975f6f392d6f7d49d35e2a3508f (patch) | |
tree | 7d5f81092e84ef67bb68b14dcef4a2d2a862a1d2 /test | |
parent | 5a628567b0d55730875220e6ed005c30f289e230 (diff) |
sparse module: new API proposal for triangular solves and experimental
solver support with a sparse matrix as the rhs.
Diffstat (limited to 'test')
-rw-r--r-- | test/sparse_product.cpp | 6 | ||||
-rw-r--r-- | test/sparse_solvers.cpp | 32 |
2 files changed, 32 insertions, 6 deletions
diff --git a/test/sparse_product.cpp b/test/sparse_product.cpp index 3a0356f00..00b5a3ed5 100644 --- a/test/sparse_product.cpp +++ b/test/sparse_product.cpp @@ -40,6 +40,7 @@ template<typename SparseMatrixType> void sparse_product(const SparseMatrixType& DenseMatrix refMat2 = DenseMatrix::Zero(rows, rows); DenseMatrix refMat3 = DenseMatrix::Zero(rows, rows); DenseMatrix refMat4 = DenseMatrix::Zero(rows, rows); + DenseMatrix refMat5 = DenseMatrix::Random(rows, rows); DenseMatrix dm4 = DenseMatrix::Zero(rows, rows); SparseMatrixType m2(rows, rows); SparseMatrixType m3(rows, rows); @@ -57,7 +58,10 @@ template<typename SparseMatrixType> void sparse_product(const SparseMatrixType& VERIFY_IS_APPROX(dm4=m2*refMat3.transpose(), refMat4=refMat2*refMat3.transpose()); VERIFY_IS_APPROX(dm4=m2.transpose()*refMat3, refMat4=refMat2.transpose()*refMat3); VERIFY_IS_APPROX(dm4=m2.transpose()*refMat3.transpose(), refMat4=refMat2.transpose()*refMat3.transpose()); - + + VERIFY_IS_APPROX(dm4=m2*(refMat3+refMat3), refMat4=refMat2*(refMat3+refMat3)); + VERIFY_IS_APPROX(dm4=m2.transpose()*(refMat3+refMat5)*0.5, refMat4=refMat2.transpose()*(refMat3+refMat5)*0.5); + // dense * sparse VERIFY_IS_APPROX(dm4=refMat2*m3, refMat4=refMat2*refMat3); VERIFY_IS_APPROX(dm4=refMat2*m3.transpose(), refMat4=refMat2*refMat3.transpose()); diff --git a/test/sparse_solvers.cpp b/test/sparse_solvers.cpp index 8ce4e2264..d1090dfed 100644 --- a/test/sparse_solvers.cpp +++ b/test/sparse_solvers.cpp @@ -63,17 +63,39 @@ template<typename Scalar> void sparse_solvers(int rows, int cols) SparseMatrix<Scalar> m2(rows, cols); DenseMatrix refMat2 = DenseMatrix::Zero(rows, cols); - // lower + // lower - dense initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, &zeroCoords, &nonzeroCoords); VERIFY_IS_APPROX(refMat2.template marked<LowerTriangular>().solveTriangular(vec2), - m2.template marked<LowerTriangular>().solveTriangular(vec3)); + m2.template triangular<LowerTriangular>().solve(vec3)); - // upper + // upper - dense initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular, &zeroCoords, &nonzeroCoords); VERIFY_IS_APPROX(refMat2.template marked<UpperTriangular>().solveTriangular(vec2), - m2.template marked<UpperTriangular>().solveTriangular(vec3)); - + m2.template triangular<UpperTriangular>().solve(vec3)); + // TODO test row major + + SparseMatrix<Scalar> matB(rows, rows); + DenseMatrix refMatB = DenseMatrix::Zero(rows, rows); + + // lower - sparse + initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular); + initSparse<Scalar>(density, refMatB, matB); + refMat2.template marked<LowerTriangular>().solveTriangularInPlace(refMatB); + m2.template triangular<LowerTriangular>().solveInPlace(matB); + VERIFY_IS_APPROX(matB.toDense(), refMatB); + + // upper - sparse + initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeUpperTriangular); + initSparse<Scalar>(density, refMatB, matB); + refMat2.template marked<UpperTriangular>().solveTriangularInPlace(refMatB); + m2.template triangular<UpperTriangular>().solveInPlace(matB); + VERIFY_IS_APPROX(matB, refMatB); + + // test deprecated API + initSparse<Scalar>(density, refMat2, m2, ForceNonZeroDiag|MakeLowerTriangular, &zeroCoords, &nonzeroCoords); + VERIFY_IS_APPROX(refMat2.template marked<LowerTriangular>().solveTriangular(vec2), + m2.template marked<LowerTriangular>().solveTriangular(vec3)); } // test LLT |