Skip to content

Commit dc8f46d

Browse files
authored
MAINT: No need to check for check for FPEs in casts to/from object (#28358)
* MAINT: No need to check for check for FPEs in casts to/from object Since these go via Python (in some form) and Python doesn't use FPEs we can be sure that we don't need to check for FPEs. Note that while it hides *almost always* spurious FPEs seen on some platforms, there could be certain chains or multiple cast situations where FPEs are checked for other reasons and the spurious FPE will show up. So it "somewhat": Closes gh-28351 * MAINT: Follow-up, got the wrong place (the other is OK). * DOC: Add a small comment as per review request I don't think it needs a comment that we can do this, but maybe it is nice to say that there was a reason for it.
1 parent ae5121e commit dc8f46d

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

numpy/_core/src/multiarray/convert_datatype.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3507,7 +3507,9 @@ initialize_void_and_object_globals(void) {
35073507
method->nin = 1;
35083508
method->nout = 1;
35093509
method->name = "object_to_any_cast";
3510-
method->flags = NPY_METH_SUPPORTS_UNALIGNED | NPY_METH_REQUIRES_PYAPI;
3510+
method->flags = (NPY_METH_SUPPORTS_UNALIGNED
3511+
| NPY_METH_REQUIRES_PYAPI
3512+
| NPY_METH_NO_FLOATINGPOINT_ERRORS);
35113513
method->casting = NPY_UNSAFE_CASTING;
35123514
method->resolve_descriptors = &object_to_any_resolve_descriptors;
35133515
method->get_strided_loop = &object_to_any_get_loop;
@@ -3522,7 +3524,9 @@ initialize_void_and_object_globals(void) {
35223524
method->nin = 1;
35233525
method->nout = 1;
35243526
method->name = "any_to_object_cast";
3525-
method->flags = NPY_METH_SUPPORTS_UNALIGNED | NPY_METH_REQUIRES_PYAPI;
3527+
method->flags = (NPY_METH_SUPPORTS_UNALIGNED
3528+
| NPY_METH_REQUIRES_PYAPI
3529+
| NPY_METH_NO_FLOATINGPOINT_ERRORS);
35263530
method->casting = NPY_SAFE_CASTING;
35273531
method->resolve_descriptors = &any_to_object_resolve_descriptors;
35283532
method->get_strided_loop = &any_to_object_get_loop;

numpy/_core/src/multiarray/dtype_transfer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ any_to_object_get_loop(
235235
NpyAuxData **out_transferdata,
236236
NPY_ARRAYMETHOD_FLAGS *flags)
237237
{
238-
239-
*flags = NPY_METH_REQUIRES_PYAPI; /* No need for floating point errors */
238+
/* Python API doesn't use FPEs and this also attempts to hide spurious ones. */
239+
*flags = NPY_METH_REQUIRES_PYAPI | NPY_METH_NO_FLOATINGPOINT_ERRORS;
240240

241241
*out_loop = _strided_to_strided_any_to_object;
242242
*out_transferdata = PyMem_Malloc(sizeof(_any_to_object_auxdata));
@@ -342,7 +342,8 @@ object_to_any_get_loop(
342342
NpyAuxData **out_transferdata,
343343
NPY_ARRAYMETHOD_FLAGS *flags)
344344
{
345-
*flags = NPY_METH_REQUIRES_PYAPI;
345+
/* Python API doesn't use FPEs and this also attempts to hide spurious ones. */
346+
*flags = NPY_METH_REQUIRES_PYAPI | NPY_METH_NO_FLOATINGPOINT_ERRORS;
346347

347348
/* NOTE: auxdata is only really necessary to flag `move_references` */
348349
_object_to_any_auxdata *data = PyMem_Malloc(sizeof(*data));

0 commit comments

Comments
 (0)