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
f29fb6d2
Verified
Commit
f29fb6d2
authored
Feb 21, 2020
by
Justin Carpentier
Browse files
core: move EigenToPy to a dedicated file
parent
610feea9
Changes
3
Hide whitespace changes
Inline
Side-by-side
CMakeLists.txt
View file @
f29fb6d2
...
...
@@ -107,6 +107,7 @@ SET(${PROJECT_NAME}_HEADERS
include/eigenpy/details.hpp
include/eigenpy/fwd.hpp
include/eigenpy/eigen-allocator.hpp
include/eigenpy/eigen-to-python.hpp
include/eigenpy/map.hpp
include/eigenpy/geometry.hpp
include/eigenpy/geometry-conversion.hpp
...
...
include/eigenpy/details.hpp
View file @
f29fb6d2
...
...
@@ -17,12 +17,12 @@
#include
"eigenpy/eigenpy.hpp"
#include
"eigenpy/eigen-allocator.hpp"
#include
"eigenpy/eigen-to-python.hpp"
#include
"eigenpy/registration.hpp"
#include
"eigenpy/map.hpp"
#include
"eigenpy/exception.hpp"
#define GET_PY_ARRAY_TYPE(array) PyArray_ObjectType(reinterpret_cast<PyObject *>(array), 0)
namespace
boost
{
namespace
python
{
namespace
detail
{
...
...
@@ -59,45 +59,7 @@ namespace boost { namespace python { namespace detail {
namespace
eigenpy
{
namespace
bp
=
boost
::
python
;
/* --- TO PYTHON -------------------------------------------------------------- */
template
<
typename
MatType
>
struct
EigenToPy
{
static
PyObject
*
convert
(
MatType
const
&
mat
)
{
typedef
typename
MatType
::
Scalar
Scalar
;
assert
(
(
mat
.
rows
()
<
INT_MAX
)
&&
(
mat
.
cols
()
<
INT_MAX
)
&&
"Matrix range larger than int ... should never happen."
);
const
npy_intp
R
=
(
npy_intp
)
mat
.
rows
(),
C
=
(
npy_intp
)
mat
.
cols
();
PyArrayObject
*
pyArray
;
// Allocate Python memory
std
::
cout
<<
"basic convert"
<<
std
::
endl
;
if
(
(
((
!
(
C
==
1
)
!=
!
(
R
==
1
))
&&
!
MatType
::
IsVectorAtCompileTime
)
||
MatType
::
IsVectorAtCompileTime
)
&&
NumpyType
::
getType
()
==
ARRAY_TYPE
)
// Handle array with a single dimension
{
std
::
cout
<<
"mat1
\n
"
<<
mat
<<
std
::
endl
;
npy_intp
shape
[
1
]
=
{
C
==
1
?
R
:
C
};
pyArray
=
(
PyArrayObject
*
)
PyArray_SimpleNew
(
1
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
);
}
else
{
npy_intp
shape
[
2
]
=
{
R
,
C
};
pyArray
=
(
PyArrayObject
*
)
PyArray_SimpleNew
(
2
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
);
}
// Copy data
EigenAllocator
<
MatType
>::
copy
(
mat
,
pyArray
);
// Create an instance (either np.array or np.matrix)
return
NumpyType
::
getInstance
().
make
(
pyArray
).
ptr
();
}
};
/* --- FROM PYTHON ------------------------------------------------------------ */
...
...
@@ -341,7 +303,6 @@ namespace eigenpy
&
EigenFromPy
<
MatType
>::
construct
,
bp
::
type_id
<
MatType
>
());
}
};
#endif
template
<
typename
MatType
,
typename
EigenEquivalentType
>
...
...
include/eigenpy/eigen-to-python.hpp
0 → 100644
View file @
f29fb6d2
//
// Copyright (c) 2014-2020 CNRS INRIA
//
#ifndef __eigenpy_eigen_to_python_hpp__
#define __eigenpy_eigen_to_python_hpp__
#include
"eigenpy/fwd.hpp"
#include
"eigenpy/numpy-type.hpp"
#include
"eigenpy/eigen-allocator.hpp"
namespace
eigenpy
{
namespace
bp
=
boost
::
python
;
template
<
typename
MatType
>
struct
EigenToPy
{
static
PyObject
*
convert
(
MatType
const
&
mat
)
{
typedef
typename
MatType
::
Scalar
Scalar
;
assert
(
(
mat
.
rows
()
<
INT_MAX
)
&&
(
mat
.
cols
()
<
INT_MAX
)
&&
"Matrix range larger than int ... should never happen."
);
const
npy_intp
R
=
(
npy_intp
)
mat
.
rows
(),
C
=
(
npy_intp
)
mat
.
cols
();
PyArrayObject
*
pyArray
;
// Allocate Python memory
if
(
(
((
!
(
C
==
1
)
!=
!
(
R
==
1
))
&&
!
MatType
::
IsVectorAtCompileTime
)
||
MatType
::
IsVectorAtCompileTime
)
&&
NumpyType
::
getType
()
==
ARRAY_TYPE
)
// Handle array with a single dimension
{
npy_intp
shape
[
1
]
=
{
C
==
1
?
R
:
C
};
pyArray
=
(
PyArrayObject
*
)
PyArray_SimpleNew
(
1
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
);
}
else
{
npy_intp
shape
[
2
]
=
{
R
,
C
};
pyArray
=
(
PyArrayObject
*
)
PyArray_SimpleNew
(
2
,
shape
,
NumpyEquivalentType
<
Scalar
>::
type_code
);
}
// Copy data
EigenAllocator
<
MatType
>::
copy
(
mat
,
pyArray
);
// Create an instance (either np.array or np.matrix)
return
NumpyType
::
getInstance
().
make
(
pyArray
).
ptr
();
}
};
}
#endif // __eigenpy_eigen_to_python_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