Skip to content

ArrayOperations.for_memory(): one registered leaf per memory type, holding the primitives that differ (0.4.0) - #10

Merged
trissim merged 2 commits into
mainfrom
feat/array-operations-for-memory
Oct 11, 2026
Merged

trissim merged 2 commits into
mainfrom
feat/array-operations-for-memory

Conversation

@trissim

@trissim trissim commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

What

  • ArrayOperations is an AutoRegisterMeta family keyed by memory_type; ArrayOperations.for_memory(MemoryType.X) returns that framework's leaf (one instance per leaf).
  • MemoryType resolves its leaf through the family. The "NUMPY_OPERATIONS"-style operations-name field and the six module-level *_OPERATIONS singletons are deleted.
  • Leaves gain an instance namespace for array-library-neutral code: module (imported on first use), accepts, astype, max, min, mean, sum, prepend_axis, linspace, ones, assign, outer, floor. The base holds the NumPy-compatible call; each leaf overrides only what its library does differently:
    • torch: uint16 reductions through float32 (CUDA has none), float32 means, torch.linspace without an endpoint argument, scalar floor in float32;
    • JAX: jax.numpy namespace, float32 means, functional assign (.at[].set);
    • TensorFlow: reduce_*, float32 means, tensor_scatter_nd_update assign, tensordot outer;
    • pyclesperanto: z-projection kernels (leading axis only), prepend_axis by create-and-assign.
  • torch and TensorFlow cast also accept native dtypes.
  • Version 0.4.0 (minor). Docs: README section, ADDING_NEW_FRAMEWORKS, CONTRIBUTING.

Why

OpenHCS writes its six per-backend image processors once against this namespace (OpenHCS surface L5). No uv.lock exists in this repository, so none is regenerated.

Tests

  • New tests/test_array_operations_family.py: one leaf per MemoryType, found by for_memory; no string or singleton roster; NumPy primitives; JAX functional assign.
  • Full suite locally (CPU, NumPy + JAX): 246 passed, 17 skipped. black --check src/ scripts/ and ruff check clean.
  • The primitives were exercised on CuPy, torch, TensorFlow and pyclesperanto on a CUDA GPU through the OpenHCS processor parity run (see the OpenHCS PR).

Not merged or tagged: the owner releases.

🤖 Generated with Claude Code

… the primitives that differ

ArrayOperations leaves register by memory_type, and
ArrayOperations.for_memory(MemoryType.X) returns the leaf. MemoryType finds
its leaf through the family; the operations-name field and the six
module-level *_OPERATIONS singletons are deleted.

Leaves gain an instance namespace for array-library-neutral code: module
(imported on first use), accepts, astype, max, min, mean, sum, prepend_axis,
linspace, ones, assign, outer and floor. Each leaf overrides only what its
library does differently (torch/JAX/TensorFlow float32 means, torch uint16
reductions, functional updates for JAX and TensorFlow, pyclesperanto
z-projections). torch and TensorFlow cast also accepts native dtypes.

Version 0.4.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 11, 2026 01:32

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.

… its dtype-name helper

The TensorFlow leaf inherited the NumPy dtype_name, so every decorated
TensorFlow call failed with "Cannot interpret 'tf.uint16' as a data type";
the _tensorflow_dtype_name helper existed but nothing used it. The torch
leaf restated _torch_dtype_name inline.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trissim
trissim merged commit 64b5e76 into main Oct 11, 2026
14 checks passed
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