15struct EIGENPY_DLLAPI ScipyType {
16 static ScipyType& getInstance();
18 static void sharedMemory(
const bool value);
20 static bool sharedMemory();
22 static bp::object getScipyType();
24 static const PyTypeObject* getScipyCSRMatrixType();
25 static const PyTypeObject* getScipyCSCMatrixType();
27 template <
typename SparseMatrix>
28 static bp::object get_pytype_object(
29 const Eigen::SparseMatrixBase<SparseMatrix>* ptr =
nullptr) {
30 EIGENPY_UNUSED_VARIABLE(ptr);
31 return SparseMatrix::IsRowMajor ? getInstance().csr_matrix_obj
32 : getInstance().csc_matrix_obj;
35 template <
typename SparseMatrix>
36 static PyTypeObject
const* get_pytype(
37 const Eigen::SparseMatrixBase<SparseMatrix>* ptr =
nullptr) {
38 EIGENPY_UNUSED_VARIABLE(ptr);
39 return SparseMatrix::IsRowMajor ? getInstance().csr_matrix_type
40 : getInstance().csc_matrix_type;
43 static int get_numpy_type_num(
const bp::object& obj) {
44 const PyTypeObject*
type = Py_TYPE(obj.ptr());
45 EIGENPY_USED_VARIABLE_ONLY_IN_DEBUG_MODE(
type);
46 assert(
type == getInstance().csr_matrix_type ||
47 type == getInstance().csc_matrix_type);
49 bp::object dtype = obj.attr(
"dtype");
51 const PyArray_Descr* npy_type =
52 reinterpret_cast<PyArray_Descr*
>(dtype.ptr());
53 return npy_type->type_num;
59 bp::object sparse_module;
62 bp::object csr_matrix_obj, csc_matrix_obj;
63 PyTypeObject *csr_matrix_type, *csc_matrix_type;