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
22b25040
Commit
22b25040
authored
May 14, 2020
by
Sergei Izmailov
Committed by
Wenzel Jakob
Jun 10, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Render full numpy numeric names (e.g. numpy.int32)
parent
63df87fa
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
32 deletions
+36
-32
include/pybind11/numpy.h
+3
-3
tests/test_eigen.py
+19
-15
tests/test_numpy_array.py
+9
-9
tests/test_numpy_vectorize.py
+5
-5
No files found.
include/pybind11/numpy.h
View file @
22b25040
...
@@ -1007,14 +1007,14 @@ struct npy_format_descriptor_name;
...
@@ -1007,14 +1007,14 @@ struct npy_format_descriptor_name;
template
<
typename
T
>
template
<
typename
T
>
struct
npy_format_descriptor_name
<
T
,
enable_if_t
<
std
::
is_integral
<
T
>::
value
>>
{
struct
npy_format_descriptor_name
<
T
,
enable_if_t
<
std
::
is_integral
<
T
>::
value
>>
{
static
constexpr
auto
name
=
_
<
std
::
is_same
<
T
,
bool
>::
value
>
(
static
constexpr
auto
name
=
_
<
std
::
is_same
<
T
,
bool
>::
value
>
(
_
(
"bool"
),
_
<
std
::
is_signed
<
T
>::
value
>
(
"
int"
,
"
uint"
)
+
_
<
sizeof
(
T
)
*
8
>
()
_
(
"bool"
),
_
<
std
::
is_signed
<
T
>::
value
>
(
"
numpy.int"
,
"numpy.
uint"
)
+
_
<
sizeof
(
T
)
*
8
>
()
);
);
};
};
template
<
typename
T
>
template
<
typename
T
>
struct
npy_format_descriptor_name
<
T
,
enable_if_t
<
std
::
is_floating_point
<
T
>::
value
>>
{
struct
npy_format_descriptor_name
<
T
,
enable_if_t
<
std
::
is_floating_point
<
T
>::
value
>>
{
static
constexpr
auto
name
=
_
<
std
::
is_same
<
T
,
float
>::
value
||
std
::
is_same
<
T
,
double
>::
value
>
(
static
constexpr
auto
name
=
_
<
std
::
is_same
<
T
,
float
>::
value
||
std
::
is_same
<
T
,
double
>::
value
>
(
_
(
"
float"
)
+
_
<
sizeof
(
T
)
*
8
>
(),
_
(
"
longdouble"
)
_
(
"
numpy.float"
)
+
_
<
sizeof
(
T
)
*
8
>
(),
_
(
"numpy.
longdouble"
)
);
);
};
};
...
@@ -1022,7 +1022,7 @@ template <typename T>
...
@@ -1022,7 +1022,7 @@ template <typename T>
struct
npy_format_descriptor_name
<
T
,
enable_if_t
<
is_complex
<
T
>::
value
>>
{
struct
npy_format_descriptor_name
<
T
,
enable_if_t
<
is_complex
<
T
>::
value
>>
{
static
constexpr
auto
name
=
_
<
std
::
is_same
<
typename
T
::
value_type
,
float
>::
value
static
constexpr
auto
name
=
_
<
std
::
is_same
<
typename
T
::
value_type
,
float
>::
value
||
std
::
is_same
<
typename
T
::
value_type
,
double
>::
value
>
(
||
std
::
is_same
<
typename
T
::
value_type
,
double
>::
value
>
(
_
(
"
complex"
)
+
_
<
sizeof
(
typename
T
::
value_type
)
*
16
>
(),
_
(
"
longcomplex"
)
_
(
"
numpy.complex"
)
+
_
<
sizeof
(
typename
T
::
value_type
)
*
16
>
(),
_
(
"numpy.
longcomplex"
)
);
);
};
};
...
...
tests/test_eigen.py
View file @
22b25040
...
@@ -79,15 +79,17 @@ def test_mutator_descriptors():
...
@@ -79,15 +79,17 @@ def test_mutator_descriptors():
m
.
fixed_mutator_a
(
zc
)
m
.
fixed_mutator_a
(
zc
)
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
m
.
fixed_mutator_r
(
zc
)
m
.
fixed_mutator_r
(
zc
)
assert
(
'(arg0: numpy.ndarray[float32[5, 6], flags.writeable, flags.c_contiguous]) -> None'
assert
(
'(arg0: numpy.ndarray[numpy.float32[5, 6],'
' flags.writeable, flags.c_contiguous]) -> None'
in
str
(
excinfo
.
value
))
in
str
(
excinfo
.
value
))
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
m
.
fixed_mutator_c
(
zr
)
m
.
fixed_mutator_c
(
zr
)
assert
(
'(arg0: numpy.ndarray[float32[5, 6], flags.writeable, flags.f_contiguous]) -> None'
assert
(
'(arg0: numpy.ndarray[numpy.float32[5, 6],'
' flags.writeable, flags.f_contiguous]) -> None'
in
str
(
excinfo
.
value
))
in
str
(
excinfo
.
value
))
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
with
pytest
.
raises
(
TypeError
)
as
excinfo
:
m
.
fixed_mutator_a
(
np
.
array
([[
1
,
2
],
[
3
,
4
]],
dtype
=
'float32'
))
m
.
fixed_mutator_a
(
np
.
array
([[
1
,
2
],
[
3
,
4
]],
dtype
=
'float32'
))
assert
(
'(arg0: numpy.ndarray[float32[5, 6], flags.writeable]) -> None'
assert
(
'(arg0: numpy.ndarray[
numpy.
float32[5, 6], flags.writeable]) -> None'
in
str
(
excinfo
.
value
))
in
str
(
excinfo
.
value
))
zr
.
flags
.
writeable
=
False
zr
.
flags
.
writeable
=
False
with
pytest
.
raises
(
TypeError
):
with
pytest
.
raises
(
TypeError
):
...
@@ -179,7 +181,7 @@ def test_negative_stride_from_python(msg):
...
@@ -179,7 +181,7 @@ def test_negative_stride_from_python(msg):
m
.
double_threer
(
second_row
)
m
.
double_threer
(
second_row
)
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
double_threer(): incompatible function arguments. The following argument types are supported:
double_threer(): incompatible function arguments. The following argument types are supported:
1. (arg0: numpy.ndarray[float32[1, 3], flags.writeable]) -> None
1. (arg0: numpy.ndarray[
numpy.
float32[1, 3], flags.writeable]) -> None
Invoked with: """
+
repr
(
np
.
array
([
5.
,
4.
,
3.
],
dtype
=
'float32'
))
# noqa: E501 line too long
Invoked with: """
+
repr
(
np
.
array
([
5.
,
4.
,
3.
],
dtype
=
'float32'
))
# noqa: E501 line too long
...
@@ -187,7 +189,7 @@ def test_negative_stride_from_python(msg):
...
@@ -187,7 +189,7 @@ def test_negative_stride_from_python(msg):
m
.
double_threec
(
second_col
)
m
.
double_threec
(
second_col
)
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
double_threec(): incompatible function arguments. The following argument types are supported:
double_threec(): incompatible function arguments. The following argument types are supported:
1. (arg0: numpy.ndarray[float32[3, 1], flags.writeable]) -> None
1. (arg0: numpy.ndarray[
numpy.
float32[3, 1], flags.writeable]) -> None
Invoked with: """
+
repr
(
np
.
array
([
7.
,
4.
,
1.
],
dtype
=
'float32'
))
# noqa: E501 line too long
Invoked with: """
+
repr
(
np
.
array
([
7.
,
4.
,
1.
],
dtype
=
'float32'
))
# noqa: E501 line too long
...
@@ -607,17 +609,19 @@ def test_special_matrix_objects():
...
@@ -607,17 +609,19 @@ def test_special_matrix_objects():
def
test_dense_signature
(
doc
):
def
test_dense_signature
(
doc
):
assert
doc
(
m
.
double_col
)
==
"""
assert
doc
(
m
.
double_col
)
==
"""
double_col(arg0: numpy.ndarray[
float32[m, 1]]) -> numpy.ndarray[
float32[m, 1]]
double_col(arg0: numpy.ndarray[
numpy.float32[m, 1]]) -> numpy.ndarray[numpy.
float32[m, 1]]
"""
"""
assert
doc
(
m
.
double_row
)
==
"""
assert
doc
(
m
.
double_row
)
==
"""
double_row(arg0: numpy.ndarray[float32[1, n]]) -> numpy.ndarray[float32[1, n]]
double_row(arg0: numpy.ndarray[numpy.float32[1, n]]) -> numpy.ndarray[numpy.float32[1, n]]
"""
assert
doc
(
m
.
double_complex
)
==
"""
double_complex(arg0: numpy.ndarray[complex64[m, 1]]) -> numpy.ndarray[complex64[m, 1]]
"""
assert
doc
(
m
.
double_mat_rm
)
==
"""
double_mat_rm(arg0: numpy.ndarray[float32[m, n]]) -> numpy.ndarray[float32[m, n]]
"""
"""
assert
doc
(
m
.
double_complex
)
==
(
"""
double_complex(arg0: numpy.ndarray[numpy.complex64[m, 1]])"""
""" -> numpy.ndarray[numpy.complex64[m, 1]]
"""
)
assert
doc
(
m
.
double_mat_rm
)
==
(
"""
double_mat_rm(arg0: numpy.ndarray[numpy.float32[m, n]])"""
""" -> numpy.ndarray[numpy.float32[m, n]]
"""
)
def
test_named_arguments
():
def
test_named_arguments
():
...
@@ -654,10 +658,10 @@ def test_sparse():
...
@@ -654,10 +658,10 @@ def test_sparse():
@pytest.requires_eigen_and_scipy
@pytest.requires_eigen_and_scipy
def
test_sparse_signature
(
doc
):
def
test_sparse_signature
(
doc
):
assert
doc
(
m
.
sparse_copy_r
)
==
"""
assert
doc
(
m
.
sparse_copy_r
)
==
"""
sparse_copy_r(arg0: scipy.sparse.csr_matrix[
float32]) -> scipy.sparse.csr_matrix[
float32]
sparse_copy_r(arg0: scipy.sparse.csr_matrix[
numpy.float32]) -> scipy.sparse.csr_matrix[numpy.
float32]
"""
# noqa: E501 line too long
"""
# noqa: E501 line too long
assert
doc
(
m
.
sparse_copy_c
)
==
"""
assert
doc
(
m
.
sparse_copy_c
)
==
"""
sparse_copy_c(arg0: scipy.sparse.csc_matrix[
float32]) -> scipy.sparse.csc_matrix[
float32]
sparse_copy_c(arg0: scipy.sparse.csc_matrix[
numpy.float32]) -> scipy.sparse.csc_matrix[numpy.
float32]
"""
# noqa: E501 line too long
"""
# noqa: E501 line too long
...
...
tests/test_numpy_array.py
View file @
22b25040
...
@@ -286,13 +286,13 @@ def test_overload_resolution(msg):
...
@@ -286,13 +286,13 @@ def test_overload_resolution(msg):
m
.
overloaded
(
"not an array"
)
m
.
overloaded
(
"not an array"
)
assert
msg
(
excinfo
.
value
)
==
"""
assert
msg
(
excinfo
.
value
)
==
"""
overloaded(): incompatible function arguments. The following argument types are supported:
overloaded(): incompatible function arguments. The following argument types are supported:
1. (arg0: numpy.ndarray[float64]) -> str
1. (arg0: numpy.ndarray[
numpy.
float64]) -> str
2. (arg0: numpy.ndarray[float32]) -> str
2. (arg0: numpy.ndarray[
numpy.
float32]) -> str
3. (arg0: numpy.ndarray[int32]) -> str
3. (arg0: numpy.ndarray[
numpy.
int32]) -> str
4. (arg0: numpy.ndarray[uint16]) -> str
4. (arg0: numpy.ndarray[
numpy.
uint16]) -> str
5. (arg0: numpy.ndarray[int64]) -> str
5. (arg0: numpy.ndarray[
numpy.
int64]) -> str
6. (arg0: numpy.ndarray[complex128]) -> str
6. (arg0: numpy.ndarray[
numpy.
complex128]) -> str
7. (arg0: numpy.ndarray[complex64]) -> str
7. (arg0: numpy.ndarray[
numpy.
complex64]) -> str
Invoked with: 'not an array'
Invoked with: 'not an array'
"""
"""
...
@@ -307,8 +307,8 @@ def test_overload_resolution(msg):
...
@@ -307,8 +307,8 @@ def test_overload_resolution(msg):
assert
m
.
overloaded3
(
np
.
array
([
1
],
dtype
=
'intc'
))
==
'int'
assert
m
.
overloaded3
(
np
.
array
([
1
],
dtype
=
'intc'
))
==
'int'
expected_exc
=
"""
expected_exc
=
"""
overloaded3(): incompatible function arguments. The following argument types are supported:
overloaded3(): incompatible function arguments. The following argument types are supported:
1. (arg0: numpy.ndarray[int32]) -> str
1. (arg0: numpy.ndarray[
numpy.
int32]) -> str
2. (arg0: numpy.ndarray[float64]) -> str
2. (arg0: numpy.ndarray[
numpy.
float64]) -> str
Invoked with: """
Invoked with: """
...
...
tests/test_numpy_vectorize.py
View file @
22b25040
...
@@ -109,7 +109,7 @@ def test_type_selection():
...
@@ -109,7 +109,7 @@ def test_type_selection():
def
test_docs
(
doc
):
def
test_docs
(
doc
):
assert
doc
(
m
.
vectorized_func
)
==
"""
assert
doc
(
m
.
vectorized_func
)
==
"""
vectorized_func(arg0: numpy.ndarray[
int32], arg1: numpy.ndarray[float32], arg2: numpy.ndarray[
float64]) -> object
vectorized_func(arg0: numpy.ndarray[
numpy.int32], arg1: numpy.ndarray[numpy.float32], arg2: numpy.ndarray[numpy.
float64]) -> object
"""
# noqa: E501 line too long
"""
# noqa: E501 line too long
...
@@ -160,12 +160,12 @@ def test_passthrough_arguments(doc):
...
@@ -160,12 +160,12 @@ def test_passthrough_arguments(doc):
assert
doc
(
m
.
vec_passthrough
)
==
(
assert
doc
(
m
.
vec_passthrough
)
==
(
"vec_passthrough("
+
", "
.
join
([
"vec_passthrough("
+
", "
.
join
([
"arg0: float"
,
"arg0: float"
,
"arg1: numpy.ndarray[float64]"
,
"arg1: numpy.ndarray[
numpy.
float64]"
,
"arg2: numpy.ndarray[float64]"
,
"arg2: numpy.ndarray[
numpy.
float64]"
,
"arg3: numpy.ndarray[int32]"
,
"arg3: numpy.ndarray[
numpy.
int32]"
,
"arg4: int"
,
"arg4: int"
,
"arg5: m.numpy_vectorize.NonPODClass"
,
"arg5: m.numpy_vectorize.NonPODClass"
,
"arg6: numpy.ndarray[float64]"
])
+
") -> object"
)
"arg6: numpy.ndarray[
numpy.
float64]"
])
+
") -> object"
)
b
=
np
.
array
([[
10
,
20
,
30
]],
dtype
=
'float64'
)
b
=
np
.
array
([[
10
,
20
,
30
]],
dtype
=
'float64'
)
c
=
np
.
array
([
100
,
200
])
# NOT a vectorized argument
c
=
np
.
array
([
100
,
200
])
# NOT a vectorized argument
...
...
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