Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: add diff for computing the n-th forward difference #784

Open
kgryte opened this issue Apr 4, 2024 · 1 comment · May be fixed by #791
Open

RFC: add diff for computing the n-th forward difference #784

kgryte opened this issue Apr 4, 2024 · 1 comment · May be fixed by #791
Labels
Accepted RFC feature request which has been accepted. RFC Request for comments. Feature requests and proposed changes.
Projects
Milestone

Comments

@kgryte
Copy link
Contributor

kgryte commented Apr 4, 2024

This RFC proposes the addition of a new API in the array API specification for computing the n-th forward difference along a specified dimension.

Overview

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

diff was originally discussed in #187 as a potential standardization candidate and has been requested by downstream libraries, such as xarray.

Prior art

Proposal

def diff(x: array, /, *, n: int = 1, axis: int = -1, prepend = Optional[array], append = Optional[array]) -> array

Questions

  • NumPy supports prepend and append as scalar values and subsequently wraps using asarray. Are we okay limiting to only arrays within the specification? Libraries, such as NumPy, would be free to accept scalars; this would just not be considered portable behavior.
  • Apart from scalars, NumPy requires that prepend and append arrays match the shape of x except along the specified axis, thus precluding broadcasting. Is there ever a situation in which broadcasting would make sense?
  • The output array must have the same dtype as the input array. Consequently, when x has a boolean dtype, the output array must also have a boolean dtype. Similarly, unsigned integer input arrays result in unsigned integer output arrays. Are we okay requiring that diff support boolean and unsigned integer dtypes? Or should we limit portable behavior to floating-point (real and complex) and signed integers?
@kgryte kgryte added RFC Request for comments. Feature requests and proposed changes. Needs Discussion Needs further discussion. labels Apr 4, 2024
@kgryte kgryte added this to the v2024 milestone Apr 4, 2024
@kgryte kgryte added this to Stage 0 in Proposals Apr 4, 2024
@rgommers
Copy link
Member

rgommers commented Apr 4, 2024

Are we okay limiting to only arrays within the specification?

That seems fine to me. prepend/append are rarely used, so there doesn't seem a need to make this really flexible.

Is there ever a situation in which broadcasting would make sense?

I don't see it in SciPy, nor can I think of a real need for this.

Or should we limit portable behavior to floating-point (real and complex) and signed integers?

This sounds good to me.

kgryte added a commit to kgryte/array-api that referenced this issue Apr 18, 2024
@kgryte kgryte linked a pull request Apr 18, 2024 that will close this issue
@kgryte kgryte added Accepted RFC feature request which has been accepted. and removed Needs Discussion Needs further discussion. labels Apr 18, 2024
@kgryte kgryte moved this from Stage 0 to Stage 1 in Proposals Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accepted RFC feature request which has been accepted. RFC Request for comments. Feature requests and proposed changes.
Projects
Proposals
Stage 1
Development

Successfully merging a pull request may close this issue.

2 participants