cupy / cupy/cupy

Refactor the way ndarray methods are implemented

Open
#2,800 1 comment 0 reactions 0 assignees View on GitHub
prio:low
Dominant language
Python
Stars
12.3k
Forks
1.1k
Avg merge
1d 20h
Merged PRs (30d)
45

Description

Currently routines implementations that have interfaces both as a module-level function and as a `ndarray` method (e.g. `cupy.std` and `ndarray.std`) are implemented in such a way that the main code is implemented in the `ndarray` method and it is called by the module-level counterpart.

I think it's better to reverse it, so that `ndarray` method calls the other.

Benefits:
* Simplifies `core.pyx` where `ndarray` is defind.
* Reduced cython module dependencies: I think it does not make sense for `core.pyx` to have a dependency to `_routines_statistics.pyx`.
* Reduced cython compilation because they can be implemented in `.py`. We can still choose to keep performance-critical functions (if any) in Cython code.

**(edit)** Originally wrote `sort` as an example but it was not a good example because `ndarray.sort` behaves in in-place manner in contrast to `cupy.sort`.

Contributor guide

Open the contributing guide

Research direction

Start by comparing the implementations of cupy.std and ndarray.std, then inspect core.pyx and _routines_statistics.pyx to understand the current dependency. Check which other routines expose both interfaces and whether sort is excluded because its methods differ in-place behavior. Done means the chosen methods delegate in the proposed direction without changing their behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.