Skip to content

Commit e9a289c

Browse files
committed
pytest-compatible access to np.float128, np.complex256
1 parent d9e3bd3 commit e9a289c

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

tests/test_buffers.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010

1111
np = pytest.importorskip("numpy")
1212

13-
if m.std_is_same_double_long_double: # Windows.
14-
np_float128 = None
15-
np_complex256 = None
16-
else:
17-
np_float128 = np.float128
18-
np_complex256 = np.complex256
13+
14+
def np_dtype_long_double_or_none(name):
15+
# Intentionally not using getattr(np, name, None), to be strict.
16+
if m.std_is_same_double_long_double: # Windows.
17+
return None
18+
return getattr(np, name)
19+
1920

2021
CPP_NAME_FORMAT_NP_DTYPE_TABLE = [
2122
item
@@ -32,10 +33,10 @@
3233
("std::uint64_t", "Q", np.uint64),
3334
("float", "f", np.float32),
3435
("double", "d", np.float64),
35-
("long double", "g", np_float128),
36+
("long double", "g", np_dtype_long_double_or_none("float128")),
3637
("std::complex<float>", "Zf", np.complex64),
3738
("std::complex<double>", "Zd", np.complex128),
38-
("std::complex<long double>", "Zg", np_complex256),
39+
("std::complex<long double>", "Zg", np_dtype_long_double_or_none("complex256")),
3940
]
4041
if item[-1] is not None
4142
]

0 commit comments

Comments
 (0)