Skip to content
GitLab
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
b95cb9bc
Verified
Commit
b95cb9bc
authored
Feb 21, 2020
by
Justin Carpentier
Browse files
core: add NumpyAllocator
parent
1fb4cf40
Changes
2
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
b95cb9bc
...
...
@@ -113,8 +113,9 @@ SET(${PROJECT_NAME}_HEADERS
include/eigenpy/geometry.hpp
include/eigenpy/geometry-conversion.hpp
include/eigenpy/memory.hpp
include/eigenpy/numpy-type.hpp
include/eigenpy/numpy.hpp
include/eigenpy/numpy-allocator.hpp
include/eigenpy/numpy-type.hpp
include/eigenpy/registration.hpp
include/eigenpy/angle-axis.hpp
include/eigenpy/quaternion.hpp
...
...
include/eigenpy/numpy-allocator.hpp
0 → 100644
View file @
b95cb9bc
/*
* Copyright 2020 INRIA
*/
#ifndef __eigenpy_numpy_allocator_hpp__
#define __eigenpy_numpy_allocator_hpp__
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/numpy-type.hpp"
#include
"eigenpy/eigen-allocator.hpp"
namespace
eigenpy
{
template
<
typename
MatType
>
struct
NumpyAllocator
{
template
<
typename
SimilarMatrixType
>
static
PyArrayObject
*
allocate
(
const
Eigen
::
MatrixBase
<
SimilarMatrixType
>
&
mat
,
npy_intp
nd
,
npy_intp
*
shape
)
{
typedef
typename
SimilarMatrixType
::
Scalar
Scalar
;
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
PyArray_SimpleNew
(
nd
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
);
// Copy data
EigenAllocator
<
SimilarMatrixType
>::
copy
(
mat
,
pyArray
);
return
pyArray
;
}
};
template
<
typename
MatType
>
struct
NumpyAllocator
<
MatType
&>
{
template
<
typename
SimilarMatrixType
>
static
PyArrayObject
*
allocate
(
Eigen
::
PlainObjectBase
<
SimilarMatrixType
>
&
mat
,
npy_intp
nd
,
npy_intp
*
shape
)
{
typedef
typename
SimilarMatrixType
::
Scalar
Scalar
;
enum
{
NPY_ARRAY_MEMORY_CONTIGUOUS
=
SimilarMatrixType
::
IsRowMajor
?
NPY_ARRAY_CARRAY
:
NPY_ARRAY_FARRAY
};
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
PyArray_New
(
&
PyArray_Type
,
nd
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
,
NULL
,
mat
.
data
(),
0
,
NPY_ARRAY_MEMORY_CONTIGUOUS
|
NPY_ARRAY_ALIGNED
,
NULL
);
return
pyArray
;
}
};
template
<
typename
MatType
>
struct
NumpyAllocator
<
const
MatType
&>
{
template
<
typename
SimilarMatrixType
>
static
PyArrayObject
*
allocate
(
const
Eigen
::
PlainObjectBase
<
SimilarMatrixType
>
&
mat
,
npy_intp
nd
,
npy_intp
*
shape
)
{
typedef
typename
SimilarMatrixType
::
Scalar
Scalar
;
enum
{
NPY_ARRAY_MEMORY_CONTIGUOUS_RO
=
SimilarMatrixType
::
IsRowMajor
?
NPY_ARRAY_CARRAY_RO
:
NPY_ARRAY_FARRAY_RO
};
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
PyArray_New
(
&
PyArray_Type
,
nd
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
,
NULL
,
mat
.
data
(),
0
,
NPY_ARRAY_MEMORY_CONTIGUOUS_RO
|
NPY_ARRAY_ALIGNED
,
NULL
);
return
pyArray
;
}
};
}
#endif // ifndef __eigenpy_numpy_allocator_hpp__
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment