Skip to content

Fall back bool/int64/uint64/float64 to supported dtypes with a warning - #6

Open
haesleinhuepf with Copilot wants to merge 2 commits into
mainfrom
copilot/support-array-api-dtypes
Open

Fall back bool/int64/uint64/float64 to supported dtypes with a warning#6
haesleinhuepf with Copilot wants to merge 2 commits into
mainfrom
copilot/support-array-api-dtypes

Conversation

Copilot AI commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

pyclesperanto doesn't natively support bool, int64, uint64, or float64. Previously, passing these dtypes raised TypeError, breaking Array API compliance. Per maintainer guidance, the fix is a silent-downcast-with-warning strategy rather than hard rejection.

Changes

  • _dtypes.py — adds DTYPE_FALLBACKS mapping unsupported → nearest supported dtype (bool→int8, int64→int32, uint64→uint32, float64→float32). require_supported() now emits a UserWarning and returns the fallback instead of raising.
  • __init__.py / _from_host() — casts the host NumPy array to the resolved dtype before the device push, so the buffer type matches when the backend ignores the dtype kwarg.
  • test_creation.py — replaces the "rejects unsupported dtype" test with one that asserts the warning is emitted and the array carries the fallback dtype.
import warnings
import oclpy as xp

with warnings.catch_warnings(record=True) as w:
    warnings.simplefilter("always")
    arr = xp.asarray([3.14], dtype=xp.float64)
    # UserWarning: dtype float64 is not supported by pyclesperanto; falling back to float32

assert arr.dtype == xp.float32

bool→int8, int64→int32, uint64→uint32, float64→float32.
require_supported() now emits a UserWarning instead of raising TypeError.
_from_host() casts the host array to the fallback dtype before pushing.
Update test to verify warning and fallback dtype rather than rejection.
Copilot AI changed the title [WIP] Support array API bool, float64, int64, and uint64 dtypes in pyclesperanto Fall back bool/int64/uint64/float64 to supported dtypes with a warning Jun 20, 2026
Copilot AI requested a review from haesleinhuepf June 20, 2026 20:21
@haesleinhuepf
haesleinhuepf marked this pull request as ready for review June 20, 2026 20:49
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