scipy-type.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2024 INRIA
3  */
4 
5 #include "eigenpy/scipy-type.hpp"
6 
7 #include <patchlevel.h> // For PY_MAJOR_VERSION
8 
9 namespace eigenpy {
10 
12  static ScipyType instance;
13  return instance;
14 }
15 
16 void ScipyType::sharedMemory(const bool value) {
18 }
19 
21 
22 const PyTypeObject* ScipyType::getScipyCSRMatrixType() {
24 }
25 
26 const PyTypeObject* ScipyType::getScipyCSCMatrixType() {
28 }
29 
31  try {
32  sparse_module = bp::import("scipy.sparse");
33  } catch (...) {
34  throw std::runtime_error(
35  "SciPy is not installed. "
36  "You can install it using the command \'pip install scipy\'.");
37  }
38 
39 #if PY_MAJOR_VERSION >= 3
40  // TODO I don't know why this Py_INCREF is necessary.
41  // Without it, the destructor of ScipyType SEGV sometimes.
42  Py_INCREF(sparse_module.ptr());
43 #endif
44 
45  csr_matrix_obj = sparse_module.attr("csr_matrix");
46  csr_matrix_type = reinterpret_cast<PyTypeObject*>(csr_matrix_obj.ptr());
47  csc_matrix_obj = sparse_module.attr("csc_matrix");
48  csc_matrix_type = reinterpret_cast<PyTypeObject*>(csc_matrix_obj.ptr());
49 
50  shared_memory = true;
51 }
52 } // namespace eigenpy
eigenpy::ScipyType::sparse_module
bp::object sparse_module
Definition: scipy-type.hpp:59
eigenpy::ScipyType::getScipyCSCMatrixType
static const PyTypeObject * getScipyCSCMatrixType()
Definition: scipy-type.cpp:26
eigenpy::ScipyType::getInstance
static ScipyType & getInstance()
Definition: scipy-type.cpp:11
eigenpy
Definition: alignment.hpp:14
eigenpy::ScipyType::ScipyType
ScipyType()
Definition: scipy-type.cpp:30
eigenpy::ScipyType::csc_matrix_obj
bp::object csc_matrix_obj
Definition: scipy-type.hpp:62
test_matrix.value
float value
Definition: test_matrix.py:161
eigenpy::ScipyType
Definition: scipy-type.hpp:15
eigenpy::ScipyType::getScipyCSRMatrixType
static const PyTypeObject * getScipyCSRMatrixType()
Definition: scipy-type.cpp:22
eigenpy::ScipyType::csr_matrix_type
PyTypeObject * csr_matrix_type
Definition: scipy-type.hpp:63
eigenpy::ScipyType::sharedMemory
static bool sharedMemory()
Definition: scipy-type.cpp:20
scipy-type.hpp
eigenpy::ScipyType::csr_matrix_obj
bp::object csr_matrix_obj
Definition: scipy-type.hpp:62
eigenpy::ScipyType::csc_matrix_type
PyTypeObject * csc_matrix_type
Definition: scipy-type.hpp:63
eigenpy::ScipyType::shared_memory
bool shared_memory
Definition: scipy-type.hpp:65


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45