src
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
11
NumpyType
&
NumpyType::getInstance
() {
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
) {
29
getInstance
().
shared_memory
=
value
;
30
}
31
32
bool
NumpyType::sharedMemory
() {
return
getInstance
().
shared_memory
; }
33
34
const
PyTypeObject*
NumpyType::getNumpyArrayType
() {
35
return
getInstance
().
NumpyArrayType
;
36
}
37
38
NumpyType::NumpyType
() {
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
eigenpy::NumpyType::getNumpyArrayType
static const PyTypeObject * getNumpyArrayType()
Definition:
numpy-type.cpp:34
eigenpy::NumpyType
Definition:
numpy-type.hpp:85
eigenpy::NumpyType::shared_memory
bool shared_memory
Definition:
numpy-type.hpp:107
eigenpy::NumpyType::NumpyType
NumpyType()
Definition:
numpy-type.cpp:38
eigenpy::NumpyType::NumpyArrayType
PyTypeObject * NumpyArrayType
Definition:
numpy-type.hpp:105
eigenpy::NumpyType::sharedMemory
static bool sharedMemory()
Definition:
numpy-type.cpp:32
eigenpy
Definition:
alignment.hpp:14
eigenpy::NumpyType::make
static bp::object make(PyArrayObject *pyArray, bool copy=false)
Definition:
numpy-type.cpp:16
copy
ReturnMatrix copy(const Eigen::MatrixBase< Matrix > &mat)
Definition:
matrix.cpp:131
test_matrix.value
float value
Definition:
test_matrix.py:161
eigenpy::NumpyType::NumpyArrayObject
bp::object NumpyArrayObject
Definition:
numpy-type.hpp:104
test_sparse_matrix.m
m
Definition:
test_sparse_matrix.py:5
numpy-type.hpp
eigenpy::NumpyType::getInstance
static NumpyType & getInstance()
Definition:
numpy-type.cpp:11
eigenpy::NumpyType::pyModule
bp::object pyModule
Definition:
numpy-type.hpp:101
eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Sat Nov 2 2024 02:14:45