Skip to content

Commit b00ac41

Browse files
authored
Merge pull request #409 from ev-br/copilot_spec_cases_unary
ENH: parse complex special cases from stubs of unary functions
2 parents 3249a73 + 45e566d commit b00ac41

File tree

3 files changed

+344
-8
lines changed

3 files changed

+344
-8
lines changed

array-api-strict-skips.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,21 @@ array_api_tests/test_data_type_functions.py::test_finfo
3232
array_api_tests/test_data_type_functions.py::test_finfo_dtype
3333
array_api_tests/test_data_type_functions.py::test_iinfo
3434
array_api_tests/test_data_type_functions.py::test_iinfo_dtype
35+
36+
37+
# complex special cases which failed "forever"
38+
array_api_tests/test_special_cases.py::test_unary[expm1(real(x_i) is +infinity and imag(x_i) is +0) -> +infinity + 0j]
39+
array_api_tests/test_special_cases.py::test_unary[expm1(real(x_i) is -infinity and imag(x_i) is +infinity) -> -1 + 0j]
40+
array_api_tests/test_special_cases.py::test_unary[expm1(real(x_i) is +infinity and imag(x_i) is +infinity) -> infinity + NaN j]
41+
array_api_tests/test_special_cases.py::test_unary[expm1(real(x_i) is -infinity and imag(x_i) is NaN) -> -1 + 0j]
42+
array_api_tests/test_special_cases.py::test_unary[expm1(real(x_i) is +infinity and imag(x_i) is NaN) -> infinity + NaN j]
43+
array_api_tests/test_special_cases.py::test_unary[expm1(real(x_i) is NaN and imag(x_i) is +0) -> NaN + 0j]
44+
array_api_tests/test_special_cases.py::test_unary[expm1((real(x_i) is +0 or real(x_i) == -0) and imag(x_i) is +0) -> 0 + 0j]
45+
46+
array_api_tests/test_special_cases.py::test_unary[sign((real(x_i) is -0 or real(x_i) == +0) and (imag(x_i) is -0 or imag(x_i) == +0)) -> 0 + 0j]
47+
array_api_tests/test_special_cases.py::test_unary[tanh(real(x_i) is +infinity and isfinite(imag(x_i)) and imag(x_i) > 0) -> 1 + 0j]
48+
49+
# this acosh failure is only seen with python==3.10 and numpy==2.2.6, and not e.g. python 3.12 & numpy 2.4.1
50+
array_api_tests/test_special_cases.py::test_unary[acosh(real(x_i) is +0 and imag(x_i) is NaN) -> NaN \xb1 \u03c0j/2]
51+
52+
array_api_tests/test_special_cases.py::test_unary[sqrt(real(x_i) is +infinity and isfinite(imag(x_i)) and imag(x_i) > 0) -> +0 + infinity j]

array_api_tests/dtype_helpers.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,39 @@ def is_scalar(x):
199199
return isinstance(x, (int, float, complex, bool))
200200

201201

202+
def complex_dtype_for(dtyp):
203+
"""Complex dtype for a float or complex."""
204+
if dtyp in complex_dtypes:
205+
return dtyp
206+
if dtyp not in real_float_dtypes:
207+
raise ValueError(f"no complex dtype to match {dtyp}")
208+
209+
real_name = dtype_to_name[dtyp]
210+
complex_name = {"float32": "complex64", "float64": "complex128"}[real_name]
211+
212+
complex_dtype = _name_to_dtype.get(complex_name, None)
213+
if complex_dtype is None:
214+
raise ValueError(f"no complex dtype to match {dtyp}")
215+
return complex_dtype
216+
217+
218+
def real_dtype_for(dtyp):
219+
"""Real float dtype for a float or complex."""
220+
if dtyp in real_float_dtypes:
221+
return dtyp
222+
if dtyp not in complex_dtypes:
223+
raise ValueError(f"no real float dtype to match {dtyp}")
224+
225+
complex_name = dtype_to_name[dtyp]
226+
real_name = {"complex64": "float32", "complex128": "float64"}[complex_name]
227+
228+
real_dtype = _name_to_dtype.get(real_name, None)
229+
if real_dtype is None:
230+
raise ValueError(f"no real dtype to match {dtyp}")
231+
return real_dtype
232+
233+
234+
202235
def _make_dtype_mapping_from_names(mapping: Dict[str, Any]) -> EqualityMapping:
203236
dtype_value_pairs = []
204237
for name, value in mapping.items():

0 commit comments

Comments
 (0)