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
c7445082
Commit
c7445082
authored
2 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
core: rework NumpyMap in preparation for Eigen::Tensor
parent
252a0190
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/numpy-map.hpp
+55
-31
55 additions, 31 deletions
include/eigenpy/numpy-map.hpp
with
55 additions
and
31 deletions
include/eigenpy/numpy-map.hpp
+
55
−
31
View file @
c7445082
/*
* Copyright 2014-2019, CNRS
* Copyright 2018-202
0
, INRIA
* Copyright 2018-202
3
, INRIA
*/
#ifndef __eigenpy_numpy_map_hpp__
...
...
@@ -11,42 +11,40 @@
#include
"eigenpy/stride.hpp"
namespace
eigenpy
{
template
<
typename
MatType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
,
bool
IsVector
=
MatType
::
IsVectorAtCompileTime
>
struct
N
umpy
MapTraits
{}
;
struct
n
umpy
_map_impl_matrix
;
/* Wrap a numpy::array with an Eigen::Map. No memory copy. */
template
<
typename
MatType
,
typename
InputScalar
,
int
AlignmentValue
=
EIGENPY_NO_ALIGNMENT_VALUE
,
typename
Stride
=
typename
StrideType
<
MatType
>
::
type
>
struct
NumpyMap
{
typedef
NumpyMapTraits
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
>
Impl
;
typedef
typename
Impl
::
EigenMap
EigenMap
;
template
<
typename
EigenType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
,
typename
BaseType
=
typename
get_eigen_base_type
<
EigenType
>
::
type
>
struct
numpy_map_impl
;
static
EigenMap
map
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
=
false
);
};
template
<
typename
MatType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
>
struct
numpy_map_impl
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
,
Eigen
::
MatrixBase
<
MatType
>
>
:
numpy_map_impl_matrix
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
>
{};
}
// namespace eigenpy
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
template
<
typename
TensorType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
>
struct
numpy_map_impl_tensor
;
/* --- DETAILS
* ------------------------------------------------------------------ */
/* --- DETAILS
* ------------------------------------------------------------------ */
/* --- DETAILS
* ------------------------------------------------------------------ */
#endif
namespace
eigenpy
{
template
<
typename
MatType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
>
struct
NumpyMapTraits
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
,
false
>
{
struct
numpy_map_impl_matrix
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
,
false
>
{
typedef
Eigen
::
Matrix
<
InputScalar
,
MatType
::
RowsAtCompileTime
,
MatType
::
ColsAtCompileTime
,
MatType
::
Options
>
EquivalentInputMatrixType
;
typedef
Eigen
::
Map
<
EquivalentInputMatrixType
,
AlignmentValue
,
Stride
>
EigenMap
;
static
EigenMap
mapImpl
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
=
false
)
{
static
EigenMap
map
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
=
false
)
{
enum
{
OuterStrideAtCompileTime
=
Stride
::
OuterStrideAtCompileTime
,
InnerStrideAtCompileTime
=
Stride
::
InnerStrideAtCompileTime
,
...
...
@@ -135,15 +133,15 @@ struct NumpyMapTraits<MatType, InputScalar, AlignmentValue, Stride, false> {
template
<
typename
MatType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
>
struct
NumpyMapTraits
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
,
true
>
{
struct
numpy_map_impl_matrix
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
,
true
>
{
typedef
Eigen
::
Matrix
<
InputScalar
,
MatType
::
RowsAtCompileTime
,
MatType
::
ColsAtCompileTime
,
MatType
::
Options
>
EquivalentInputMatrixType
;
typedef
Eigen
::
Map
<
EquivalentInputMatrixType
,
AlignmentValue
,
Stride
>
EigenMap
;
static
EigenMap
mapImpl
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
=
false
)
{
static
EigenMap
map
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
=
false
)
{
EIGENPY_UNUSED_VARIABLE
(
swap_dimensions
);
assert
(
PyArray_NDIM
(
pyArray
)
<=
2
);
...
...
@@ -176,13 +174,39 @@ struct NumpyMapTraits<MatType, InputScalar, AlignmentValue, Stride, true> {
}
};
template
<
typename
MatType
,
typename
InputScalar
,
int
AlignmentValue
,
#ifdef EIGENPY_WITH_TENSOR_SUPPORT
template
<
typename
TensorType
,
typename
InputScalar
,
int
AlignmentValue
,
typename
Stride
>
typename
NumpyMap
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
>::
EigenMap
NumpyMap
<
MatType
,
InputScalar
,
AlignmentValue
,
Stride
>::
map
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
)
{
return
Impl
::
mapImpl
(
pyArray
,
swap_dimensions
);
}
struct
numpy_map_impl
<
TensorType
,
InputScalar
,
AlignmentValue
,
Stride
,
Eigen
::
TensorBase
<
TensorType
>
>
{
typedef
TensorType
Tensor
;
typedef
typename
Eigen
::
internal
::
traits
<
TensorType
>::
Index
Index
;
static
const
Index
NumIndices
=
TensorType
::
NumIndices
;
typedef
Eigen
::
Tensor
<
InputScalar
,
NumIndices
,
Tensor
::
Options
,
Index
>
EquivalentInputTensorType
;
typedef
typename
EquivalentInputTensorType
::
Dimensions
Dimensions
;
typedef
Eigen
::
TensorMap
<
EquivalentInputTensorType
,
Tensor
::
Options
>
EigenMap
;
static
EigenMap
map
(
PyArrayObject
*
pyArray
,
bool
swap_dimensions
=
false
)
{
assert
(
PyArray_NDIM
(
pyArray
)
==
NumIndices
||
NumIndices
==
Eigen
::
Dynamic
);
Eigen
::
DSizes
<
Index
,
NumIndices
>
dimensions
(
PyArray_NDIM
(
pyArray
));
for
(
int
k
=
0
;
k
<
PyArray_NDIM
(
pyArray
);
++
k
)
dimensions
[
k
]
=
PyArray_DIMS
(
pyArray
)[
k
];
InputScalar
*
pyData
=
reinterpret_cast
<
InputScalar
*>
(
PyArray_DATA
(
pyArray
));
return
EigenMap
(
pyData
,
dimensions
);
}
};
#endif
/* Wrap a numpy::array with an Eigen::Map. No memory copy. */
template
<
typename
EigenType
,
typename
InputScalar
,
int
AlignmentValue
=
EIGENPY_NO_ALIGNMENT_VALUE
,
typename
Stride
=
typename
StrideType
<
EigenType
>
::
type
>
struct
NumpyMap
:
numpy_map_impl
<
EigenType
,
InputScalar
,
AlignmentValue
,
Stride
>
{};
}
// namespace eigenpy
...
...
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