scipy-type.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024 INRIA
3  */
4 
5 #ifndef __eigenpy_scipy_type_hpp__
6 #define __eigenpy_scipy_type_hpp__
7 
8 #include "eigenpy/fwd.hpp"
9 #include "eigenpy/register.hpp"
11 #include "eigenpy/numpy-type.hpp"
12 
13 namespace eigenpy {
14 
15 struct EIGENPY_DLLAPI ScipyType {
16  static ScipyType& getInstance();
17 
18  static void sharedMemory(const bool value);
19 
20  static bool sharedMemory();
21 
22  static bp::object getScipyType();
23 
24  static const PyTypeObject* getScipyCSRMatrixType();
25  static const PyTypeObject* getScipyCSCMatrixType();
26 
27  template <typename SparseMatrix>
28  static bp::object get_pytype_object(
29  const Eigen::SparseMatrixBase<SparseMatrix>* ptr = nullptr) {
31  return SparseMatrix::IsRowMajor ? getInstance().csr_matrix_obj
32  : getInstance().csc_matrix_obj;
33  }
34 
35  template <typename SparseMatrix>
36  static PyTypeObject const* get_pytype(
37  const Eigen::SparseMatrixBase<SparseMatrix>* ptr = nullptr) {
39  return SparseMatrix::IsRowMajor ? getInstance().csr_matrix_type
40  : getInstance().csc_matrix_type;
41  }
42 
43  static int get_numpy_type_num(const bp::object& obj) {
44  const PyTypeObject* type = Py_TYPE(obj.ptr());
46  assert(type == getInstance().csr_matrix_type ||
47  type == getInstance().csc_matrix_type);
48 
49  bp::object dtype = obj.attr("dtype");
50 
51  const PyArray_Descr* npy_type =
52  reinterpret_cast<PyArray_Descr*>(dtype.ptr());
53  return npy_type->type_num;
54  }
55 
56  protected:
57  ScipyType();
58 
59  bp::object sparse_module;
60 
61  // SciPy types
62  bp::object csr_matrix_obj, csc_matrix_obj;
63  PyTypeObject *csr_matrix_type, *csc_matrix_type;
64 
66 };
67 } // namespace eigenpy
68 
69 #endif // ifndef __eigenpy_scipy_type_hpp__
register.hpp
EIGENPY_USED_VARIABLE_ONLY_IN_DEBUG_MODE
#define EIGENPY_USED_VARIABLE_ONLY_IN_DEBUG_MODE(var)
Definition: fwd.hpp:114
eigenpy::ScipyType::sparse_module
bp::object sparse_module
Definition: scipy-type.hpp:59
EIGENPY_UNUSED_VARIABLE
#define EIGENPY_UNUSED_VARIABLE(var)
Definition: fwd.hpp:111
fwd.hpp
scalar-conversion.hpp
eigenpy
Definition: alignment.hpp:14
eigenpy::ScipyType::get_pytype
static PyTypeObject const * get_pytype(const Eigen::SparseMatrixBase< SparseMatrix > *ptr=nullptr)
Definition: scipy-type.hpp:36
eigenpy::ScipyType::get_numpy_type_num
static int get_numpy_type_num(const bp::object &obj)
Definition: scipy-type.hpp:43
eigenpy::ScipyType::get_pytype_object
static bp::object get_pytype_object(const Eigen::SparseMatrixBase< SparseMatrix > *ptr=nullptr)
Definition: scipy-type.hpp:28
test_matrix.value
float value
Definition: test_matrix.py:161
eigenpy::ScipyType
Definition: scipy-type.hpp:15
eigenpy::ScipyType::csr_matrix_type
PyTypeObject * csr_matrix_type
Definition: scipy-type.hpp:63
eigenpy::ScipyType::csr_matrix_obj
bp::object csr_matrix_obj
Definition: scipy-type.hpp:62
numpy-type.hpp
eigenpy::ScipyType::shared_memory
bool shared_memory
Definition: scipy-type.hpp:65


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 14 2024 02:15:58