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
7edd72db
Commit
7edd72db
authored
Oct 20, 2016
by
Ivan Smirnov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disallow registering dtypes multiple times
parent
ccc69f91
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
13 additions
and
0 deletions
+13
-0
include/pybind11/numpy.h
+3
-0
tests/test_numpy_dtypes.cpp
+1
-0
tests/test_numpy_dtypes.py
+9
-0
No files found.
include/pybind11/numpy.h
View file @
7edd72db
...
@@ -668,6 +668,9 @@ struct npy_format_descriptor<T, enable_if_t<is_pod_struct<T>::value>> {
...
@@ -668,6 +668,9 @@ struct npy_format_descriptor<T, enable_if_t<is_pod_struct<T>::value>> {
}
}
static
void
register_dtype
(
std
::
initializer_list
<
field_descriptor
>
fields
)
{
static
void
register_dtype
(
std
::
initializer_list
<
field_descriptor
>
fields
)
{
if
(
dtype_ptr
)
pybind11_fail
(
"NumPy: dtype is already registered"
);
list
names
,
formats
,
offsets
;
list
names
,
formats
,
offsets
;
for
(
auto
field
:
fields
)
{
for
(
auto
field
:
fields
)
{
if
(
!
field
.
descr
)
if
(
!
field
.
descr
)
...
...
tests/test_numpy_dtypes.cpp
View file @
7edd72db
...
@@ -335,6 +335,7 @@ test_initializer numpy_dtypes([](py::module &m) {
...
@@ -335,6 +335,7 @@ test_initializer numpy_dtypes([](py::module &m) {
m
.
def
(
"f_simple"
,
[](
SimpleStruct
s
)
{
return
s
.
y
*
10
;
});
m
.
def
(
"f_simple"
,
[](
SimpleStruct
s
)
{
return
s
.
y
*
10
;
});
m
.
def
(
"f_packed"
,
[](
PackedStruct
s
)
{
return
s
.
y
*
10
;
});
m
.
def
(
"f_packed"
,
[](
PackedStruct
s
)
{
return
s
.
y
*
10
;
});
m
.
def
(
"f_nested"
,
[](
NestedStruct
s
)
{
return
s
.
a
.
y
*
10
;
});
m
.
def
(
"f_nested"
,
[](
NestedStruct
s
)
{
return
s
.
a
.
y
*
10
;
});
m
.
def
(
"register_dtype"
,
[]()
{
PYBIND11_NUMPY_DTYPE
(
SimpleStruct
,
x
,
y
,
z
);
});
});
});
#undef PYBIND11_PACKED
#undef PYBIND11_PACKED
tests/test_numpy_dtypes.py
View file @
7edd72db
...
@@ -196,3 +196,12 @@ def test_scalar_conversion():
...
@@ -196,3 +196,12 @@ def test_scalar_conversion():
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
func
(
arr
[
0
])
func
(
arr
[
0
])
assert
'incompatible function arguments'
in
str
(
excinfo
.
value
)
assert
'incompatible function arguments'
in
str
(
excinfo
.
value
)
@pytest.requires_numpy
def
test_register_dtype
():
from
pybind11_tests
import
register_dtype
with
pytest
.
raises
(
RuntimeError
)
as
excinfo
:
register_dtype
()
assert
'dtype is already registered'
in
str
(
excinfo
.
value
)
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