Skip to content

Add copysign function to the standard #593

Closed
@steff456

Description

@steff456
Member

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

Proposal:

def copysign(x1: array, x2:array, /) -> array

cc @kgryte

Activity

rgommers

rgommers commented on Feb 15, 2023

@rgommers
Member

This seems like a reasonable addition. Do TensorFlow and MXNet have alternatives or open feature requests?

kgryte

kgryte commented on Feb 23, 2023

@kgryte
Contributor

MXNet does have a copysign function. TF is the odd one out and does not appear to have a copysign API even in its experimental NumPy namespace.

asmeurer

asmeurer commented on Aug 1, 2023

@asmeurer
Member

I don't know if this can actually be replicated with where because of -0.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    API extensionAdds new functions or objects to the API.

    Type

    No type

    Projects

    Status

    Stage 2

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @asmeurer@rgommers@kgryte@steff456

      Issue actions

        Add `copysign` function to the standard · Issue #593 · data-apis/array-api