Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Stack Of Tasks
eigenpy
Commits
ca5c9252
Verified
Commit
ca5c9252
authored
Dec 28, 2020
by
Justin Carpentier
Browse files
core: allows template specialization of EigenFromPy
parent
8bbaa052
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/eigenpy/eigen-from-python.hpp
View file @
ca5c9252
...
...
@@ -275,13 +275,13 @@ namespace eigenpy
memory
->
convertible
=
storage
->
storage
.
bytes
;
}
template
<
typename
MatType
>
template
<
typename
MatType
,
typename
_Scalar
>
struct
EigenFromPy
{
typedef
typename
MatType
::
Scalar
Scalar
;
/// \brief Determine if pyObj can be converted into a MatType object
static
void
*
convertible
(
Py
Array
Object
*
py
Array
);
static
void
*
convertible
(
PyObject
*
py
Obj
);
/// \brief Allocate memory and copy pyObj in the new storage
static
void
construct
(
PyObject
*
pyObj
,
...
...
@@ -290,12 +290,14 @@ namespace eigenpy
static
void
registration
();
};
template
<
typename
MatType
>
void
*
EigenFromPy
<
MatType
>::
convertible
(
Py
Array
Object
*
py
Array
)
template
<
typename
MatType
,
typename
_Scalar
>
void
*
EigenFromPy
<
MatType
,
_Scalar
>::
convertible
(
PyObject
*
py
Obj
)
{
if
(
!
call_PyArray_Check
(
reinterpret_cast
<
PyObject
*>
(
py
Array
)))
if
(
!
call_PyArray_Check
(
reinterpret_cast
<
PyObject
*>
(
py
Obj
)))
return
0
;
PyArrayObject
*
pyArray
=
reinterpret_cast
<
PyArrayObject
*>
(
pyObj
);
if
(
!
np_type_is_convertible_into_scalar
<
Scalar
>
(
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
)))
return
0
;
...
...
@@ -403,15 +405,15 @@ namespace eigenpy
return
pyArray
;
}
template
<
typename
MatType
>
void
EigenFromPy
<
MatType
>::
construct
(
PyObject
*
pyObj
,
bp
::
converter
::
rvalue_from_python_stage1_data
*
memory
)
template
<
typename
MatType
,
typename
_Scalar
>
void
EigenFromPy
<
MatType
,
_Scalar
>::
construct
(
PyObject
*
pyObj
,
bp
::
converter
::
rvalue_from_python_stage1_data
*
memory
)
{
eigen_from_py_construct
<
MatType
>
(
pyObj
,
memory
);
}
template
<
typename
MatType
>
void
EigenFromPy
<
MatType
>::
registration
()
template
<
typename
MatType
,
typename
_Scalar
>
void
EigenFromPy
<
MatType
,
_Scalar
>::
registration
()
{
bp
::
converter
::
registry
::
push_back
(
reinterpret_cast
<
void
*
(
*
)(
_object
*
)
>
(
&
EigenFromPy
::
convertible
),
...
...
@@ -431,7 +433,7 @@ namespace eigenpy
// Add conversion to Eigen::EigenBase<MatType>
typedef
Eigen
::
EigenBase
<
MatType
>
EigenBase
;
EigenFromPy
<
EigenBase
>::
registration
();
EigenFromPy
<
EigenBase
,
typename
MatType
::
Scalar
>::
registration
();
// Add conversion to Eigen::PlainObjectBase<MatType>
typedef
Eigen
::
PlainObjectBase
<
MatType
>
PlainObjectBase
;
...
...
@@ -449,8 +451,8 @@ namespace eigenpy
}
};
template
<
typename
MatType
>
struct
EigenFromPy
<
Eigen
::
MatrixBase
<
MatType
>
>
:
EigenFromPy
<
MatType
>
template
<
typename
MatType
,
typename
_Scalar
>
struct
EigenFromPy
<
Eigen
::
MatrixBase
<
MatType
>
,
_Scalar
>
:
EigenFromPy
<
MatType
>
{
typedef
EigenFromPy
<
MatType
>
EigenFromPyDerived
;
typedef
Eigen
::
MatrixBase
<
MatType
>
Base
;
...
...
@@ -463,8 +465,8 @@ namespace eigenpy
}
};
template
<
typename
MatType
>
struct
EigenFromPy
<
Eigen
::
EigenBase
<
MatType
>
>
:
EigenFromPy
<
MatType
>
template
<
typename
MatType
,
typename
_Scalar
>
struct
EigenFromPy
<
Eigen
::
EigenBase
<
MatType
>
,
_Scalar
>
:
EigenFromPy
<
MatType
>
{
typedef
EigenFromPy
<
MatType
>
EigenFromPyDerived
;
typedef
Eigen
::
EigenBase
<
MatType
>
Base
;
...
...
@@ -477,8 +479,8 @@ namespace eigenpy
}
};
template
<
typename
MatType
>
struct
EigenFromPy
<
Eigen
::
PlainObjectBase
<
MatType
>
>
:
EigenFromPy
<
MatType
>
template
<
typename
MatType
,
typename
_Scalar
>
struct
EigenFromPy
<
Eigen
::
PlainObjectBase
<
MatType
>
,
_Scalar
>
:
EigenFromPy
<
MatType
>
{
typedef
EigenFromPy
<
MatType
>
EigenFromPyDerived
;
typedef
Eigen
::
PlainObjectBase
<
MatType
>
Base
;
...
...
@@ -493,20 +495,21 @@ namespace eigenpy
#if EIGEN_VERSION_AT_LEAST(3,2,0)
template
<
typename
MatType
,
int
Options
,
typename
Stride
>
struct
EigenFromPy
<
Eigen
::
Ref
<
MatType
,
Options
,
Stride
>
>
template
<
typename
MatType
,
int
Options
,
typename
Stride
,
typename
_Scalar
>
struct
EigenFromPy
<
Eigen
::
Ref
<
MatType
,
Options
,
Stride
>
,
_Scalar
>
{
typedef
Eigen
::
Ref
<
MatType
,
Options
,
Stride
>
RefType
;
typedef
typename
MatType
::
Scalar
Scalar
;
/// \brief Determine if pyObj can be converted into a MatType object
static
void
*
convertible
(
Py
Array
Object
*
py
Array
)
static
void
*
convertible
(
PyObject
*
py
Obj
)
{
if
(
!
call_PyArray_Check
(
reinterpret_cast
<
PyObject
*>
(
pyArray
)
))
if
(
!
call_PyArray_Check
(
pyObj
))
return
0
;
PyArrayObject
*
pyArray
=
reinterpret_cast
<
PyArrayObject
*>
(
pyObj
);
if
(
!
PyArray_ISWRITEABLE
(
pyArray
))
return
0
;
return
EigenFromPy
<
MatType
>::
convertible
(
py
Array
);
return
EigenFromPy
<
MatType
>::
convertible
(
py
Obj
);
}
static
void
registration
()
...
...
@@ -517,16 +520,16 @@ namespace eigenpy
}
};
template
<
typename
MatType
,
int
Options
,
typename
Stride
>
struct
EigenFromPy
<
const
Eigen
::
Ref
<
const
MatType
,
Options
,
Stride
>
>
template
<
typename
MatType
,
int
Options
,
typename
Stride
,
typename
_Scalar
>
struct
EigenFromPy
<
const
Eigen
::
Ref
<
const
MatType
,
Options
,
Stride
>
,
_Scalar
>
{
typedef
const
Eigen
::
Ref
<
const
MatType
,
Options
,
Stride
>
ConstRefType
;
typedef
typename
MatType
::
Scalar
Scalar
;
/// \brief Determine if pyObj can be converted into a MatType object
static
void
*
convertible
(
Py
Array
Object
*
py
Array
)
static
void
*
convertible
(
PyObject
*
py
Obj
)
{
return
EigenFromPy
<
MatType
>::
convertible
(
py
Array
);
return
EigenFromPy
<
MatType
>::
convertible
(
py
Obj
);
}
static
void
registration
()
...
...
include/eigenpy/fwd.hpp
View file @
ca5c9252
...
...
@@ -28,8 +28,8 @@
namespace
eigenpy
{
template
<
typename
MatType
>
struct
EigenFromPy
;
template
<
typename
MatType
,
typename
Scalar
=
typename
boost
::
remove_reference
<
MatType
>
::
type
::
Scalar
>
struct
EigenToPy
;
template
<
typename
MatType
,
typename
Scalar
=
typename
boost
::
remove_reference
<
MatType
>
::
type
::
Scalar
>
struct
EigenFromPy
;
}
#endif // ifndef __eigenpy_fwd_hpp__
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment