Skip to content

Commit cc9da81

Browse files
authored
Merge pull request #361 from jcarpent/devel
Remove support of numpy.matrix class
2 parents 14787a6 + d66fb9f commit cc9da81

18 files changed

+18
-695
lines changed

README.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ EigenPy — Efficient Python bindings between Numpy/Eigen
1010
<a href="https://github.com/psf/black"><img src="https://img.shields.io/badge/code%20style-black-000000.svg" alt="Code style: black"></a>
1111
</p>
1212

13-
**EigenPy** is an open source framework which allows to bind the famous [Eigen](http://eigen.tuxfamily.org) C++ library in Python.
13+
**EigenPy** is an open source framework which allows to bind the famous [Eigen](http://eigen.tuxfamily.org) C++ library in Python via Boost.Python.
1414

1515
**EigenPy** provides:
1616
- full memory sharing between Numpy and Eigen avoiding memory allocation
1717
- full support Eigen::Ref avoiding memory allocation
18+
- full support of the Eigen::Tensor module
1819
- exposition of the Geometry module of Eigen for easy code prototyping
1920
- standard matrix decomposion routines of Eigen such as the Cholesky decomposition, SVD decomposition, QR decomposition, and etc.
2021
- full support of SWIG objects
22+
- full support of runtime declaration of Numpy scalar types
23+
- extended API to expose std::vector types
2124

2225
## Setup
2326

@@ -26,9 +29,10 @@ The installation of **EigenPy** on your computer is made easy for Linux/BSD, Mac
2629
### The Conda approach
2730

2831
You simply need this simple line:
29-
```
32+
```bash
3033
conda install eigenpy -c conda-forge
3134
```
35+
3236
### Ubuntu
3337

3438
You can easily install **EigenPy** from binairies.
@@ -43,18 +47,14 @@ sudo sh -c "echo 'deb [arch=amd64] http://robotpkg.openrobots.org/packages/debia
4347
curl http://robotpkg.openrobots.org/packages/debian/robotpkg.key | sudo apt-key add -
4448
```
4549
3. You need to run at least once apt update to fetch the package descriptions:
46-
```
50+
```bash
4751
sudo apt-get update
4852
```
53+
4954
#### Install EigenPy
5055
4. The installation of **EigenPy** and its dependencies is made through the line:
5156

52-
For Python 2.7
53-
```
54-
sudo apt install robotpkg-py27-eigenpy
55-
```
56-
or for Python 3.{5,6,7}
57-
```
57+
```bash
5858
sudo apt install robotpkg-py35-eigenpy
5959
```
6060
where 35 should be replaced by the python 3 you want to work this (e.g. `robotpkg-py36-eigenpy` to work with Python 3.6).
@@ -81,6 +81,7 @@ The following people have been involved in the development of **EigenPy**:
8181
- [Wolfgang Merkt](http://www.wolfgangmerkt.com/) (University of Edinburgh): ROS integration and support
8282
- [Sean Yen](https://www.linkedin.com/in/seanyentw) (Microsoft): Windows integration
8383
- [Loïc Estève](https://github.com/lesteve) (INRIA): Conda integration
84+
- [Wilson Jallet](https://manifoldfr.github.io/) (INRIA/LAAS-CNRS): core developer
8485

8586
If you have taken part to the development of **EigenPy**, feel free to add your name and contribution here.
8687

benchmarks/bench-switch.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,23 +24,6 @@
2424
ipython.magic(cmd2)
2525
print("\n")
2626

27-
eigenpy.switchToNumpyMatrix()
28-
print("----------------------")
29-
print("switch to numpy matrix")
30-
print("----------------------")
31-
print("\n")
32-
33-
cmd3 = "timeit quat.coeffs()"
34-
print(cmd3)
35-
ipython.magic(cmd3)
36-
print("\n")
37-
38-
eigenpy.switchToNumpyArray()
39-
print("---------------------")
40-
print("switch to numpy array")
41-
print("---------------------")
42-
print("\n")
43-
4427
cmd4 = "timeit quat.coeffs()"
4528
print(cmd4)
4629
ipython.magic(cmd4)

include/eigenpy/eigen-to-python.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,8 @@ struct eigen_to_py_impl_matrix {
101101
PyArrayObject* pyArray;
102102
// Allocate Python memory
103103
if ((((!(C == 1) != !(R == 1)) && !MatrixDerived::IsVectorAtCompileTime) ||
104-
MatrixDerived::IsVectorAtCompileTime) &&
105-
NumpyType::getType() ==
106-
ARRAY_TYPE) // Handle array with a single dimension
104+
MatrixDerived::IsVectorAtCompileTime)) // Handle array with a single
105+
// dimension
107106
{
108107
npy_intp shape[1] = {C == 1 ? R : C};
109108
pyArray = NumpyAllocator<MatType>::allocate(

include/eigenpy/numpy-type.hpp

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2020 INRIA
2+
* Copyright 2018-2023 INRIA
33
*/
44

55
#ifndef __eigenpy_numpy_type_hpp__
@@ -45,54 +45,30 @@ bool np_type_is_convertible_into_scalar(const int np_type) {
4545
}
4646
}
4747

48-
enum NP_TYPE { MATRIX_TYPE, ARRAY_TYPE };
49-
5048
struct EIGENPY_DLLAPI NumpyType {
5149
static NumpyType& getInstance();
5250

53-
operator bp::object() { return getInstance().CurrentNumpyType; }
54-
5551
static bp::object make(PyArrayObject* pyArray, bool copy = false);
5652

5753
static bp::object make(PyObject* pyObj, bool copy = false);
5854

59-
static void setNumpyType(bp::object& obj);
60-
6155
static void sharedMemory(const bool value);
6256

6357
static bool sharedMemory();
6458

65-
static void switchToNumpyArray();
66-
67-
static void switchToNumpyMatrix();
68-
69-
static NP_TYPE& getType();
70-
7159
static bp::object getNumpyType();
7260

73-
static const PyTypeObject* getNumpyMatrixType();
74-
7561
static const PyTypeObject* getNumpyArrayType();
7662

77-
static bool isMatrix();
78-
79-
static bool isArray();
80-
8163
protected:
8264
NumpyType();
8365

84-
bp::object CurrentNumpyType;
8566
bp::object pyModule;
8667

8768
// Numpy types
88-
bp::object NumpyMatrixObject;
89-
PyTypeObject* NumpyMatrixType;
90-
// bp::object NumpyAsMatrixObject; PyTypeObject * NumpyAsMatrixType;
9169
bp::object NumpyArrayObject;
9270
PyTypeObject* NumpyArrayType;
9371

94-
NP_TYPE np_type;
95-
9672
bool shared_memory;
9773
};
9874
} // namespace eigenpy

src/eigenpy.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright 2014-2019, CNRS
3-
* Copyright 2018-2021, INRIA
3+
* Copyright 2018-2023, INRIA
44
*/
55

66
#include "eigenpy/eigenpy.hpp"
@@ -30,20 +30,6 @@ void enableEigenPy() {
3030

3131
Exception::registerException();
3232

33-
bp::def(
34-
"setNumpyType", &NumpyType::setNumpyType, bp::arg("numpy_type"),
35-
"Change the Numpy type returned by the converters from an Eigen object.");
36-
37-
bp::def(
38-
"getNumpyType", &NumpyType::getNumpyType,
39-
"Get the Numpy type returned by the converters from an Eigen object.");
40-
41-
bp::def("switchToNumpyArray", &NumpyType::switchToNumpyArray,
42-
"Set the conversion from Eigen::Matrix to numpy.ndarray.");
43-
44-
bp::def("switchToNumpyMatrix", &NumpyType::switchToNumpyMatrix,
45-
"Set the conversion from Eigen::Matrix to numpy.matrix.");
46-
4733
bp::def("sharedMemory", (void (*)(const bool))NumpyType::sharedMemory,
4834
bp::arg("value"),
4935
"Share the memory when converting from Eigen to Numpy.");

src/numpy-type.cpp

Lines changed: 3 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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-
4328
void NumpyType::sharedMemory(const bool value) {
4429
getInstance().shared_memory = value;
4530
}
4631

4732
bool 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-
6734
const 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-
8438
NumpyType::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
}

unittest/CMakeLists.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,6 @@ if(NOT NUMPY_WITH_BROKEN_UFUNC_SUPPORT)
8080
"unittest")
8181
endif()
8282

83-
add_python_unit_test("py-switch" "unittest/python/test_switch.py"
84-
"python;unittest")
85-
set_tests_properties("py-switch" PROPERTIES DEPENDS ${PYWRAP})
86-
8783
add_python_unit_test("py-dimensions" "unittest/python/test_dimensions.py"
8884
"python;unittest")
8985
set_tests_properties("py-dimensions" PROPERTIES DEPENDS ${PYWRAP})

unittest/alpha/bnpy.cpp

Lines changed: 0 additions & 35 deletions
This file was deleted.

0 commit comments

Comments
 (0)