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
2a7acb6d
Commit
2a7acb6d
authored
Jun 22, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Incref descriptors properly when creating arrays
parent
669e1426
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
9 deletions
+16
-9
example/example20.py
+5
-7
example/example20.ref
+9
-0
include/pybind11/numpy.h
+2
-2
No files found.
example/example20.py
View file @
2a7acb6d
...
@@ -29,12 +29,10 @@ for func, dtype in [(create_rec_simple, simple_dtype), (create_rec_packed, packe
...
@@ -29,12 +29,10 @@ for func, dtype in [(create_rec_simple, simple_dtype), (create_rec_packed, packe
check_eq
(
arr
,
[(
False
,
0
,
0.0
),
(
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)],
simple_dtype
)
check_eq
(
arr
,
[(
False
,
0
,
0.0
),
(
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)],
simple_dtype
)
check_eq
(
arr
,
[(
False
,
0
,
0.0
),
(
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)],
packed_dtype
)
check_eq
(
arr
,
[(
False
,
0
,
0.0
),
(
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)],
packed_dtype
)
# uncomment lines below to cause a segfault upon exit in Py_Finalize :(
if
dtype
==
simple_dtype
:
print_rec_simple
(
arr
)
# if dtype == simple_dtype:
else
:
# print_rec_simple(arr)
print_rec_packed
(
arr
)
# else:
# print_rec_packed(arr)
nested_dtype
=
np
.
dtype
([(
'a'
,
simple_dtype
),
(
'b'
,
packed_dtype
)])
nested_dtype
=
np
.
dtype
([(
'a'
,
simple_dtype
),
(
'b'
,
packed_dtype
)])
...
@@ -47,4 +45,4 @@ assert arr.dtype == nested_dtype
...
@@ -47,4 +45,4 @@ assert arr.dtype == nested_dtype
check_eq
(
arr
,
[((
False
,
0
,
0.0
),
(
True
,
1
,
1.5
)),
check_eq
(
arr
,
[((
False
,
0
,
0.0
),
(
True
,
1
,
1.5
)),
((
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)),
((
True
,
1
,
1.5
),
(
False
,
2
,
3.0
)),
((
False
,
2
,
3.0
),
(
True
,
3
,
4.5
))],
nested_dtype
)
((
False
,
2
,
3.0
),
(
True
,
3
,
4.5
))],
nested_dtype
)
#
print_rec_nested(arr)
print_rec_nested
(
arr
)
example/example20.ref
View file @
2a7acb6d
T{?:x:xxxI:y:f:z:}
T{?:x:xxxI:y:f:z:}
T{?:x:=I:y:f:z:}
T{?:x:=I:y:f:z:}
T{T{?:x:xxxI:y:f:z:}:a:T{?:x:=I:y:f:z:}:b:}
T{T{?:x:xxxI:y:f:z:}:a:T{?:x:=I:y:f:z:}:b:}
0,0,0
1,1,1.5
0,2,3
0,0,0
1,1,1.5
0,2,3
0,0,0|1,1,1.5
1,1,1.5|0,2,3
0,2,3|1,3,4.5
include/pybind11/numpy.h
View file @
2a7acb6d
...
@@ -96,7 +96,7 @@ public:
...
@@ -96,7 +96,7 @@ public:
template
<
typename
Type
>
array
(
size_t
size
,
const
Type
*
ptr
)
{
template
<
typename
Type
>
array
(
size_t
size
,
const
Type
*
ptr
)
{
API
&
api
=
lookup_api
();
API
&
api
=
lookup_api
();
PyObject
*
descr
=
detail
::
npy_format_descriptor
<
Type
>::
desc
r
();
PyObject
*
descr
=
object
(
detail
::
npy_format_descriptor
<
Type
>::
descr
(),
true
).
release
().
pt
r
();
Py_intptr_t
shape
=
(
Py_intptr_t
)
size
;
Py_intptr_t
shape
=
(
Py_intptr_t
)
size
;
object
tmp
=
object
(
api
.
PyArray_NewFromDescr_
(
object
tmp
=
object
(
api
.
PyArray_NewFromDescr_
(
api
.
PyArray_Type_
,
descr
,
1
,
&
shape
,
nullptr
,
(
void
*
)
ptr
,
0
,
nullptr
),
false
);
api
.
PyArray_Type_
,
descr
,
1
,
&
shape
,
nullptr
,
(
void
*
)
ptr
,
0
,
nullptr
),
false
);
...
@@ -147,7 +147,7 @@ public:
...
@@ -147,7 +147,7 @@ public:
if
(
ptr
==
nullptr
)
if
(
ptr
==
nullptr
)
return
nullptr
;
return
nullptr
;
API
&
api
=
lookup_api
();
API
&
api
=
lookup_api
();
PyObject
*
descr
=
detail
::
npy_format_descriptor
<
T
>::
desc
r
();
PyObject
*
descr
=
object
(
detail
::
npy_format_descriptor
<
T
>::
descr
(),
true
).
release
().
pt
r
();
PyObject
*
result
=
api
.
PyArray_FromAny_
(
ptr
,
descr
,
0
,
0
,
API
::
NPY_ENSURE_ARRAY_
|
ExtraFlags
,
nullptr
);
PyObject
*
result
=
api
.
PyArray_FromAny_
(
ptr
,
descr
,
0
,
0
,
API
::
NPY_ENSURE_ARRAY_
|
ExtraFlags
,
nullptr
);
if
(
!
result
)
if
(
!
result
)
PyErr_Clear
();
PyErr_Clear
();
...
...
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