Skip to content

0.5.1: no inherited operation a library cannot perform; host calls leave the accelerator alone; warn_return_any on - #13

Merged
trissim merged 5 commits into
mainfrom
refactor/sound-array-defaults
Oct 12, 2026
Merged

trissim merged 5 commits into
mainfrom
refactor/sound-array-defaults

Conversation

@trissim

@trissim trissim commented Oct 12, 2026

Copy link
Copy Markdown
Contributor

Follow-ups to 0.5.0. Details are in CHANGELOG.md.

  • Sound inheritance. ArrayLibrary supplies no NumPy-style implementation. NumpyArrayApi (NumPy, CuPy, JAX) holds them; ArrayMath declares linspace/ones/outer/floor and pyclesperanto does not inherit it, so those four are an AttributeError there instead of a failure inside the call; InPlaceAssignment holds assign by item. tests/test_operation_soundness.py calls every array operation on every importable library and checks the class structure of the rest.
  • Execution wrapper. The device is read from the call's arguments. A torch function on host tensors no longer calls torch.cuda.current_device() (which initialises CUDA) or opens a stream; data on device N uses device N's stream.
  • Typing. warn_return_any = true, ignore_missing_imports = false, the numpy.* skip override removed. Each imported library is declared in stubs/ (first on mypy_path, not in the wheel); NumpyArrayApi names its module by a Protocol. No Any, no casts, no ignores. Enum metaclass overrides annotated.
  • CONTRIBUTING.md: compatibility rule removed. TESTING.md: commands for a GPU run.

Local: 344 passed, 123 skipped on Python 3.10, 3.12, 3.13 (NumPy only); 372 passed, 95 skipped on 3.12 with the torch CPU wheel; mypy src/ stubs/, ruff and black clean. Not run on a GPU.

🤖 Generated with Claude Code

trissim and others added 5 commits October 12, 2026 15:34
ArrayLibrary supplies no implementation that assumes an array API. The
NumPy-style defaults move to NumpyArrayApi (NumPy, CuPy, JAX); linspace, ones,
outer and floor are declared by ArrayMath, which pyclesperanto does not
inherit; assignment by item is InPlaceAssignment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The execution wrapper reads the device from the call's arguments. It used to
ask the library for its current device whenever an accelerator existed, which
for torch initialises CUDA and opens a stream for a function working on host
tensors, and used the selected device's stream even when the data was on
another device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… type

warn_return_any is on and ignore_missing_imports is off. The numpy.*
follow_imports = "skip" override is gone.

Every library the package imports is declared in stubs/, which lists what
arraybridge calls and comes before an installed copy on mypy_path, so the
result does not depend on what is installed. CI checks `mypy src/ stubs/`.

- A leaf states `module = <library>` under TYPE_CHECKING, so its calls are
  checked against the declaration of that one library.
- NumpyArrayApi and MutableArrays name their module by the Protocols
  NumpyFunctions and MutableNumpyFunctions, and their arrays by NumpyArray
  and MutableNumpyArray; each leaf returns its module from `array_module`
  and the checker compares the two.
- Values with no static type are checked where they enter: _mapped_dtype
  (the dtype class asked for), MemoryContractAttribute.read (a name or
  None), DeviceMove.convert (one library), DLPackExchange.convert (the
  target imports DLPack), TorchLibrary.stream_scope (a torch stream).
- AcceleratorDevices asks each leaf for _device_if_accepted; CudaLibrary
  for create_stream; DLPackImport.from_dlpack returns NotImplemented when
  the leaf's _reads_dlpack says no, so _import_dlpack returns an array.
- The MemoryType metaclass overrides carry EnumMeta's signatures. The
  __call__ override is removed: Enum already asks _missing_ for a value it
  does not know.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 12, 2026 19:59
@trissim
trissim merged commit ae0da21 into main Oct 12, 2026
13 of 14 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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