Closed
Description
This RFC requests to include a new API in the array API specification for the purpose of returning a value with the magnitude of x
but the sign of y
.
Overview
Based on array comparison data, the API is available in the majority of libraries in the PyData ecosystem.
The Array API specification does not currently include a convenient method of copying the sign from one value to another value via the IEEE 754 function copysign
. This function is commonly used in the implementations of transcendental functions involving argument reductions.
While this can be implemented in terms of where
, doing so is overly cumbersome.
Prior art
- C99: https://en.cppreference.com/w/c/numeric/math/copysign
- NumPy: https://numpy.org/doc/stable/reference/generated/numpy.copysign.html
- PyTorch: https://pytorch.org/docs/stable/generated/torch.copysign.html
- MXNet: https://mxnet.apache.org/versions/master/api/python/docs/api/np/generated/mxnet.np.copysign.html#mxnet.np.copysign
Proposal:
def copysign(x1: array, x2:array, /) -> array
cc @kgryte
Metadata
Metadata
Assignees
Type
Projects
Status
Stage 2
Activity
rgommers commentedon Feb 15, 2023
This seems like a reasonable addition. Do TensorFlow and MXNet have alternatives or open feature requests?
kgryte commentedon Feb 23, 2023
MXNet does have a
copysign
function. TF is the odd one out and does not appear to have acopysign
API even in its experimental NumPy namespace.asmeurer commentedon Aug 1, 2023
I don't know if this can actually be replicated with
where
because of-0.0
.copysign
to the specification #693