Skip to content
Snippets Groups Projects
Commit 4c426786 authored by Dr. Felix Tobias Schindler's avatar Dr. Felix Tobias Schindler
Browse files

[bindings] add matching type to matrix/vector

parent 93f1835c
No related branches found
No related tags found
No related merge requests found
...@@ -43,12 +43,12 @@ PYBIND11_PLUGIN(_la) ...@@ -43,12 +43,12 @@ PYBIND11_PLUGIN(_la)
LA::bind_Backends(m); LA::bind_Backends(m);
LA::bind_Vector<LA::CommonDenseVector<double>>(m, "CommonDenseVector_double"); auto common_dense_vector_double = LA::bind_Vector<LA::CommonDenseVector<double>>(m, "CommonDenseVector_double");
#if HAVE_DUNE_ISTL #if HAVE_DUNE_ISTL
LA::bind_Vector<LA::IstlDenseVector<double>>(m, "IstlDenseVector_double"); auto istl_dense_vector_double = LA::bind_Vector<LA::IstlDenseVector<double>>(m, "IstlDenseVector_double");
#endif #endif
#if HAVE_EIGEN #if HAVE_EIGEN
LA::bind_Vector<LA::EigenDenseVector<double>>(m, "EigenDenseVector_double"); auto eigen_dense_vector_double = LA::bind_Vector<LA::EigenDenseVector<double>>(m, "EigenDenseVector_double");
#endif #endif
LA::bind_SparsityPatternDefault(m); LA::bind_SparsityPatternDefault(m);
...@@ -56,7 +56,7 @@ PYBIND11_PLUGIN(_la) ...@@ -56,7 +56,7 @@ PYBIND11_PLUGIN(_la)
#define BIND_MATRIX(C, s, c, id) auto c = LA::bind_Matrix<C, s>(m, id); #define BIND_MATRIX(C, s, c, id) auto c = LA::bind_Matrix<C, s>(m, id);
BIND_MATRIX(LA::CommonDenseMatrix<double>, false, common_dense_matrix_double, "CommonDenseMatrix_double"); BIND_MATRIX(LA::CommonDenseMatrix<double>, false, common_dense_matrix_double, "CommonDenseMatrix_double");
BIND_MATRIX(LA::CommonSparseMatrix<double>, true, common_sparse_matrix_double, "CommonSparseMatrix_double"); // BIND_MATRIX(LA::CommonSparseMatrix<double>, true, common_sparse_matrix_double, "CommonSparseMatrix_double");
#if HAVE_DUNE_ISTL #if HAVE_DUNE_ISTL
BIND_MATRIX(LA::IstlRowMajorSparseMatrix<double>, BIND_MATRIX(LA::IstlRowMajorSparseMatrix<double>,
true, true,
...@@ -71,14 +71,14 @@ PYBIND11_PLUGIN(_la) ...@@ -71,14 +71,14 @@ PYBIND11_PLUGIN(_la)
"EigenRowMajorSparseMatrix_double"); "EigenRowMajorSparseMatrix_double");
#endif #endif
#undef BIND_MATRIX #undef BIND_MATRIX
LA::addbind_Matrix_Vector_interaction<LA::CommonDenseVector<double>>(common_dense_matrix_double); LA::addbind_Matrix_Vector_interaction(common_dense_matrix_double, common_dense_vector_double);
LA::addbind_Matrix_Vector_interaction<LA::CommonDenseVector<double>>(common_sparse_matrix_double); // LA::addbind_Matrix_Vector_interaction(common_sparse_matrix_double, common_dense_vector_double);
#if HAVE_DUNE_ISTL #if HAVE_DUNE_ISTL
LA::addbind_Matrix_Vector_interaction<LA::IstlDenseVector<double>>(istl_row_major_sparse_matrix_double); LA::addbind_Matrix_Vector_interaction(istl_row_major_sparse_matrix_double, istl_dense_vector_double);
#endif #endif
#if HAVE_EIGEN #if HAVE_EIGEN
LA::addbind_Matrix_Vector_interaction<LA::EigenDenseVector<double>>(eigen_dense_matrix_double); LA::addbind_Matrix_Vector_interaction(eigen_dense_matrix_double, eigen_dense_vector_double);
LA::addbind_Matrix_Vector_interaction<LA::EigenDenseVector<double>>(eigen_row_major_sparse_matrix_double); LA::addbind_Matrix_Vector_interaction(eigen_row_major_sparse_matrix_double, eigen_dense_vector_double);
#endif #endif
LA::bind_Solver<LA::CommonDenseMatrix<double>>(m, "CommonDenseMatrix_double"); LA::bind_Solver<LA::CommonDenseMatrix<double>>(m, "CommonDenseMatrix_double");
......
...@@ -99,8 +99,6 @@ typename std::enable_if<is_matrix<C>::value, pybind11::class_<C>>::type bind_Mat ...@@ -99,8 +99,6 @@ typename std::enable_if<is_matrix<C>::value, pybind11::class_<C>>::type bind_Mat
addbind_ProvidesBackend(c); addbind_ProvidesBackend(c);
c.def_property_readonly_static("vector_type", [](py::object /*self*/) { return C::vector_type; });
internal::addbind_Matrix<C, sparse>::template ctor<S>(c); internal::addbind_Matrix<C, sparse>::template ctor<S>(c);
c.def("__init__", c.def("__init__",
[](C& self, const ssize_t rows, const ssize_t cols, const SparsityPatternDefault& pattern) { [](C& self, const ssize_t rows, const ssize_t cols, const SparsityPatternDefault& pattern) {
...@@ -161,14 +159,17 @@ typename std::enable_if<is_matrix<C>::value, pybind11::class_<C>>::type bind_Mat ...@@ -161,14 +159,17 @@ typename std::enable_if<is_matrix<C>::value, pybind11::class_<C>>::type bind_Mat
} // ... bind_Matrix(...) } // ... bind_Matrix(...)
template <class V, class M> template <class M, class V>
void addbind_Matrix_Vector_interaction(pybind11::class_<M>& c) void addbind_Matrix_Vector_interaction(pybind11::class_<M>& mat, pybind11::class_<V>& vec)
{ {
namespace py = pybind11; namespace py = pybind11;
c.def("mv", [](const M& self, const V& xx, V& yy) { self.mv(xx, yy); }, "source", "range"); mat.def("mv", [](const M& self, const V& xx, V& yy) { self.mv(xx, yy); }, "source", "range");
mat.def(py::self * V());
c.def(py::self * V()); mat.def("vector_type", [vec](M& /*self*/) { return vec; });
vec.def("matrix_type", [mat](V& /*self*/) { return mat; });
} // ... addbind_Matrix_Vector_interaction(...) } // ... addbind_Matrix_Vector_interaction(...)
......
...@@ -43,9 +43,6 @@ typename std::enable_if<is_vector<C>::value, pybind11::class_<C>>::type bind_Vec ...@@ -43,9 +43,6 @@ typename std::enable_if<is_vector<C>::value, pybind11::class_<C>>::type bind_Vec
py::class_<C> c = bind_ProvidesDataAccess<C>(m, id, id); py::class_<C> c = bind_ProvidesDataAccess<C>(m, id, id);
addbind_ProvidesBackend(c); addbind_ProvidesBackend(c);
c.def_property_readonly_static("dense_matrix_type", [](py::object /*self*/) { return C::dense_matrix_type; });
c.def_property_readonly_static("sparse_matrix_type", [](py::object /*self*/) { return C::sparse_matrix_type; });
c.def("__init__", c.def("__init__",
[](C& vec, const ssize_t size, const S& value) { [](C& vec, const ssize_t size, const S& value) {
try { try {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment