Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
pybind11
Commits
6956b655
Commit
6956b655
authored
Aug 15, 2016
by
Ivan Smirnov
Browse files
Simplify code in eigen.h using new array ctors
parent
67b3daee
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
77 deletions
+18
-77
include/pybind11/eigen.h
include/pybind11/eigen.h
+18
-77
No files found.
include/pybind11/eigen.h
View file @
6956b655
...
...
@@ -85,7 +85,7 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value &&
if
(
!
buffer
.
check
())
return
false
;
buffer_inf
o
info
=
buffer
.
request
();
aut
o
info
=
buffer
.
request
();
if
(
info
.
ndim
==
1
)
{
typedef
Eigen
::
InnerStride
<>
Strides
;
if
(
!
isVector
&&
...
...
@@ -127,37 +127,19 @@ struct type_caster<Type, typename std::enable_if<is_eigen_dense<Type>::value &&
static
handle
cast
(
const
Type
&
src
,
return_value_policy
/* policy */
,
handle
/* parent */
)
{
if
(
isVector
)
{
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
>::
format
(),
/* Number of dimensions */
1
,
/* Buffer dimensions */
{
(
size_t
)
src
.
size
()
},
/* Strides (in bytes) for each index */
{
sizeof
(
Scalar
)
*
static_cast
<
size_t
>
(
src
.
innerStride
())
}
)).
release
();
return
array
(
{
(
size_t
)
src
.
size
()
},
// shape
{
sizeof
(
Scalar
)
*
static_cast
<
size_t
>
(
src
.
innerStride
())
},
// strides
src
.
data
()
// data
).
release
();
}
else
{
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
>::
format
(),
/* Number of dimensions */
isVector
?
1
:
2
,
/* Buffer dimensions */
{
(
size_t
)
src
.
rows
(),
return
array
(
{
(
size_t
)
src
.
rows
(),
// shape
(
size_t
)
src
.
cols
()
},
/* Strides (in bytes) for each index */
{
sizeof
(
Scalar
)
*
static_cast
<
size_t
>
(
src
.
row
Stride
()),
sizeof
(
Scalar
)
*
static_cast
<
size_t
>
(
src
.
colStride
())
}
)
).
release
();
{
sizeof
(
Scalar
)
*
static_cast
<
size_t
>
(
src
.
rowStride
()),
// strides
sizeof
(
Scalar
)
*
static_cast
<
size_t
>
(
src
.
col
Stride
())
}
,
src
.
data
()
// data
).
release
();
}
}
...
...
@@ -248,9 +230,9 @@ struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::
!
outerIndicesArray
.
check
())
return
false
;
buffer_inf
o
outerIndices
=
outerIndicesArray
.
request
();
buffer_inf
o
innerIndices
=
innerIndicesArray
.
request
();
buffer_inf
o
values
=
valuesArray
.
request
();
aut
o
outerIndices
=
outerIndicesArray
.
request
();
aut
o
innerIndices
=
innerIndicesArray
.
request
();
aut
o
values
=
valuesArray
.
request
();
value
=
Eigen
::
MappedSparseMatrix
<
Scalar
,
Type
::
Flags
,
StorageIndex
>
(
shape
[
0
].
cast
<
Index
>
(),
...
...
@@ -270,50 +252,9 @@ struct type_caster<Type, typename std::enable_if<is_eigen_sparse<Type>::value>::
object
matrix_type
=
module
::
import
(
"scipy.sparse"
).
attr
(
rowMajor
?
"csr_matrix"
:
"csc_matrix"
);
array
data
(
buffer_info
(
// Pointer to buffer
const_cast
<
Scalar
*>
(
src
.
valuePtr
()),
// Size of one scalar
sizeof
(
Scalar
),
// Python struct-style format descriptor
format_descriptor
<
Scalar
>::
format
(),
// Number of dimensions
1
,
// Buffer dimensions
{
(
size_t
)
src
.
nonZeros
()
},
// Strides
{
sizeof
(
Scalar
)
}
));
array
outerIndices
(
buffer_info
(
// Pointer to buffer
const_cast
<
StorageIndex
*>
(
src
.
outerIndexPtr
()),
// Size of one scalar
sizeof
(
StorageIndex
),
// Python struct-style format descriptor
format_descriptor
<
StorageIndex
>::
format
(),
// Number of dimensions
1
,
// Buffer dimensions
{
(
size_t
)
(
rowMajor
?
src
.
rows
()
:
src
.
cols
())
+
1
},
// Strides
{
sizeof
(
StorageIndex
)
}
));
array
innerIndices
(
buffer_info
(
// Pointer to buffer
const_cast
<
StorageIndex
*>
(
src
.
innerIndexPtr
()),
// Size of one scalar
sizeof
(
StorageIndex
),
// Python struct-style format descriptor
format_descriptor
<
StorageIndex
>::
format
(),
// Number of dimensions
1
,
// Buffer dimensions
{
(
size_t
)
src
.
nonZeros
()
},
// Strides
{
sizeof
(
StorageIndex
)
}
));
array
data
((
size_t
)
src
.
nonZeros
(),
src
.
valuePtr
());
array
outerIndices
((
size_t
)
(
rowMajor
?
src
.
rows
()
:
src
.
cols
())
+
1
,
src
.
outerIndexPtr
());
array
innerIndices
((
size_t
)
src
.
nonZeros
(),
src
.
innerIndexPtr
());
return
matrix_type
(
std
::
make_tuple
(
data
,
innerIndices
,
outerIndices
),
...
...
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