Skip to content

Commit 1c58c53

Browse files
committed
core: add arg type info
1 parent 77f0505 commit 1c58c53

File tree

1 file changed

+68
-8
lines changed

1 file changed

+68
-8
lines changed

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

0 commit comments

Comments
 (0)