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
d0bafd90
Commit
d0bafd90
authored
Jun 26, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add a test for buffer format of unbound struct
parent
a0e37f25
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
1 deletions
+12
-1
example/example20.cpp
+7
-0
example/example20.py
+5
-1
No files found.
example/example20.cpp
View file @
d0bafd90
...
@@ -44,6 +44,8 @@ std::ostream& operator<<(std::ostream& os, const NestedStruct& v) {
...
@@ -44,6 +44,8 @@ std::ostream& operator<<(std::ostream& os, const NestedStruct& v) {
return
os
<<
"n:a="
<<
v
.
a
<<
";b="
<<
v
.
b
;
return
os
<<
"n:a="
<<
v
.
a
<<
";b="
<<
v
.
b
;
}
}
struct
UnboundStruct
{
};
template
<
typename
T
>
template
<
typename
T
>
py
::
array
mkarray_via_buffer
(
size_t
n
)
{
py
::
array
mkarray_via_buffer
(
size_t
n
)
{
return
py
::
array
(
py
::
buffer_info
(
nullptr
,
sizeof
(
T
),
return
py
::
array
(
py
::
buffer_info
(
nullptr
,
sizeof
(
T
),
...
@@ -61,6 +63,10 @@ py::array_t<S> create_recarray(size_t n) {
...
@@ -61,6 +63,10 @@ py::array_t<S> create_recarray(size_t n) {
return
arr
;
return
arr
;
}
}
std
::
string
get_format_unbound
()
{
return
py
::
format_descriptor
<
UnboundStruct
>::
format
();
}
py
::
array_t
<
NestedStruct
>
create_nested
(
size_t
n
)
{
py
::
array_t
<
NestedStruct
>
create_nested
(
size_t
n
)
{
auto
arr
=
mkarray_via_buffer
<
NestedStruct
>
(
n
);
auto
arr
=
mkarray_via_buffer
<
NestedStruct
>
(
n
);
auto
ptr
=
static_cast
<
NestedStruct
*>
(
arr
.
request
().
ptr
);
auto
ptr
=
static_cast
<
NestedStruct
*>
(
arr
.
request
().
ptr
);
...
@@ -107,4 +113,5 @@ void init_ex20(py::module &m) {
...
@@ -107,4 +113,5 @@ void init_ex20(py::module &m) {
m
.
def
(
"print_rec_packed"
,
&
print_recarray
<
PackedStruct
>
);
m
.
def
(
"print_rec_packed"
,
&
print_recarray
<
PackedStruct
>
);
m
.
def
(
"print_rec_nested"
,
&
print_recarray
<
NestedStruct
>
);
m
.
def
(
"print_rec_nested"
,
&
print_recarray
<
NestedStruct
>
);
m
.
def
(
"print_dtypes"
,
&
print_dtypes
);
m
.
def
(
"print_dtypes"
,
&
print_dtypes
);
m
.
def
(
"get_format_unbound"
,
&
get_format_unbound
);
}
}
example/example20.py
View file @
d0bafd90
#!/usr/bin/env python
#!/usr/bin/env python
from
__future__
import
print_function
from
__future__
import
print_function
import
unittest
import
numpy
as
np
import
numpy
as
np
from
example
import
(
from
example
import
(
create_rec_simple
,
create_rec_packed
,
create_rec_nested
,
print_format_descriptors
,
create_rec_simple
,
create_rec_packed
,
create_rec_nested
,
print_format_descriptors
,
print_rec_simple
,
print_rec_packed
,
print_rec_nested
,
print_dtypes
print_rec_simple
,
print_rec_packed
,
print_rec_nested
,
print_dtypes
,
get_format_unbound
)
)
def
check_eq
(
arr
,
data
,
dtype
):
def
check_eq
(
arr
,
data
,
dtype
):
np
.
testing
.
assert_equal
(
arr
,
np
.
array
(
data
,
dtype
=
dtype
))
np
.
testing
.
assert_equal
(
arr
,
np
.
array
(
data
,
dtype
=
dtype
))
unittest
.
TestCase
()
.
assertRaisesRegex
(
RuntimeError
,
'unsupported buffer format'
,
get_format_unbound
)
print_format_descriptors
()
print_format_descriptors
()
print_dtypes
()
print_dtypes
()
...
...
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