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
5e7ae5b1
Verified
Commit
5e7ae5b1
authored
5 years ago
by
Justin Carpentier
Browse files
Options
Downloads
Patches
Plain Diff
core: add helper np_type_is_convertible_into_scalar
parent
4f6f7044
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
include/eigenpy/eigen-from-python.hpp
+2
-29
2 additions, 29 deletions
include/eigenpy/eigen-from-python.hpp
include/eigenpy/numpy-type.hpp
+30
-0
30 additions, 0 deletions
include/eigenpy/numpy-type.hpp
with
32 additions
and
29 deletions
include/eigenpy/eigen-from-python.hpp
+
2
−
29
View file @
5e7ae5b1
...
@@ -86,34 +86,7 @@ namespace eigenpy
...
@@ -86,34 +86,7 @@ namespace eigenpy
template
<
typename
MatType
>
template
<
typename
MatType
>
struct
EigenFromPy
struct
EigenFromPy
{
{
typedef
typename
MatType
::
Scalar
Scalar
;
static
bool
isScalarConvertible
(
const
int
np_type
)
{
if
(
NumpyEquivalentType
<
typename
MatType
::
Scalar
>::
type_code
==
np_type
)
return
true
;
switch
(
np_type
)
{
case
NPY_INT
:
return
FromTypeToType
<
int
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_LONG
:
return
FromTypeToType
<
long
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_FLOAT
:
return
FromTypeToType
<
float
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_CFLOAT
:
return
FromTypeToType
<
std
::
complex
<
float
>
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_DOUBLE
:
return
FromTypeToType
<
double
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_CDOUBLE
:
return
FromTypeToType
<
std
::
complex
<
double
>
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_LONGDOUBLE
:
return
FromTypeToType
<
long
double
,
typename
MatType
::
Scalar
>::
value
;
case
NPY_CLONGDOUBLE
:
return
FromTypeToType
<
std
::
complex
<
long
double
>
,
typename
MatType
::
Scalar
>::
value
;
default:
return
false
;
}
}
/// \brief Determine if pyObj can be converted into a MatType object
/// \brief Determine if pyObj can be converted into a MatType object
static
void
*
convertible
(
PyArrayObject
*
pyArray
)
static
void
*
convertible
(
PyArrayObject
*
pyArray
)
...
@@ -121,7 +94,7 @@ namespace eigenpy
...
@@ -121,7 +94,7 @@ namespace eigenpy
if
(
!
PyArray_Check
(
pyArray
))
if
(
!
PyArray_Check
(
pyArray
))
return
0
;
return
0
;
if
(
!
isScalarConvertible
(
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
)))
if
(
!
np_type_is_convertible_into_scalar
<
Scalar
>
(
EIGENPY_GET_PY_ARRAY_TYPE
(
pyArray
)))
return
0
;
return
0
;
if
(
MatType
::
IsVectorAtCompileTime
)
if
(
MatType
::
IsVectorAtCompileTime
)
...
...
This diff is collapsed.
Click to expand it.
include/eigenpy/numpy-type.hpp
+
30
−
0
View file @
5e7ae5b1
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#define __eigenpy_numpy_type_hpp__
#define __eigenpy_numpy_type_hpp__
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/scalar-conversion.hpp"
#include
<patchlevel.h>
// For PY_MAJOR_VERSION
#include
<patchlevel.h>
// For PY_MAJOR_VERSION
...
@@ -23,6 +24,35 @@ namespace eigenpy
...
@@ -23,6 +24,35 @@ namespace eigenpy
template
<
>
struct
NumpyEquivalentType
<
std
::
complex
<
long
double
>
>
{
enum
{
type_code
=
NPY_CLONGDOUBLE
};};
template
<
>
struct
NumpyEquivalentType
<
std
::
complex
<
long
double
>
>
{
enum
{
type_code
=
NPY_CLONGDOUBLE
};};
template
<
>
struct
NumpyEquivalentType
<
int
>
{
enum
{
type_code
=
NPY_INT
};};
template
<
>
struct
NumpyEquivalentType
<
int
>
{
enum
{
type_code
=
NPY_INT
};};
template
<
>
struct
NumpyEquivalentType
<
long
>
{
enum
{
type_code
=
NPY_LONG
};};
template
<
>
struct
NumpyEquivalentType
<
long
>
{
enum
{
type_code
=
NPY_LONG
};};
template
<
typename
Scalar
>
bool
np_type_is_convertible_into_scalar
(
const
int
np_type
)
{
if
(
NumpyEquivalentType
<
Scalar
>::
type_code
==
np_type
)
return
true
;
switch
(
np_type
)
{
case
NPY_INT
:
return
FromTypeToType
<
int
,
Scalar
>::
value
;
case
NPY_LONG
:
return
FromTypeToType
<
long
,
Scalar
>::
value
;
case
NPY_FLOAT
:
return
FromTypeToType
<
float
,
Scalar
>::
value
;
case
NPY_CFLOAT
:
return
FromTypeToType
<
std
::
complex
<
float
>
,
Scalar
>::
value
;
case
NPY_DOUBLE
:
return
FromTypeToType
<
double
,
Scalar
>::
value
;
case
NPY_CDOUBLE
:
return
FromTypeToType
<
std
::
complex
<
double
>
,
Scalar
>::
value
;
case
NPY_LONGDOUBLE
:
return
FromTypeToType
<
long
double
,
Scalar
>::
value
;
case
NPY_CLONGDOUBLE
:
return
FromTypeToType
<
std
::
complex
<
long
double
>
,
Scalar
>::
value
;
default:
return
false
;
}
}
enum
NP_TYPE
enum
NP_TYPE
{
{
...
...
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