Skip to content

Commit 4a44fac

Browse files
authored
Merge pull request #273 from jcarpent/devel
Export name types
2 parents 6ac2ab1 + a2edcc3 commit 4a44fac

File tree

6 files changed

+139
-32
lines changed

6 files changed

+139
-32
lines changed

include/eigenpy/angle-axis.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ namespace eigenpy
5959
((bp::arg("self"),bp::arg("angle"),bp::arg("axis")),
6060
"Initialize from angle and axis."))
6161
.def(bp::init<Matrix3>
62-
((bp::arg("self"),bp::arg("rotation matrix")),
62+
((bp::arg("self"),bp::arg("R")),
6363
"Initialize from a rotation matrix"))
6464
.def(bp::init<Quaternion>((bp::arg("self"),bp::arg("quaternion")),
6565
"Initialize from a quaternion."))
@@ -84,9 +84,9 @@ namespace eigenpy
8484
"Sets *this from a 3x3 rotation matrix",
8585
bp::return_self<>())
8686
.def("toRotationMatrix",
87-
// bp::arg("self"),
8887
&AngleAxis::toRotationMatrix,
89-
"Constructs and returns an equivalent 3x3 rotation matrix.")
88+
// bp::arg("self"),
89+
"Constructs and returns an equivalent rotation matrix.")
9090
.def("matrix",&AngleAxis::matrix,
9191
bp::arg("self"),
9292
"Returns an equivalent rotation matrix.")

include/eigenpy/eigen-from-python.hpp

Lines changed: 68 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright (c) 2014-2020 CNRS INRIA
2+
// Copyright (c) 2014-2022 CNRS INRIA
33
//
44

55
#ifndef __eigenpy_eigen_from_python_hpp__
@@ -12,6 +12,36 @@
1212

1313
#include <boost/python/converter/rvalue_from_python_data.hpp>
1414

15+
namespace eigenpy
16+
{
17+
18+
template<typename C>
19+
struct expected_pytype_for_arg {};
20+
21+
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
22+
struct expected_pytype_for_arg<Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
23+
{
24+
static PyTypeObject const *get_pytype()
25+
{
26+
PyTypeObject const * py_type = eigenpy::getPyArrayType();
27+
return py_type;
28+
}
29+
};
30+
31+
}
32+
33+
namespace boost {
34+
namespace python {
35+
namespace converter {
36+
37+
template<typename Scalar, int Rows, int Cols, int Options, int MaxRows, int MaxCols>
38+
struct expected_pytype_for_arg<Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
39+
: eigenpy::expected_pytype_for_arg<Eigen::Matrix< Scalar, Rows, Cols, Options, MaxRows, MaxCols> >
40+
{
41+
};
42+
43+
}}}
44+
1545
namespace eigenpy
1646
{
1747
namespace details
@@ -427,7 +457,12 @@ namespace eigenpy
427457
{
428458
bp::converter::registry::push_back
429459
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
430-
&EigenFromPy::construct,bp::type_id<MatType>());
460+
&EigenFromPy::construct,
461+
bp::type_id<MatType>()
462+
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
463+
,&eigenpy::expected_pytype_for_arg<MatType>::get_pytype
464+
#endif
465+
);
431466
}
432467

433468
template<typename MatType>
@@ -453,7 +488,7 @@ namespace eigenpy
453488
// Add conversion to Eigen::Ref<MatType>
454489
typedef Eigen::Ref<MatType> RefType;
455490
EigenFromPy<RefType>::registration();
456-
491+
457492
// Add conversion to Eigen::Ref<MatType>
458493
typedef const Eigen::Ref<const MatType> ConstRefType;
459494
EigenFromPy<ConstRefType>::registration();
@@ -471,7 +506,12 @@ namespace eigenpy
471506
{
472507
bp::converter::registry::push_back
473508
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
474-
&EigenFromPy::construct,bp::type_id<Base>());
509+
&EigenFromPy::construct,
510+
bp::type_id<Base>()
511+
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
512+
,&eigenpy::expected_pytype_for_arg<MatType>::get_pytype
513+
#endif
514+
);
475515
}
476516
};
477517

@@ -485,7 +525,12 @@ namespace eigenpy
485525
{
486526
bp::converter::registry::push_back
487527
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
488-
&EigenFromPy::construct,bp::type_id<Base>());
528+
&EigenFromPy::construct,
529+
bp::type_id<Base>()
530+
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
531+
,&eigenpy::expected_pytype_for_arg<MatType>::get_pytype
532+
#endif
533+
);
489534
}
490535
};
491536

