Skip to content

ENH: Add is_dpnp_array & is_dpnp_namespace helper functions - #467

Open
Nin17 wants to merge 1 commit into
data-apis:mainfrom
Nin17:dpnp
Open

ENH: Add is_dpnp_array & is_dpnp_namespace helper functions#467
Nin17 wants to merge 1 commit into
data-apis:mainfrom
Nin17:dpnp

Conversation

@Nin17

@Nin17 Nin17 commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Add is_dpnp_array & is_dpnp_namespace helper functions: #442

Copilot AI lite review requested due to automatic review settings August 21, 2026 12:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_cls still has no dpnp branch. Thus is_lazy_array(dpnp.asarray([1, 2, 3])) falls through to the generic bool(x) probe; dpnp raises for multi-element truth values, which this helper interprets as True, 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 other is_*_array helpers and the newly added _ArrayApiObj alternatives. Static type checkers therefore cannot narrow x after a successful check, which defeats the typed inspection API; return a TypeIs covering 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_library is also parametrized with dpnp. Cases such as torch -> dpnp therefore reach tgt_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
Comment thread tests/_helpers.py
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"
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.

2 participants