ENH: Add is_dpnp_array & is_dpnp_namespace helper functions - #467
Open
Nin17 wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds and documents is_dpnp_array and is_dpnp_namespace helpers for dpnp support.
Changes:
- Implements and exports the new helpers.
- Extends dpnp-related tests and library registration.
- Updates README and API documentation.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Summary | Findings |
|---|---|---|
tests/test_common.py |
Adds dpnp helper and conversion tests. | None |
tests/test_array_namespace.py |
Adds dpnp namespace API-version cases. | None |
tests/_helpers.py |
Registers dpnp in shared tests. | Nit, 3 votes: dpnp is not installed in test jobs, so cases are skipped; add it to a test environment or remove it from the matrix. |
src/array_api_compat/common/_helpers.py |
Implements and exports dpnp helpers and type support. | Moderate, 2 votes: add dpnp to the optional-import mypy override or provide it in the type-check environment. |
README.md |
Documents dpnp support. | None |
docs/supported-array-libraries.md |
Documents dpnp support. | None |
docs/index.md |
Updates the supported-library summary. | None |
docs/helper-functions.rst |
Documents the new helpers. | None |
Suppressed comments (3)
src/array_api_compat/common/_helpers.py:53
- These types are now part of
_ArrayApiObj, but_is_lazy_clsstill has no dpnp branch. Thusis_lazy_array(dpnp.asarray([1, 2, 3]))falls through to the genericbool(x)probe; dpnp raises for multi-element truth values, which this helper interprets asTrue, misclassifying eager dpnp arrays as lazy unlike the NumPy/CuPy/Torch cases. Add both dpnp classes to the eager branch of_is_lazy_cls.
| dpnp.ndarray
| dpnp.tensor.usm_ndarray
src/array_api_compat/common/_helpers.py:286
- This public helper is annotated as plain
bool, unlike the otheris_*_arrayhelpers and the newly added_ArrayApiObjalternatives. Static type checkers therefore cannot narrowxafter a successful check, which defeats the typed inspection API; return aTypeIscovering both supported dpnp array classes.
def is_dpnp_array(x: object) -> bool:
tests/test_common.py:268
- This skip only covers dpnp as the source, but
target_libraryis also parametrized with dpnp. Cases such astorch -> dpnptherefore reachtgt_lib.asarray(a)and fail because dpnp's conversion path accepts USM/NumPy/buffer inputs, not these other array objects. Extend the skip to the target side (or limit the supported source types) so this matrix does not fail whenever dpnp is installed.
elif source_library == "dpnp" and target_library != "dpnp":
pytest.skip(reason="dpnp does not allow implicit conversion")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| if TYPE_CHECKING: | ||
| import cupy as cp | ||
| import dask.array as da | ||
| import dpnp |
| wrapped_libraries = ["numpy", "cupy", "torch", "dask.array"] | ||
| all_libraries = wrapped_libraries + [ | ||
| "array_api_strict", "jax.numpy", "ndonnx", "sparse" | ||
| "array_api_strict", "jax.numpy", "ndonnx", "sparse", "dpnp" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
is_dpnp_array&is_dpnp_namespacehelper functions: #442