@@ -499,7 +544,12 @@ namespace eigenpy
499544
{
500545
bp::converter::registry::push_back
501546
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
502-
&EigenFromPy::construct,bp::type_id<Base>());
547+
&EigenFromPy::construct,
548+
bp::type_id<Base>()
549+
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
550+
,&eigenpy::expected_pytype_for_arg<MatType>::get_pytype
551+
#endif
552+
);
503553
}
504554
};
505555

@@ -526,7 +576,12 @@ namespace eigenpy
526576
{
527577
bp::converter::registry::push_back
528578
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
529-
&eigen_from_py_construct<RefType>,bp::type_id<RefType>());
579+
&eigen_from_py_construct<RefType>,
580+
bp::type_id<RefType>()
581+
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
582+
,&eigenpy::expected_pytype_for_arg<MatType>::get_pytype
583+
#endif
584+
);
530585
}
531586
};
532587

@@ -546,7 +601,12 @@ namespace eigenpy
546601
{
547602
bp::converter::registry::push_back
548603
(reinterpret_cast<void *(*)(_object *)>(&EigenFromPy::convertible),
549-
&eigen_from_py_construct<ConstRefType>,bp::type_id<ConstRefType>());
604+
&eigen_from_py_construct<ConstRefType>,
605+
bp::type_id<ConstRefType>()
606+
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
607+
,&eigenpy::expected_pytype_for_arg<MatType>::get_pytype
608+
#endif
609+
);
550610
}
551611
};
552612
#endif

include/eigenpy/eigen-to-python.hpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ namespace eigenpy
8080
// Create an instance (either np.array or np.matrix)
8181
return NumpyType::make(pyArray).ptr();
8282
}
83+
84+
static PyTypeObject const *get_pytype()
85+
{
86+
return getPyArrayType();
87+
}
8388
};
8489

8590
template<typename MatType, int Options, typename Stride, typename _Scalar>
@@ -110,14 +115,19 @@ namespace eigenpy
110115
// Create an instance (either np.array or np.matrix)
111116
return NumpyType::make(pyArray).ptr();
112117
}
118+
119+
static PyTypeObject const *get_pytype()
120+
{
121+
return getPyArrayType();
122+
}
113123
};
114124

115125
template<typename MatType>
116126
struct EigenToPyConverter
117127
{
118128
static void registration()
119129
{
120-
bp::to_python_converter<MatType,EigenToPy<MatType> >();
130+
bp::to_python_converter<MatType,EigenToPy<MatType>, true>();
121131
}
122132
};
123133
}

include/eigenpy/numpy.hpp

Lines changed: 54 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ namespace eigenpy
6262

6363
}
6464

65-
#if defined _WIN32 || defined __CYGWIN__
65+
6666
namespace eigenpy
6767
{
68+
#if defined _WIN32 || defined __CYGWIN__
6869
EIGENPY_DLLAPI bool call_PyArray_Check(PyObject *);
6970

7071
EIGENPY_DLLAPI PyObject* call_PyArray_SimpleNew(int nd, npy_intp * shape, int np_type);
@@ -86,19 +87,59 @@ namespace eigenpy
8687
EIGENPY_DLLAPI PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject *arr);
8788

