array-api icon indicating copy to clipboard operation
array-api copied to clipboard

RFC: add `ravel()` (or `flatten()`)

Open asmeurer opened this issue 2 years ago • 2 comments

Should we have a ravel() or flatten() function? Right now you can do it with reshape, but it's maybe not obvious. reshape also has the advantage in that it can be explicit about copying.

If not, I wonder if we should have some page or documentation somewhere to indicate the best workarounds for NumPy functions that aren't included in the standard, like "replace ravel(x) with reshape(x, (x.size,))".

asmeurer avatar Jul 15 '23 16:07 asmeurer

If not, I wonder if we should have some page or documentation somewhere to indicate the best workarounds for NumPy functions that aren't included in the standard, like "replace ravel(x) with reshape(x, (x.size,))".

I'd prefer that - keeping the standard to one way of doing things. Such a page would be useful for many users. We may also add guidance for PyTorch/JAX/etc. users there as needed.

The question is where it should live. Maybe under the Other heading in the top-level structure (see https://data-apis.org/array-api/latest/index.html)?

rgommers avatar Jul 16 '23 10:07 rgommers

"replace ravel(x) with reshape(x, (x.size,))".

Correction. Should be "replace ravel(x) with reshape(x, (-1,))".

asmeurer avatar Jul 16 '23 14:07 asmeurer