data-apis / array-api

RFC document, tooling and other content related to the array API standard
https://data-apis.github.io/array-api/latest/
MIT License
204 stars 42 forks source link

RFC: add `reciprocal` for computing the element-wise reciprocal #790

Open kgryte opened 2 months ago

kgryte commented 2 months ago

This RFC proposes the addition of a new API in the array API specification for computing the element-wise reciprocal.

Overview

Based on array comparison data, the API is available across all major array libraries in the PyData ecosystem.

reciprocal was originally identified in https://github.com/data-apis/array-api/issues/187 as a potential standardization candidate and has been mentioned by downstream libraries (see Intheon case study).

Prior art

Proposal

def reciprocal(x: array, /) -> array

Questions

rgommers commented 2 months ago

@oleksandr-pavlyk's comment that this is useful also to avoid dealing with moving a Python scalar to GPU/accelerator if it's written as 1/x and that's why it was added to dpctl seems like an additional reason to do this.

So +1 for adding this, with "should" for floating-point types only (as suggested). That way it's a straightforward signal that this is portable, without placing a new implementation burden on any known library.

kgryte commented 2 months ago

PR is up: https://github.com/data-apis/array-api/pull/802