Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
eigenpy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stack Of Tasks
eigenpy
Commits
f2053d74
Commit
f2053d74
authored
2 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
core: start reworking EigenFromPyConverter in preparation for Eigen::Tensor
parent
83a4411c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/eigenpy/eigen-from-python.hpp
+59
-17
59 additions, 17 deletions
include/eigenpy/eigen-from-python.hpp
with
59 additions
and
17 deletions
include/eigenpy/eigen-from-python.hpp
+
59
−
17
View file @
f2053d74
...
@@ -12,18 +12,27 @@
...
@@ -12,18 +12,27 @@
namespace
eigenpy
{
namespace
eigenpy
{
template
<
typename
C
>
template
<
typename
EigenType
,
typename
BaseType
=
typename
get_eigen_base_type
<
EigenType
>
::
type
>
struct
expected_pytype_for_arg
{};
struct
expected_pytype_for_arg
{};
template
<
typename
Scalar
,
int
Rows
,
int
Cols
,
int
Options
,
int
MaxRows
,
template
<
typename
MatType
>
int
MaxCols
>
struct
expected_pytype_for_arg
<
MatType
,
Eigen
::
MatrixBase
<
MatType
>
>
{
struct
expected_pytype_for_arg
<
static
PyTypeObject
const
*
get_pytype
()
{
Eigen
::
Matrix
<
Scalar
,
Rows
,
Cols
,
Options
,
MaxRows
,
MaxCols
>
>
{
PyTypeObject
const
*
py_type
=
eigenpy
::
getPyArrayType
();
return
py_type
;
}
};
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
template
<
typename
TensorType
>
struct
expected_pytype_for_arg
<
TensorType
,
Eigen
::
TensorBase
<
TensorType
>
>
{
static
PyTypeObject
const
*
get_pytype
()
{
static
PyTypeObject
const
*
get_pytype
()
{
PyTypeObject
const
*
py_type
=
eigenpy
::
getPyArrayType
();
PyTypeObject
const
*
py_type
=
eigenpy
::
getPyArrayType
();
return
py_type
;
return
py_type
;
}
}
};
};
#endif
}
// namespace eigenpy
}
// namespace eigenpy
...
@@ -38,6 +47,13 @@ struct expected_pytype_for_arg<
...
@@ -38,6 +47,13 @@ struct expected_pytype_for_arg<
:
eigenpy
::
expected_pytype_for_arg
<
:
eigenpy
::
expected_pytype_for_arg
<
Eigen
::
Matrix
<
Scalar
,
Rows
,
Cols
,
Options
,
MaxRows
,
MaxCols
>
>
{};
Eigen
::
Matrix
<
Scalar
,
Rows
,
Cols
,
Options
,
MaxRows
,
MaxCols
>
>
{};
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
template
<
typename
Scalar
,
int
Rank
,
int
Options
,
typename
IndexType
>
struct
expected_pytype_for_arg
<
Eigen
::
Tensor
<
Scalar
,
Rank
,
Options
,
IndexType
>
>
:
eigenpy
::
expected_pytype_for_arg
<
Eigen
::
Tensor
<
Scalar
,
Rank
,
Options
,
IndexType
>
>
{};
#endif
}
// namespace converter
}
// namespace converter
}
// namespace python
}
// namespace python
}
// namespace boost
}
// namespace boost
...
@@ -269,8 +285,23 @@ void eigen_from_py_construct(
...
@@ -269,8 +285,23 @@ void eigen_from_py_construct(
memory
->
convertible
=
storage
->
storage
.
bytes
;
memory
->
convertible
=
storage
->
storage
.
bytes
;
}
}
template
<
typename
MatType
,
typename
_Scalar
>
template
<
typename
EigenType
,
struct
EigenFromPy
{
typename
BaseType
=
typename
get_eigen_base_type
<
EigenType
>
::
type
>
struct
eigen_from_py_impl
{
typedef
typename
EigenType
::
Scalar
Scalar
;
/// \brief Determine if pyObj can be converted into a MatType object
static
void
*
convertible
(
PyObject
*
pyObj
);
/// \brief Allocate memory and copy pyObj in the new storage
static
void
construct
(
PyObject
*
pyObj
,
bp
::
converter
::
rvalue_from_python_stage1_data
*
memory
);
static
void
registration
();
};
template
<
typename
MatType
>
struct
eigen_from_py_impl
<
MatType
,
Eigen
::
MatrixBase
<
MatType
>
>
{
typedef
typename
MatType
::
Scalar
Scalar
;
typedef
typename
MatType
::
Scalar
Scalar
;
/// \brief Determine if pyObj can be converted into a MatType object
/// \brief Determine if pyObj can be converted into a MatType object
...
@@ -283,8 +314,12 @@ struct EigenFromPy {
...
@@ -283,8 +314,12 @@ struct EigenFromPy {
static
void
registration
();
static
void
registration
();
};
};
template
<
typename
MatType
,
typename
_Scalar
>
template
<
typename
EigenType
,
typename
_Scalar
>
void
*
EigenFromPy
<
MatType
,
_Scalar
>::
convertible
(
PyObject
*
pyObj
)
{
struct
EigenFromPy
:
eigen_from_py_impl
<
EigenType
>
{};
template
<
typename
MatType
>
void
*
eigen_from_py_impl
<
MatType
,
Eigen
::
MatrixBase
<
MatType
>
>::
convertible
(
PyObject
*
pyObj
)
{
if
(
!
call_PyArray_Check
(
reinterpret_cast
<
PyObject
*>
(
pyObj
)))
return
0
;
if
(
!
call_PyArray_Check
(
reinterpret_cast
<
PyObject
*>
(
pyObj
)))
return
0
;
PyArrayObject
*
pyArray
=
reinterpret_cast
<
PyArrayObject
*>
(
pyObj
);
PyArrayObject
*
pyArray
=
reinterpret_cast
<
PyArrayObject
*>
(
pyObj
);
...
@@ -384,26 +419,33 @@ void *EigenFromPy<MatType, _Scalar>::convertible(PyObject *pyObj) {
...
@@ -384,26 +419,33 @@ void *EigenFromPy<MatType, _Scalar>::convertible(PyObject *pyObj) {
return
pyArray
;
return
pyArray
;
}
}
template
<
typename
MatType
,
typename
_Scalar
>
template
<
typename
MatType
>
void
E
igen
F
rom
Py
<
MatType
,
_Scalar
>::
construct
(
void
e
igen
_f
rom
_py_impl
<
MatType
,
Eigen
::
MatrixBase
<
MatType
>
>::
construct
(
PyObject
*
pyObj
,
bp
::
converter
::
rvalue_from_python_stage1_data
*
memory
)
{
PyObject
*
pyObj
,
bp
::
converter
::
rvalue_from_python_stage1_data
*
memory
)
{
eigen_from_py_construct
<
MatType
>
(
pyObj
,
memory
);
eigen_from_py_construct
<
MatType
>
(
pyObj
,
memory
);
}
}
template
<
typename
MatType
,
typename
_Scalar
>
template
<
typename
MatType
>
void
E
igen
F
rom
Py
<
MatType
,
_Scalar
>::
registration
()
{
void
e
igen
_f
rom
_py_impl
<
MatType
,
Eigen
::
MatrixBase
<
MatType
>
>::
registration
()
{
bp
::
converter
::
registry
::
push_back
(
bp
::
converter
::
registry
::
push_back
(
reinterpret_cast
<
void
*
(
*
)(
_object
*
)
>
(
&
E
igen
F
rom
Py
::
convertible
),
reinterpret_cast
<
void
*
(
*
)(
_object
*
)
>
(
&
e
igen
_f
rom
_py_impl
::
convertible
),
&
E
igen
F
rom
Py
::
construct
,
bp
::
type_id
<
MatType
>
()
&
e
igen
_f
rom
_py_impl
::
construct
,
bp
::
type_id
<
MatType
>
()
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
#ifndef BOOST_PYTHON_NO_PY_SIGNATURES
,
,
&
eigenpy
::
expected_pytype_for_arg
<
MatType
>::
get_pytype
&
eigenpy
::
expected_pytype_for_arg
<
MatType
>::
get_pytype
#endif
#endif
);
);
}
}
template
<
typename
EigenType
,
typename
BaseType
=
typename
get_eigen_base_type
<
EigenType
>
::
type
>
struct
eigen_from_py_converter_impl
;
template
<
typename
EigenType
>
struct
EigenFromPyConverter
:
eigen_from_py_converter_impl
<
EigenType
>
{};
template
<
typename
MatType
>
template
<
typename
MatType
>
struct
E
igen
F
rom
PyC
onverter
{
struct
e
igen
_f
rom
_py_c
onverter
_impl
<
MatType
,
Eigen
::
MatrixBase
<
MatType
>
>
{
static
void
registration
()
{
static
void
registration
()
{
EigenFromPy
<
MatType
>::
registration
();
EigenFromPy
<
MatType
>::
registration
();
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment