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
Guilhem Saurel
eigenpy
Commits
dd5e3688
Commit
dd5e3688
authored
2 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
core: simplify code by removing redundant portions
parent
061874ad
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
include/eigenpy/eigen-allocator.hpp
+24
-95
24 additions, 95 deletions
include/eigenpy/eigen-allocator.hpp
with
24 additions
and
95 deletions
include/eigenpy/eigen-allocator.hpp
+
24
−
95
View file @
dd5e3688
//
// Copyright (c) 2014-202
0
CNRS INRIA
// Copyright (c) 2014-202
3
CNRS INRIA
//
#ifndef __eigenpy_eigen_allocator_hpp__
...
...
@@ -115,8 +115,11 @@ struct cast_matrix_or_array<Scalar, NewScalar, false> {
mat, NumpyMap<MatType, NewScalar>::map( \
pyArray, details::check_swap(pyArray, mat)))
template
<
typename
EigenType
>
struct
EigenAllocator
;
template
<
typename
MatType
>
struct
E
igen
A
llocator
{
struct
e
igen
_a
llocator
_impl
{
typedef
MatType
Type
;
typedef
typename
MatType
::
Scalar
Scalar
;
...
...
@@ -130,8 +133,17 @@ struct EigenAllocator {
Type
*
mat_ptr
=
details
::
init_matrix_or_array
<
Type
>::
run
(
pyArray
,
raw_ptr
);
Type
&
mat
=
*
mat_ptr
;
copy
(
pyArray
,
mat
);
}
/// \brief Copy Python array into the input matrix mat.
template
<
typename
MatrixDerived
>
static
void
copy
(
PyArrayObject
*
pyArray
,
const
Eigen
::
MatrixBase
<
MatrixDerived
>
&
mat_
)
{
MatrixDerived
&
mat
=
mat_
.
const_cast_derived
();
const
int
pyArray_type_code
=
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
);
const
int
Scalar_type_code
=
Register
::
getTypeCode
<
Scalar
>
();
if
(
pyArray_type_code
==
Scalar_type_code
)
{
mat
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
,
details
::
check_swap
(
pyArray
,
mat
));
// avoid useless cast
...
...
@@ -185,13 +197,10 @@ struct EigenAllocator {
const
int
pyArray_type_code
=
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
);
const
int
Scalar_type_code
=
Register
::
getTypeCode
<
Scalar
>
();
typedef
typename
NumpyMap
<
MatType
,
Scalar
>::
EigenMap
MapType
;
if
(
pyArray_type_code
==
Scalar_type_code
)
// no cast needed
{
MapType
map_pyArray
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
,
details
::
check_swap
(
pyArray
,
mat
));
map_pyArray
=
mat
;
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
,
details
::
check_swap
(
pyArray
,
mat
))
=
mat
;
return
;
}
...
...
@@ -253,7 +262,7 @@ inline bool is_arr_layout_compatible_with_mat_type(PyArrayObject *pyArray) {
}
template
<
typename
MatType
,
int
Options
,
typename
Stride
>
struct
E
igen
A
llocator
<
Eigen
::
Ref
<
MatType
,
Options
,
Stride
>
>
{
struct
e
igen
_a
llocator
_impl
<
Eigen
::
Ref
<
MatType
,
Options
,
Stride
>
>
{
typedef
Eigen
::
Ref
<
MatType
,
Options
,
Stride
>
RefType
;
typedef
typename
MatType
::
Scalar
Scalar
;
...
...
@@ -296,49 +305,7 @@ struct EigenAllocator<Eigen::Ref<MatType, Options, Stride> > {
new
(
raw_ptr
)
StorageType
(
mat_ref
,
pyArray
,
mat_ptr
);
RefType
&
mat
=
*
reinterpret_cast
<
RefType
*>
(
raw_ptr
);
if
(
pyArray_type_code
==
Scalar_type_code
)
{
mat
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
,
details
::
check_swap
(
pyArray
,
mat
));
// avoid useless cast
return
;
}
switch
(
pyArray_type_code
)
{
case
NPY_INT
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
int
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_LONG
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
long
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_FLOAT
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
float
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_CFLOAT
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
std
::
complex
<
float
>
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_DOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
double
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_CDOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
std
::
complex
<
double
>
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_LONGDOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
long
double
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_CLONGDOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
std
::
complex
<
long
double
>
,
Scalar
,
pyArray
,
mat
);
break
;
default:
throw
Exception
(
"You asked for a conversion which is not implemented."
);
}
EigenAllocator
<
MatType
>::
copy
(
pyArray
,
mat
);
}
else
{
assert
(
pyArray_type_code
==
Scalar_type_code
);
typename
NumpyMap
<
MatType
,
Scalar
,
Options
,
NumpyMapStride
>::
EigenMap
...
...
@@ -355,7 +322,7 @@ struct EigenAllocator<Eigen::Ref<MatType, Options, Stride> > {
};
template
<
typename
MatType
,
int
Options
,
typename
Stride
>
struct
E
igen
A
llocator
<
const
Eigen
::
Ref
<
const
MatType
,
Options
,
Stride
>
>
{
struct
e
igen
_a
llocator
_impl
<
const
Eigen
::
Ref
<
const
MatType
,
Options
,
Stride
>
>
{
typedef
const
Eigen
::
Ref
<
const
MatType
,
Options
,
Stride
>
RefType
;
typedef
typename
MatType
::
Scalar
Scalar
;
...
...
@@ -399,49 +366,7 @@ struct EigenAllocator<const Eigen::Ref<const MatType, Options, Stride> > {
new
(
raw_ptr
)
StorageType
(
mat_ref
,
pyArray
,
mat_ptr
);
MatType
&
mat
=
*
mat_ptr
;
if
(
pyArray_type_code
==
Scalar_type_code
)
{
mat
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
,
details
::
check_swap
(
pyArray
,
mat
));
// avoid useless cast
return
;
}
switch
(
pyArray_type_code
)
{
case
NPY_INT
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
int
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_LONG
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
long
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_FLOAT
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
float
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_CFLOAT
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
std
::
complex
<
float
>
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_DOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
double
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_CDOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
std
::
complex
<
double
>
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_LONGDOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
long
double
,
Scalar
,
pyArray
,
mat
);
break
;
case
NPY_CLONGDOUBLE
:
EIGENPY_CAST_FROM_PYARRAY_TO_EIGEN_MATRIX
(
MatType
,
std
::
complex
<
long
double
>
,
Scalar
,
pyArray
,
mat
);
break
;
default:
throw
Exception
(
"You asked for a conversion which is not implemented."
);
}
EigenAllocator
<
MatType
>::
copy
(
pyArray
,
mat
);
}
else
{
assert
(
pyArray_type_code
==
Scalar_type_code
);
typename
NumpyMap
<
MatType
,
Scalar
,
Options
,
NumpyMapStride
>::
EigenMap
...
...
@@ -457,6 +382,10 @@ struct EigenAllocator<const Eigen::Ref<const MatType, Options, Stride> > {
}
};
#endif
template
<
typename
EigenType
>
struct
EigenAllocator
:
eigen_allocator_impl
<
EigenType
>
{};
}
// namespace eigenpy
#endif // __eigenpy_eigen_allocator_hpp__
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