From f9ef66b2d3af601520508c1747126bcd99e29c7b Mon Sep 17 00:00:00 2001 From: Justin Carpentier Date: Fri, 26 Jan 2024 11:35:06 +0100 Subject: [PATCH] test/sparse: extend test for Row and Col major matrices --- unittest/python/test_sparse_matrix.py | 4 +++ unittest/sparse_matrix.cpp | 35 ++++++++++++--------------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/unittest/python/test_sparse_matrix.py b/unittest/python/test_sparse_matrix.py index 803ebe7d9..428c3bede 100644 --- a/unittest/python/test_sparse_matrix.py +++ b/unittest/python/test_sparse_matrix.py @@ -2,6 +2,7 @@ import numpy as np import sparse_matrix +from scipy.sparse import csc_matrix, csr_matrix m = sparse_matrix.emptyMatrix() assert m.shape == (0, 0) @@ -22,3 +23,6 @@ diag_mat_copy = sparse_matrix.copy(diag_mat) assert (diag_mat_copy != diag_mat).nnz == 0 + +diag_mat_csr = csr_matrix(diag_mat) +assert (sparse_matrix.copy(diag_mat_csr) != diag_mat_csr).nnz == 0 diff --git a/unittest/sparse_matrix.cpp b/unittest/sparse_matrix.cpp index 4fb23a61d..e8e4b2d60 100644 --- a/unittest/sparse_matrix.cpp +++ b/unittest/sparse_matrix.cpp @@ -35,11 +35,6 @@ Eigen::SparseMatrix diagonal( return mat; } -template -void matrix1x1_input(const Eigen::Matrix& mat) { - std::cout << mat << std::endl; -} - template Eigen::SparseMatrix emptyVector() { return Eigen::SparseMatrix(); @@ -61,24 +56,24 @@ Eigen::SparseMatrix copy( return mat; } -BOOST_PYTHON_MODULE(sparse_matrix) { - using namespace Eigen; +template +void expose_functions() { namespace bp = boost::python; - eigenpy::enableEigenPy(); + bp::def("vector1x1", vector1x1); + bp::def("matrix1x1", matrix1x1); - typedef Eigen::SparseMatrix SparseMatrixD; - eigenpy::EigenToPyConverter::registration(); - eigenpy::EigenFromPyConverter::registration(); + bp::def("print", print); + bp::def("copy", copy); + bp::def("diagonal", diagonal); - bp::def("vector1x1", vector1x1); - bp::def("matrix1x1", matrix1x1); - bp::def("matrix1x1", matrix1x1_input); - bp::def("matrix1x1_int", matrix1x1_input); + bp::def("emptyVector", emptyVector); + bp::def("emptyMatrix", emptyMatrix); +} - bp::def("print", print); - bp::def("copy", copy); - bp::def("diagonal", diagonal); +BOOST_PYTHON_MODULE(sparse_matrix) { + namespace bp = boost::python; + eigenpy::enableEigenPy(); - bp::def("emptyVector", emptyVector); - bp::def("emptyMatrix", emptyMatrix); + expose_functions(); + expose_functions(); }