Skip to content

Commit d86ce43

Browse files
authored
Merge pull request #150 from jcarpent/topic/array_by_default
Switch to np.array type by default
2 parents 9341871 + 9d8dd7a commit d86ce43

File tree

3 files changed

+11
-22
lines changed

3 files changed

+11
-22
lines changed

include/eigenpy/details.hpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ namespace eigenpy
155155

156156
enum NP_TYPE
157157
{
158-
DEFAULT_TYPE,
159158
MATRIX_TYPE,
160159
ARRAY_TYPE
161160
};
@@ -176,16 +175,6 @@ namespace eigenpy
176175

177176
bp::object make(PyObject* pyObj, bool copy = false)
178177
{
179-
if (getType() == DEFAULT_TYPE) {
180-
std::cerr <<
181-
"eigenpy warning: you use the deprecated class numpy.matrix without explicily asking for it. "
182-
"The default behaviour will change to numpy.array at next major release.\n"
183-
"- Either call eigenpy.switchToNumpyMatrix() before using eigenpy to suppress this warning\n"
184-
"- or call eigenpy.switchToNumpyArray() and adapt your code accordingly.\n"
185-
"See https://github.com/stack-of-tasks/eigenpy/issues/87 for further details."
186-
<< std::endl;
187-
switchToNumpyMatrix();
188-
}
189178
bp::object m;
190179
if(PyType_IsSubtype(reinterpret_cast<PyTypeObject*>(CurrentNumpyType.ptr()),NumpyMatrixType))
191180
m = NumpyMatrixObject(bp::object(bp::handle<>(pyObj)), bp::object(), copy);
@@ -268,8 +257,8 @@ namespace eigenpy
268257
//NumpyAsMatrixObject = pyModule.attr("asmatrix");
269258
//NumpyAsMatrixType = reinterpret_cast<PyTypeObject*>(NumpyAsMatrixObject.ptr());
270259

271-
CurrentNumpyType = NumpyMatrixObject; // default conversion
272-
getType() = DEFAULT_TYPE;
260+
CurrentNumpyType = NumpyArrayObject; // default conversion
261+
getType() = ARRAY_TYPE;
273262
}
274263

275264
bp::object CurrentNumpyType;

unittest/python/test_geometry.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def isapprox(a,b,epsilon=1e-6):
2727

2828
Rq = q.matrix()
2929
Rr = r.matrix()
30-
assert(isapprox(Rq*Rq.T,np.eye(3)))
30+
assert(isapprox(Rq.dot(Rq.T),np.eye(3)))
3131
assert(isapprox(Rr,Rq))
3232

3333
qR = Quaternion(Rr)
@@ -42,15 +42,15 @@ def isapprox(a,b,epsilon=1e-6):
4242
if verbose: print("As expected, catched exception: ",e)
4343

4444
# --- Angle Vector ------------------------------------------------
45-
r = AngleAxis(.1,np.matrix([1,0,0],np.double).T)
45+
r = AngleAxis(.1,np.array([1,0,0],np.double))
4646
if verbose: print("Rx(.1) = \n\n",r.matrix(),"\n")
4747
assert( isapprox(r.matrix()[2,2],cos(r.angle)))
48-
assert( isapprox(r.axis,np.matrix("1;0;0")) )
48+
assert( isapprox(r.axis,np.array([1.,0,0])) )
4949
assert( isapprox(r.angle,0.1) )
5050
assert(r.isApprox(r))
5151
assert(r.isApprox(r,1e-2))
5252

53-
r.axis = np.matrix([0,1,0],np.double).T
53+
r.axis = np.array([0,1,0],np.double).T
5454
assert( isapprox(r.matrix()[0,0],cos(r.angle)))
5555

5656
ri = r.inverse()

unittest/python/test_matrix.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111

1212
if verbose: print("===> From empty VectorXd to Py")
1313
v = eigenpy.emptyVector()
14-
assert v.shape == (0,1)
14+
assert v.shape == (0,)
1515

1616
if verbose: print("===> From MatrixXd to Py")
1717
M = eigenpy.naturals(3,3,verbose)
18-
Mcheck = np.reshape(np.matrix(range(9),np.double),[3,3])
18+
Mcheck = np.reshape(np.array(range(9),np.double),[3,3])
1919
assert np.array_equal(Mcheck,M)
2020

2121
if verbose: print("===> From Matrix3d to Py")
@@ -24,13 +24,13 @@
2424

2525
if verbose: print("===> From VectorXd to Py")
2626
v = eigenpy.naturalsX(3,verbose)
27-
vcheck = np.matrix([range(3),],np.double).T
27+
vcheck = np.array(range(3),np.double).T
2828
assert np.array_equal(vcheck ,v)
2929

3030
if verbose: print("===> From Py to Eigen::MatrixXd")
3131
if verbose: print("===> From Py to Eigen::MatrixXd")
3232
if verbose: print("===> From Py to Eigen::MatrixXd")
33-
Mref = np.reshape(np.matrix(range(64),np.double),[8,8])
33+
Mref = np.reshape(np.array(range(64),np.double),[8,8])
3434

3535
# Test base function
3636
Mref_from_base = eigenpy.base(Mref)
@@ -125,4 +125,4 @@
125125

126126
vec1x1 = eigenpy.vector1x1(value)
127127
assert(vec1x1.size == 1)
128-
assert(vec1x1[0,0] == value)
128+
assert(vec1x1[0] == value)

0 commit comments

Comments
 (0)