8889
EIGENPY_DLLAPI int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc);
89-
}
9090
#else
91-
#define call_PyArray_Check(py_obj) PyArray_Check(py_obj)
92-
#define call_PyArray_SimpleNew PyArray_SimpleNew
93-
#define call_PyArray_New(py_type_ptr,nd,shape,np_type,data_ptr,options) \
94-
PyArray_New(py_type_ptr,nd,shape,np_type,NULL,data_ptr,0,options,NULL)
95-
#define getPyArrayType() &PyArray_Type
96-
#define call_PyArray_DescrFromType(typenum) PyArray_DescrFromType(typenum)
97-
#define call_PyArray_MinScalarType(py_arr) PyArray_MinScalarType(py_arr)
98-
#define call_PyArray_InitArrFuncs(funcs) PyArray_InitArrFuncs(funcs)
99-
#define call_PyArray_RegisterDataType(dtype) PyArray_RegisterDataType(dtype)
100-
#define call_PyArray_RegisterCanCast(descr,totype,scalar) PyArray_RegisterCanCast(descr,totype,scalar)
101-
#define call_PyArray_RegisterCastFunc(descr,totype,castfunc) PyArray_RegisterCastFunc(descr,totype,castfunc)
91+
inline bool call_PyArray_Check(PyObject * py_obj)
92+
{
93+
return PyArray_Check(py_obj);
94+
}
95+
96+
inline PyObject* call_PyArray_SimpleNew(int nd, npy_intp * shape, int np_type)
97+
{
98+
return PyArray_SimpleNew(nd,shape,np_type);
99+
}
100+
101+
inline PyObject* call_PyArray_New(PyTypeObject * py_type_ptr, int nd, npy_intp * shape, int np_type, void * data_ptr, int options)
102+
{
103+
return PyArray_New(py_type_ptr,nd,shape,np_type,NULL,data_ptr,0,options,NULL);
104+
}
105+
106+
inline int call_PyArray_ObjectType(PyObject * obj, int val)
107+
{
108+
return PyArray_ObjectType(obj,val);
109+
}
110+
111+
inline PyTypeObject * getPyArrayType() { return &PyArray_Type; }
112+
113+
inline PyArray_Descr * call_PyArray_DescrFromType(int typenum)
114+
{
115+
return PyArray_DescrFromType(typenum);
116+
}
117+
118+
inline void call_PyArray_InitArrFuncs(PyArray_ArrFuncs * funcs)
119+
{
120+
PyArray_InitArrFuncs(funcs);
121+
}
122+
123+
inline int call_PyArray_RegisterDataType(PyArray_Descr * dtype)
124+
{
125+
return PyArray_RegisterDataType(dtype);
126+
}
127+
128+
inline PyArray_Descr * call_PyArray_MinScalarType(PyArrayObject * arr)
129+
{
130+
return PyArray_MinScalarType(arr);
131+
}
132+
133+
inline int call_PyArray_RegisterCanCast(PyArray_Descr *descr, int totype, NPY_SCALARKIND scalar)
134+
{
135+
return PyArray_RegisterCanCast(descr,totype,scalar);
136+
}
137+
138+
inline int call_PyArray_RegisterCastFunc(PyArray_Descr* descr, int totype, PyArray_VectorUnaryFunc* castfunc)
139+
{
140+
return PyArray_RegisterCastFunc(descr,totype,castfunc);
141+
}
102142
#endif
143+
}
103144

104145
#endif // ifndef __eigenpy_numpy_hpp__

include/eigenpy/quaternion.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ namespace eigenpy
171171
"Returns an equivalent 3x3 rotation matrix. Similar to toRotationMatrix.")
172172
.def("toRotationMatrix",&Quaternion::toRotationMatrix,
173173
// bp::arg("self"), // Bug in Boost.Python
174-
"Returns an equivalent 3x3 rotation matrix.")
174+
"Returns an equivalent rotation matrix.")
175175

176176
.def("setFromTwoVectors",&setFromTwoVectors,((bp::arg("self"),bp::arg("a"),bp::arg("b"))),
177177
"Set *this to be the quaternion which transforms a into b through a rotation."

python/main.cpp

Lines changed: 2 additions & 6 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-2022, INRIA
44
*/
55

66
#include "eigenpy/eigenpy.hpp"
@@ -48,12 +48,8 @@ BOOST_PYTHON_MODULE(eigenpy_pywrap)
4848
using namespace Eigen;
4949

5050
bp::def("is_approx",(bool (*)(const Eigen::MatrixBase<MatrixXd> &, const Eigen::MatrixBase<MatrixXd> &, const double &))&is_approx<MatrixXd,MatrixXd>,
51-
bp::args("A","B","prec"),
51+
(bp::arg("A"),bp::arg("B"),bp::arg("prec") = 1e-12),
5252
"Returns True if A is approximately equal to B, within the precision determined by prec.");
53-
54-
bp::def("is_approx",(bool (*)(const Eigen::MatrixBase<MatrixXd> &, const Eigen::MatrixBase<MatrixXd> &))&is_approx<MatrixXd,MatrixXd>,
55-
bp::args("A","B"),
56-
"Returns True if A is approximately equal to B.");
5753
}
5854

5955
exposeDecompositions();

0 commit comments

Comments
 (0)