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
afec732a
Verified
Commit
afec732a
authored
May 05, 2020
by
Justin Carpentier
Browse files
core: allows the use of user types
parent
747ef907
Changes
2
Hide whitespace changes
Inline
Side-by-side
include/eigenpy/eigen-allocator.hpp
View file @
afec732a
...
...
@@ -7,6 +7,7 @@
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/numpy-map.hpp"
#include
"eigenpy/user-type.hpp"
#include
"eigenpy/scalar-conversion.hpp"
#include
"eigenpy/utils/is-aligned.hpp"
...
...
@@ -115,7 +116,8 @@ namespace eigenpy
Type
&
mat
=
*
mat_ptr
;
const
int
pyArray_type_code
=
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
);
if
(
pyArray_type_code
==
NumpyEquivalentType
<
Scalar
>::
type_code
)
const
int
Scalar_type_code
=
Register
::
getTypeCode
<
Scalar
>
();
if
(
pyArray_type_code
==
Scalar_type_code
)
{
mat
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
);
// avoid useless cast
return
;
...
...
@@ -159,10 +161,11 @@ namespace eigenpy
{
const
MatrixDerived
&
mat
=
const_cast
<
const
MatrixDerived
&>
(
mat_
.
derived
());
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
==
NumpyEquivalentType
<
Scalar
>::
type_code
)
// no cast needed
if
(
pyArray_type_code
==
Scalar
_
type_code
)
// no cast needed
{
MapType
map_pyArray
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
);
if
(
mat
.
rows
()
==
map_pyArray
.
rows
())
...
...
@@ -220,7 +223,8 @@ namespace eigenpy
bool
need_to_allocate
=
false
;
const
int
pyArray_type_code
=
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
);
if
(
pyArray_type_code
!=
NumpyEquivalentType
<
Scalar
>::
type_code
)
const
int
Scalar_type_code
=
Register
::
getTypeCode
<
Scalar
>
();
if
(
pyArray_type_code
!=
Scalar_type_code
)
need_to_allocate
|=
true
;
if
(
(
MatType
::
IsRowMajor
&&
(
PyArray_IS_C_CONTIGUOUS
(
pyArray
)
&&
!
PyArray_IS_F_CONTIGUOUS
(
pyArray
)))
||
(
!
MatType
::
IsRowMajor
&&
(
PyArray_IS_F_CONTIGUOUS
(
pyArray
)
&&
!
PyArray_IS_C_CONTIGUOUS
(
pyArray
)))
...
...
@@ -246,7 +250,7 @@ namespace eigenpy
new
(
raw_ptr
)
StorageType
(
mat_ref
,
pyArray
,
mat_ptr
);
RefType
&
mat
=
*
reinterpret_cast
<
RefType
*>
(
raw_ptr
);
if
(
pyArray_type_code
==
NumpyEquivalentType
<
Scalar
>::
type_code
)
if
(
pyArray_type_code
==
Scalar
_
type_code
)
{
mat
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
);
// avoid useless cast
return
;
...
...
@@ -284,7 +288,7 @@ namespace eigenpy
}
else
{
assert
(
pyArray_type_code
==
NumpyEquivalentType
<
Scalar
>::
type_code
);
assert
(
pyArray_type_code
==
Scalar
_
type_code
);
typename
NumpyMap
<
MatType
,
Scalar
,
Options
,
NumpyMapStride
>::
EigenMap
numpyMap
=
NumpyMap
<
MatType
,
Scalar
,
Options
,
NumpyMapStride
>::
map
(
pyArray
);
RefType
mat_ref
(
numpyMap
);
new
(
raw_ptr
)
StorageType
(
mat_ref
,
pyArray
);
...
...
@@ -312,7 +316,9 @@ namespace eigenpy
bool
need_to_allocate
=
false
;
const
int
pyArray_type_code
=
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
);
if
(
pyArray_type_code
!=
NumpyEquivalentType
<
Scalar
>::
type_code
)
const
int
Scalar_type_code
=
Register
::
getTypeCode
<
Scalar
>
();
if
(
pyArray_type_code
!=
Scalar_type_code
)
need_to_allocate
|=
true
;
if
(
(
MatType
::
IsRowMajor
&&
(
PyArray_IS_C_CONTIGUOUS
(
pyArray
)
&&
!
PyArray_IS_F_CONTIGUOUS
(
pyArray
)))
||
(
!
MatType
::
IsRowMajor
&&
(
PyArray_IS_F_CONTIGUOUS
(
pyArray
)
&&
!
PyArray_IS_C_CONTIGUOUS
(
pyArray
)))
...
...
@@ -338,7 +344,7 @@ namespace eigenpy
new
(
raw_ptr
)
StorageType
(
mat_ref
,
pyArray
,
mat_ptr
);
MatType
&
mat
=
*
mat_ptr
;
if
(
pyArray_type_code
==
NumpyEquivalentType
<
Scalar
>::
type_code
)
if
(
pyArray_type_code
==
Scalar
_
type_code
)
{
mat
=
NumpyMap
<
MatType
,
Scalar
>::
map
(
pyArray
);
// avoid useless cast
return
;
...
...
@@ -376,7 +382,7 @@ namespace eigenpy
}
else
{
assert
(
pyArray_type_code
==
NumpyEquivalentType
<
Scalar
>::
type_code
);
assert
(
pyArray_type_code
==
Scalar
_
type_code
);
typename
NumpyMap
<
MatType
,
Scalar
,
Options
,
NumpyMapStride
>::
EigenMap
numpyMap
=
NumpyMap
<
MatType
,
Scalar
,
Options
,
NumpyMapStride
>::
map
(
pyArray
);
RefType
mat_ref
(
numpyMap
);
new
(
raw_ptr
)
StorageType
(
mat_ref
,
pyArray
);
...
...
include/eigenpy/numpy-allocator.hpp
View file @
afec732a
...
...
@@ -9,8 +9,11 @@
#include
"eigenpy/numpy-type.hpp"
#include
"eigenpy/eigen-allocator.hpp"
#include
"eigenpy/user-type.hpp"
namespace
eigenpy
{
template
<
typename
MatType
>
struct
NumpyAllocator
{
...
...
@@ -20,8 +23,8 @@ namespace eigenpy
{
typedef
typename
SimilarMatrixType
::
Scalar
Scalar
;
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
call_PyArray_SimpleNew
(
static_cast
<
int
>
(
nd
),
shape
,
NumpyEquivalentType
<
Scalar
>::
type_
code
);
const
int
code
=
Register
::
getTypeCode
<
Scalar
>
();
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
call_PyArray_SimpleNew
(
static_cast
<
int
>
(
nd
),
shape
,
code
);
// Copy data
EigenAllocator
<
SimilarMatrixType
>::
copy
(
mat
,
pyArray
);
...
...
@@ -42,11 +45,11 @@ namespace eigenpy
if
(
NumpyType
::
sharedMemory
())
{
PyTypeObject
py_type
=
get
Py
Type
<
Scalar
>
();
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
call_PyArray_New
(
&
py_t
ype
,
const
int
Scalar_type_code
=
Register
::
getType
Code
<
Scalar
>
();
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
call_PyArray_New
(
getPyArrayT
ype
()
,
static_cast
<
int
>
(
nd
),
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
,
Scalar
_
type_code
,
mat
.
data
(),
NPY_ARRAY_MEMORY_CONTIGUOUS
|
NPY_ARRAY_ALIGNED
);
...
...
@@ -80,11 +83,11 @@ namespace eigenpy
if
(
NumpyType
::
sharedMemory
())
{
PyTypeObject
py_type
=
get
Py
Type
<
Scalar
>
();
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
call_PyArray_New
(
&
py_t
ype
,
const
int
Scalar_type_code
=
Register
::
getType
Code
<
Scalar
>
();
PyArrayObject
*
pyArray
=
(
PyArrayObject
*
)
call_PyArray_New
(
getPyArrayT
ype
()
,
static_cast
<
int
>
(
nd
),
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
,
Scalar
_
type_code
,
const_cast
<
SimilarMatrixType
&>
(
mat
.
derived
()).
data
(),
NPY_ARRAY_MEMORY_CONTIGUOUS_RO
|
NPY_ARRAY_ALIGNED
);
...
...
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