Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pybind11
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
open
pybind11
Commits
a970a579
Commit
a970a579
authored
May 20, 2016
by
Wenzel Jakob
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eigen.h: return compile time vectors as 1D NumPy arrays
parent
b47a9de0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
18 deletions
+35
-18
include/pybind11/eigen.h
+35
-18
No files found.
include/pybind11/eigen.h
View file @
a970a579
...
@@ -41,6 +41,7 @@ template<typename Type>
...
@@ -41,6 +41,7 @@ template<typename Type>
struct
type_caster
<
Type
,
typename
std
::
enable_if
<
is_eigen_dense
<
Type
>::
value
>::
type
>
{
struct
type_caster
<
Type
,
typename
std
::
enable_if
<
is_eigen_dense
<
Type
>::
value
>::
type
>
{
typedef
typename
Type
::
Scalar
Scalar
;
typedef
typename
Type
::
Scalar
Scalar
;
static
constexpr
bool
rowMajor
=
Type
::
Flags
&
Eigen
::
RowMajorBit
;
static
constexpr
bool
rowMajor
=
Type
::
Flags
&
Eigen
::
RowMajorBit
;
static
constexpr
bool
isVector
=
Type
::
IsVectorAtCompileTime
;
bool
load
(
handle
src
,
bool
)
{
bool
load
(
handle
src
,
bool
)
{
array_t
<
Scalar
>
buffer
(
src
,
true
);
array_t
<
Scalar
>
buffer
(
src
,
true
);
...
@@ -50,7 +51,7 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
...
@@ -50,7 +51,7 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
buffer_info
info
=
buffer
.
request
();
buffer_info
info
=
buffer
.
request
();
if
(
info
.
ndim
==
1
)
{
if
(
info
.
ndim
==
1
)
{
typedef
Eigen
::
Stride
<
Eigen
::
Dynamic
,
0
>
Strides
;
typedef
Eigen
::
Stride
<
Eigen
::
Dynamic
,
0
>
Strides
;
if
(
!
Type
::
IsVectorAtCompileTime
&&
if
(
!
isVector
&&
!
(
Type
::
RowsAtCompileTime
==
Eigen
::
Dynamic
&&
!
(
Type
::
RowsAtCompileTime
==
Eigen
::
Dynamic
&&
Type
::
ColsAtCompileTime
==
Eigen
::
Dynamic
))
Type
::
ColsAtCompileTime
==
Eigen
::
Dynamic
))
return
false
;
return
false
;
...
@@ -87,23 +88,39 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
...
@@ -87,23 +88,39 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value>::t
}
}
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
array
result
(
buffer_info
(
if
(
isVector
)
{
/* Pointer to buffer */
return
array
(
buffer_info
(
const_cast
<
Scalar
*>
(
src
.
data
()),
/* Pointer to buffer */
/* Size of one scalar */
const_cast
<
Scalar
*>
(
src
.
data
()),
sizeof
(
Scalar
),
/* Size of one scalar */
/* Python struct-style format descriptor */
sizeof
(
Scalar
),
format_descriptor
<
Scalar
>::
value
,
/* Python struct-style format descriptor */
/* Number of dimensions */
format_descriptor
<
Scalar
>::
value
,
2
,
/* Number of dimensions */
/* Buffer dimensions */
1
,
{
(
size_t
)
src
.
rows
(),
/* Buffer dimensions */
(
size_t
)
src
.
cols
()
},
{
(
size_t
)
src
.
size
()
},
/* Strides (in bytes) for each index */
/* Strides (in bytes) for each index */
{
sizeof
(
Scalar
)
*
(
rowMajor
?
src
.
cols
()
:
1
),
{
sizeof
(
Scalar
)
}
sizeof
(
Scalar
)
*
(
rowMajor
?
1
:
src
.
rows
())
}
)).
release
();
));
}
else
{
return
result
.
release
();
return
array
(
buffer_info
(
/* Pointer to buffer */
const_cast
<
Scalar
*>
(
src
.
data
()),
/* Size of one scalar */
sizeof
(
Scalar
),
/* Python struct-style format descriptor */
format_descriptor
<
Scalar
>::
value
,
/* Number of dimensions */
isVector
?
1
:
2
,
/* Buffer dimensions */
{
(
size_t
)
src
.
rows
(),
(
size_t
)
src
.
cols
()
},
/* Strides (in bytes) for each index */
{
sizeof
(
Scalar
)
*
(
rowMajor
?
src
.
cols
()
:
1
),
sizeof
(
Scalar
)
*
(
rowMajor
?
1
:
src
.
rows
())
}
)).
release
();
}
}
}
template
<
typename
_T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
_T
>
;
template
<
typename
_T
>
using
cast_op_type
=
pybind11
::
detail
::
cast_op_type
<
_T
>
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a 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