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
abd3429c
Commit
abd3429c
authored
Nov 01, 2016
by
Ivan Smirnov
Browse files
Add a test for numpy dtypes with custom names
parent
e8b50360
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
2 deletions
+11
-2
tests/test_numpy_dtypes.cpp
tests/test_numpy_dtypes.cpp
+9
-1
tests/test_numpy_dtypes.py
tests/test_numpy_dtypes.py
+2
-1
No files found.
tests/test_numpy_dtypes.cpp
View file @
abd3429c
...
...
@@ -67,6 +67,11 @@ struct StringStruct {
std
::
array
<
char
,
3
>
b
;
};
PYBIND11_PACKED
(
struct
StructWithUglyNames
{
int8_t
__x__
;
uint64_t
__y__
;
});
enum
class
E1
:
int64_t
{
A
=
-
1
,
B
=
1
};
enum
E2
:
uint8_t
{
X
=
1
,
Y
=
2
};
...
...
@@ -197,7 +202,8 @@ py::list print_dtypes() {
py
::
dtype
::
of
<
PartialStruct
>
().
str
(),
py
::
dtype
::
of
<
PartialNestedStruct
>
().
str
(),
py
::
dtype
::
of
<
StringStruct
>
().
str
(),
py
::
dtype
::
of
<
EnumStruct
>
().
str
()
py
::
dtype
::
of
<
EnumStruct
>
().
str
(),
py
::
dtype
::
of
<
StructWithUglyNames
>
().
str
()
};
auto
l
=
py
::
list
();
for
(
const
auto
&
s
:
dtypes
)
{
...
...
@@ -312,6 +318,8 @@ test_initializer numpy_dtypes([](py::module &m) {
// ... or after
py
::
class_
<
PackedStruct
>
(
m
,
"PackedStruct"
);
PYBIND11_NUMPY_DTYPE_EX
(
StructWithUglyNames
,
__x__
,
"x"
,
__y__
,
"y"
);
m
.
def
(
"create_rec_simple"
,
&
create_recarray
<
SimpleStruct
>
);
m
.
def
(
"create_rec_packed"
,
&
create_recarray
<
PackedStruct
>
);
m
.
def
(
"create_rec_nested"
,
&
create_nested
);
...
...
tests/test_numpy_dtypes.py
View file @
abd3429c
...
...
@@ -42,7 +42,8 @@ def test_dtype():
"{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}"
,
"{'names':['a'], 'formats':[{'names':['x','y','z'], 'formats':['?','<u4','<f4'], 'offsets':[0,4,8], 'itemsize':24}], 'offsets':[8], 'itemsize':40}"
,
"[('a', 'S3'), ('b', 'S3')]"
,
"[('e1', '<i8'), ('e2', 'u1')]"
"[('e1', '<i8'), ('e2', 'u1')]"
,
"[('x', 'i1'), ('y', '<u8')]"
]
d1
=
np
.
dtype
({
'names'
:
[
'a'
,
'b'
],
'formats'
:
[
'int32'
,
'float64'
],
...
...
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