pipekit-array¶
Array-API operators on top of pipekit. One operator runs on numpy,
JAX, CuPy, PyTorch, or dask via array_namespace(x) dispatch — see
the design doc
for the full architecture, ADRs, and the v0.1 operator catalogue.
Phase A of the v0.1 implementation has landed: namespace dispatch +
reductions + stack/concat combinators. Phases B–D add geometry, QC,
and the trained-model wrapper ModelOp.
array_namespace¶
pipekit_array._namespace
¶
Array API namespace dispatch shim.
The single point of backend dispatch for every pipekit-array
operator. array_namespace(*xs) returns the Array API
namespace (numpy, jax.numpy, torch via array-api-compat, …)
shared by all input arrays.
Tries the optional array-api-compat library first — without it,
PyTorch tensors don't expose __array_namespace__ natively and torch
backends won't dispatch. Falls back to native
x.__array_namespace__() lookup if the compat shim isn't installed.
See docs/design/architecture.md §4 and ADR A1 for the rationale.
array_namespace(*xs)
¶
Return the Array API namespace shared by all input arrays.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*xs
|
Any
|
One or more array-like objects. All must share the same Array API backend. |
()
|
Returns:
| Type | Description |
|---|---|
Any
|
The module-like namespace object (e.g. |
Any
|
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If no input implements the Array API, or if the
inputs span more than one backend. The error message is
consistent whether or not |
Source code in packages/pipekit-array/src/pipekit_array/_namespace.py
Reductions¶
pipekit_array.reduce
¶
Reductions — MeanScalar.
Wraps xp.mean as a pipekit Operator. See
docs/design/api/operators.md for the spec.
MeanScalar
¶
Bases: Operator
Reduce an array to a scalar (or per-axis means) via xp.mean.
Defaults to a full reduction (axis=None) yielding a scalar of
rank 0. Output dtype matches the input's floating dtype per the
Array API mean contract.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
int | tuple[int, ...] | None
|
Axis or tuple of axes to reduce over. |
None
|
keepdims
|
bool
|
If True, retains the reduced axes with size 1. |
False
|
Raises:
| Type | Description |
|---|---|
ValueError
|
From |
Example::
out = MeanScalar()(image) # scalar
out = MeanScalar(axis=(-2, -1))(image) # per-band mean
out = MeanScalar(axis=0, keepdims=True)(image) # shape (1, H, W)
Source code in packages/pipekit-array/src/pipekit_array/reduce.py
Combinators¶
pipekit_array.combinators
¶
Combinators — StackAlong, ConcatenateAlong.
Thin wrappers over xp.stack and xp.concat (the Array API
standardised names) so the operations compose into a pipeline. See
docs/design/api/operators.md for the spec.
ApplyToBands lands in Phase B alongside BatchedMap.
ConcatenateAlong
¶
Bases: Operator
Concatenate a list-of-arrays along an existing axis via xp.concat.
xp.concat is the Array API standardised name; numpy 2.0+
exposes it as concat alongside the legacy concatenate alias.
All input arrays must share shape (except along axis), dtype,
and backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
int
|
Existing axis to concatenate along. Default 0. |
0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
From |
Example::
out = ConcatenateAlong(axis=0)([arr_a, arr_b]) # shape (2*N, H, W)
Source code in packages/pipekit-array/src/pipekit_array/combinators.py
StackAlong
¶
Bases: Operator
Stack a list-of-arrays along a new axis via xp.stack.
All input arrays must share the same shape, dtype, and backend.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
axis
|
int
|
Position of the new axis in the output. Default 0. |
0
|
Raises:
| Type | Description |
|---|---|
ValueError
|
From |
Example::
out = StackAlong(axis=0)([arr_a, arr_b, arr_c]) # shape (3, H, W)