11/*
2- * Copyright 2018-2020 INRIA
2+ * Copyright 2018-2023 INRIA
33 */
44
55#include " eigenpy/numpy-type.hpp"
@@ -17,70 +17,24 @@ bp::object NumpyType::make(PyArrayObject* pyArray, bool copy) {
1717 return make ((PyObject*)pyArray, copy);
1818}
1919
20- bp::object NumpyType::make (PyObject* pyObj, bool copy) {
20+ bp::object NumpyType::make (PyObject* pyObj, bool /* copy*/ ) {
2121 bp::object m;
22- if (isMatrix ())
23- m = getInstance ().NumpyMatrixObject (bp::object (bp::handle<>(pyObj)),
24- bp::object (), copy);
25- // m = NumpyAsMatrixObject(bp::object(bp::handle<>(pyObj)));
26- else if (isArray ())
27- m = bp::object (bp::handle<>(pyObj)); // nothing to do here
22+ m = bp::object (bp::handle<>(pyObj)); // nothing to do here
2823
2924 Py_INCREF (m.ptr ());
3025 return m;
3126}
3227
33- void NumpyType::setNumpyType (bp::object& obj) {
34- PyTypeObject* obj_type = PyType_Check (obj.ptr ())
35- ? reinterpret_cast <PyTypeObject*>(obj.ptr ())
36- : obj.ptr ()->ob_type ;
37- if (PyType_IsSubtype (obj_type, getInstance ().NumpyMatrixType ))
38- switchToNumpyMatrix ();
39- else if (PyType_IsSubtype (obj_type, getInstance ().NumpyArrayType ))
40- switchToNumpyArray ();
41- }
42-
4328void NumpyType::sharedMemory (const bool value) {
4429 getInstance ().shared_memory = value;
4530}
4631
4732bool NumpyType::sharedMemory () { return getInstance ().shared_memory ; }
4833
49- void NumpyType::switchToNumpyArray () {
50- getInstance ().CurrentNumpyType = getInstance ().NumpyArrayObject ;
51- getInstance ().getType () = ARRAY_TYPE;
52- }
53-
54- void NumpyType::switchToNumpyMatrix () {
55- getInstance ().CurrentNumpyType = getInstance ().NumpyMatrixObject ;
56- getInstance ().getType () = MATRIX_TYPE;
57- }
58-
59- NP_TYPE& NumpyType::getType () { return getInstance ().np_type ; }
60-
61- bp::object NumpyType::getNumpyType () { return getInstance ().CurrentNumpyType ; }
62-
63- const PyTypeObject* NumpyType::getNumpyMatrixType () {
64- return getInstance ().NumpyMatrixType ;
65- }
66-
6734const PyTypeObject* NumpyType::getNumpyArrayType () {
6835 return getInstance ().NumpyArrayType ;
6936}
7037
71- bool NumpyType::isMatrix () {
72- return PyType_IsSubtype (
73- reinterpret_cast <PyTypeObject*>(getInstance ().CurrentNumpyType .ptr ()),
74- getInstance ().NumpyMatrixType );
75- }
76-
77- bool NumpyType::isArray () {
78- if (getInstance ().isMatrix ()) return false ;
79- return PyType_IsSubtype (
80- reinterpret_cast <PyTypeObject*>(getInstance ().CurrentNumpyType .ptr ()),
81- getInstance ().NumpyArrayType );
82- }
83-
8438NumpyType::NumpyType () {
8539 pyModule = bp::import (" numpy" );
8640
@@ -90,16 +44,8 @@ NumpyType::NumpyType() {
9044 Py_INCREF (pyModule.ptr ());
9145#endif
9246
93- NumpyMatrixObject = pyModule.attr (" matrix" );
94- NumpyMatrixType = reinterpret_cast <PyTypeObject*>(NumpyMatrixObject.ptr ());
9547 NumpyArrayObject = pyModule.attr (" ndarray" );
9648 NumpyArrayType = reinterpret_cast <PyTypeObject*>(NumpyArrayObject.ptr ());
97- // NumpyAsMatrixObject = pyModule.attr("asmatrix");
98- // NumpyAsMatrixType =
99- // reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr());
100-
101- CurrentNumpyType = NumpyArrayObject; // default conversion
102- np_type = ARRAY_TYPE;
10349
10450 shared_memory = true ;
10551}
0 commit comments