numpy-type.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2018-2023 INRIA
3  */
4 
5 #include "eigenpy/numpy-type.hpp"
6 
7 #include <patchlevel.h> // For PY_MAJOR_VERSION
8 
9 namespace eigenpy {
10 
12  static NumpyType instance;
13  return instance;
14 }
15 
16 bp::object NumpyType::make(PyArrayObject* pyArray, bool copy) {
17  return make((PyObject*)pyArray, copy);
18 }
19 
20 bp::object NumpyType::make(PyObject* pyObj, bool /*copy*/) {
21  bp::object m;
22  m = bp::object(bp::handle<>(pyObj)); // nothing to do here
23 
24  Py_INCREF(m.ptr());
25  return m;
26 }
27 
28 void NumpyType::sharedMemory(const bool value) {
30 }
31 
33 
34 const PyTypeObject* NumpyType::getNumpyArrayType() {
35  return getInstance().NumpyArrayType;
36 }
37 
39  pyModule = bp::import("numpy");
40 
41 #if PY_MAJOR_VERSION >= 3
42  // TODO I don't know why this Py_INCREF is necessary.
43  // Without it, the destructor of NumpyType SEGV sometimes.
44  Py_INCREF(pyModule.ptr());
45 #endif
46 
47  NumpyArrayObject = pyModule.attr("ndarray");
48  NumpyArrayType = reinterpret_cast<PyTypeObject*>(NumpyArrayObject.ptr());
49 
50  shared_memory = true;
51 }
52 } // namespace eigenpy
ReturnMatrix copy(const Eigen::MatrixBase< Matrix > &mat)
Definition: matrix.cpp:131
static bool sharedMemory()
Definition: numpy-type.cpp:32
bp::object NumpyArrayObject
Definition: numpy-type.hpp:69
static bp::object make(PyArrayObject *pyArray, bool copy=false)
Definition: numpy-type.cpp:16
static const PyTypeObject * getNumpyArrayType()
Definition: numpy-type.cpp:34
PyTypeObject * NumpyArrayType
Definition: numpy-type.hpp:70
static NumpyType & getInstance()
Definition: numpy-type.cpp:11
bp::object pyModule
Definition: numpy-type.hpp:66


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 2 2023 02:10:26