Skip to content

ENH: Add is_dpnp_array & is_dpnp_namespace helper functions - #467

Merged
ev-br merged 1 commit into
data-apis:mainfrom
Nin17:dpnp
Aug 24, 2026
Merged

ENH: Add is_dpnp_array & is_dpnp_namespace helper functions#467
ev-br merged 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"

@ev-br ev-br left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Am going to trust you on dpnp details (usm_array, dpnp.tensor namespace).
LGTM otherwise.
Thank you @Nin17

@ev-br
ev-br merged commit 76ad14a into data-apis:main Aug 24, 2026
28 checks passed
@ev-br ev-br added this to the 1.16 milestone Aug 24, 2026
@Nin17

Nin17 commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

This is the documentation for the dpnp.tensor namespace.

This is the result I get for running array-api-test 2025.12 tests against dpnp.tensor, it has errors for lacking the linalg and fft extensions, the test_dunder_dlpack error that's also present in the main dpnp namespace and an error for test_can_cast.

======================================== short test summary info ========================================
FAILED array_api_tests/test_data_type_functions.py::test_can_cast - AssertionError: out=False, but should be True [can_cast(complex64, float64)]
FAILED array_api_tests/test_dlpack.py::test_dunder_dlpack - BufferError: array cannot be placed on the requested device without a copy
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-cholesky] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-cross] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-det] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-diagonal] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-eigh] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-eigvalsh] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-inv] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-matmul] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-matrix_norm] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-matrix_power] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-matrix_rank] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-matrix_transpose] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-outer] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-pinv] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-qr] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-slogdet] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-solve] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-svd] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-svdvals] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-tensordot] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-trace] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-vecdot] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[linalg-vector_norm] - AttributeError: module 'dpnp.tensor' has no attribute 'linalg'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-fft] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-ifft] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-fftn] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-ifftn] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-rfft] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-irfft] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-rfftn] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-irfftn] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-hfft] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-ihfft] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-fftfreq] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-rfftfreq] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-fftshift] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
FAILED array_api_tests/test_has_names.py::test_has_names[fft-ifftshift] - AttributeError: module 'dpnp.tensor' has no attribute 'fft'
================= 39 failed, 1330 passed, 84 skipped, 63 warnings in 189.58s (0:03:09) ==================

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.

3 participants