cupy / cupy/cupy

Use NumPy functions: `normalize_axis_index`, `normalize_axis_tuple`

Open
#4,522 1 comment 1 reaction 0 assignees View on GitHub
cat:code-fix st:needs-discussion
Dominant language
Python
Stars
12.3k
Forks
1.1k
Avg merge
1d 20h
Merged PRs (30d)
45

Description

The functions `normalize_axis_index`, `normalize_axis_tuple` are not documented, but the author says
> When I added this function, it was always my intent for it to be consumed by downstream packages, but as Sebastian remarks, it wasn't really desirable to put it in the top-level namespace.
>
> I think I would be reasonably happy to make the guarantee that it would not be removed (or more likely, moved) without a lengthy deprecation cycle.
>
> Perhaps worth opening a github issue, so we can keep track of how many downstream projects are already using it.

http://numpy-discussion.10968.n7.nabble.com/Is-numpy-lib-shape-base-normalize-axis-index-considered-part-of-the-public-API-td48016.html#a48020

- SciPy uses `normalize_axis_index` but does not use `normalize_axis_tuple`.
- Dask uses `normalize_axis_index` and `normalize_axis_tuple`, while they are adapted directly from NumPy.
https://github.com/dask/dask/blob/2020.12.0/dask/array/numpy_compat.py

The scope of the issue is Python-level. CuPy should keep own Cython (`cdef`) implementations for performance, like NumPy has C implementations, too.

Contributor guide

Open the contributing guide

Research direction

Start by comparing NumPy's normalize_axis_index and normalize_axis_tuple with the Python-level CuPy API, then review Dask's dask/array/numpy_compat.py usage. Done means the requested Python-level CuPy functions are available for downstream packages and documented, while the existing Cython implementations remain in place for performance.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
api
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.