Skip to content

Add ndarray subclassing support via ndarray.view() method#2815

Open
antonwolfy wants to merge 4 commits intomasterfrom
resolve-gh-2764
Open

Add ndarray subclassing support via ndarray.view() method#2815
antonwolfy wants to merge 4 commits intomasterfrom
resolve-gh-2764

Conversation

@antonwolfy
Copy link
Contributor

@antonwolfy antonwolfy commented Mar 11, 2026

The PR adds ndarray subclassing support via ndarray.view() method.

It implements the type parameter in dpnp.ndarray.view() to enable custom subclasses, matching NumPy/CuPy behavior. Also includes proper __array_finalize__ hook invocation for metadata propagation.

The implementation is done through _view_impl() helper using 'array_class' parameter to avoid shadowing builtin 'type'.
The tests scope is extended with new 7 tests for verifying subclassing support and enabling TestSubclassArrayView class from third party tests.

This PR closes #2764.

  • Have you provided a meaningful PR description?
  • Have you added a test, reproducer or referred to an issue with a reproducer?
  • Have you tested your changes locally for CPU and GPU devices?
  • Have you made sure that new changes do not introduce compiler warnings?
  • Have you checked performance impact of proposed changes?
  • Have you added documentation for your changes, if necessary?
  • Have you added your changes to the changelog?

@antonwolfy antonwolfy added this to the 0.20.0 release milestone Mar 11, 2026
@antonwolfy antonwolfy self-assigned this Mar 11, 2026
@github-actions
Copy link
Contributor

View rendered docs @ https://intelpython.github.io/dpnp/pull/2815/index.html

@github-actions
Copy link
Contributor

Array API standard conformance tests for dpnp=0.20.0dev4=py313h509198e_5 ran successfully.
Passed: 1356
Failed: 1
Skipped: 16

@coveralls
Copy link
Collaborator

Coverage Status

coverage: 81.186% (+0.02%) from 81.17%
when pulling 919d737 on resolve-gh-2764
into 4b64466 on master.

@antonwolfy antonwolfy marked this pull request as ready for review March 11, 2026 19:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for ndarray subclassing via view(type=...)

2 participants