Format: each decision states the choice, the alternatives considered and the reason. Reviewers should treat these as the load-bearing commitments of the design; everything else follows from them. An As built paragraph records where the shipped code departs from a decision or adds to it.
A1. Dispatch via array_namespace(x), not a backend registry¶
Decision: Operators call array_namespace(x) inside _apply and use the returned namespace exclusively.
There is no backend registry, no Backend enum and no backend= constructor argument.
Alternatives considered:
Backend registry:
Operator(..., backend="jax")selects the implementation. Rejected: it duplicates information the input array already carries, and adds a configuration knob the user has to keep in sync.Per-backend operator subclasses:
NumpyMeanScalar,JaxMeanScalar. Rejected: it explodes the surface area and defeats the whole point of the Array API.
Rationale: array_namespace(x) is the standard’s blessed dispatch path.
The input picks the backend and the operator stays backend-agnostic.
This is the single most important decision; it defines what pipekit-array is.
A2. Strict purity: no in-place mutation¶
Decision: Every operator is side-effect-free.
No x[i] = value, no x += other, no xp.copyto(dst, src).
Operators that need to “modify” return a fresh array via xp.where, xp.concat or xp.stack.
Alternatives considered:
Per-backend mutation: mutate when the backend supports it (NumPy, torch), copy otherwise (JAX). Rejected: it makes operator semantics backend-dependent, breaks R1 of the shape rules, and defeats test reproducibility.
Optional in-place flag:
Op(..., copy=False). Rejected: it silently breaks under JAX and lures users into backend coupling.
Rationale: JAX immutability is the strict constraint, and designing to it gets the others for free. The performance gap is backend-internal: JAX’s XLA compiler removes intermediate copies, and NumPy users pay one extra allocation per operator, which is negligible at the operator granularity pipekit-array works at.
A3. Carrier-aware controllers ship in pipekit-array, not pipekit¶
Decision: pipekit-array.observe.Histogram ships its own controller, with to_array=lambda x: xp.reshape(x, (-1,)) as the default.
pipekit_ops.observe.Histogram keeps its to_array: Callable constructor argument for the generic case.
Alternatives considered:
Add Array API logic to
pipekit_ops.observe.Histogram. Rejected: pipekit core has no third-party deps, by rule, and the Array API import would couple core to a sister library’s domain.Make
pipekit-array.Histograma subclass. Rejected: the two Histograms share the controller pattern, but the array version has array-specific stat options (per-axis histograms, dtype-aware bin edges) that don’t generalise to “an arbitrary carrier flattened to a sequence of numbers”.
Rationale: the same logic with different defaults. The carrier-aware version makes the right choice for arrays without forcing the user to spell it out, and the core version stays generic for non-array carriers (custom dataclasses, GeoTensor metadata stats, etc.).
As built: the array Histogram is not built yet (phase B).
A4. No per-backend conditionals inside operators¶
Decision: If an operator can’t be written against array_namespace(x) alone, it doesn’t live in pipekit-array.
It either:
lives in a per-backend sister package (
pipekit-jax, a futurepipekit-torch);lives in user code;
doesn’t exist (the operator is dropped from the catalogue).
Alternatives considered:
Internal
if xp.__name__ == "jax.numpy"branches. Rejected: the backend coupling defeats the dispatch story, tests must run per branch, and bugs become per-backend bugs.
Rationale: backend-specific tricks are the wrong layer’s problem. pipekit-array’s value is the generic operator; if the operator can’t be generic, it doesn’t belong here.
As built: the dim-level functions keep a few backend checks, each in a shared helper and none in an operator’s _apply.
namespace_of gives dask data a _DaskNamespace that maps the Array API names dask lacks (permute_dims, concat, cumulative_sum, cumulative_prod); reduce(..., where=) raises TypeError for backends other than NumPy and JAX; quantile rechunks dask’s reduced axes into one chunk; and dot falls back to broadcast, multiply and sum on a namespace without einsum (architecture R3).
A5. pipekit-array.BatchedMap is array-shaped, not a shadow¶
Superseded by A19: the array-shaped operator is
BatchAlong, and it ships.
Decision: pipekit-array.parallel.BatchedMap(op, batch_size=8, axis=0) splits the input array along axis, applies op to each chunk, and concatenates the results back along axis.
It is distinct from pipekit_ops.execution.BatchedMap, which takes an iterable and applies op to each item.
The two coexist, and users pick by carrier shape:
op input type | Use |
|---|---|
| iterable of carriers | pipekit_ops.execution.BatchedMap |
| single large array | pipekit_array.parallel.BatchedMap |
Rationale: the same name for a different problem. The iterable version is for streams; the array version is for splitting one big tensor for inference. Renaming either is gratuitous churn, because the import path disambiguates.
A6. NaN semantics are documented, not hidden¶
Decision: Operators that touch NaN (AssertNoNaN, AssertValidFraction) document the per-backend edge cases in their docstrings.
We do not try to unify them.
Alternatives considered:
Per-operator NaN normalisation: call
xp.nan_to_numbefore the check. Rejected: it is lossy, and it surprises users who passed NaN deliberately.Skip NaN-touching operators in v0.1. Rejected: these are the most-requested QC operators, and the workaround is losing users.
Rationale: the documented edge cases are small (NumPy and JAX agree on xp.isnan and xp.sum(isnan_mask), which is all the v0.1 operators need).
Other gaps are caught by the per-backend test matrix.
As built: the dim-level functions take NaN explicitly instead of implicitly (A12): quantile has skipna=False by default, cumreduce asks for "nancumsum" by name, and reduce resolves "nanmean", "nanmedian" and the like from the namespace.
A7. Dask laziness is the user’s responsibility¶
Decision: pipekit-array supports dask.array inputs but does not call .compute() for the user.
A dask-backed pipeline returns a dask array, and the user calls .compute() (or .persist(), etc.) at the consumption boundary.
Alternatives considered:
Auto-compute at operator boundaries: this kills the laziness benefit and turns dask into “slow NumPy”.
Auto-compute at the pipeline boundary: pipekit operators don’t know they’re at a “pipeline boundary”; the operator API is the same whether you compose ten of them or call one in a notebook.
Rationale: dask’s value is the lazy graph, and we don’t break it. We document the pattern and trust the user.
As built: the dim-level functions keep dask lazy (gate G10; quantile’s dask output stays lazy).
Two shipped pieces cannot: Estimator computes a dask input on the host, because scikit-learn computes on NumPy, and the einx bridge raises BackendError naming .compute(), because einx has no dask backend.
A8. ModelOp split: pipekit-array vs pipekit-jax¶
Decision: The trained-model wrapper splits along weight round-trippability:
pipekit_array.inference.ModelOp(model, method, batch_size)is the generic wrapper. It works for any callable model (sklearnpredict, raw Keras__call__, plain PyTorchnn.Module.forward, a NumPy function). There is no registry round trip; the model object is the artifact.pipekit_jax.JaxModelOp(module, ...)is the weight-blob variant for Equinoxeqx.Modules. It implementsserialize_weights() → bytesandwith_weights(blob) → JaxModelOp, sopipekit-experiment.ModelRegistrycan store and reload weights byte-identically (the v0.2 reproducibility upgrade for pipekit-train).
Alternatives considered:
One
ModelOpfor everything: this would force pipekit-array to carry an Orbax dependency for the JAX path. Rejected: pipekit-array has zero hard backend deps.ModelOpalways serialises viapickle. Rejected: pickle isn’t byte-stable across Python versions, which defeats reproducibility.
Rationale: two cases, two operators.
ModelOp handles 95% of users (PyTorch, Keras, sklearn) without touching JAX, and JaxModelOp handles the Equinox reproducibility case without pulling Orbax into pipekit-array’s dependency cone.
pipekit-train’s Lightning and Keras adapters would return pipekit-array.ModelOp from loop.run().
The Equinox adapter returns EquinoxModelOp (in-package, no round trip) or pipekit-jax.JaxModelOp (full round trip), per user choice.
The contract is “the returned op is a pipekit_ops.Operator”; the specific class differs by backend.
As built: JaxModelOp ships in pipekit-jax; ModelOp is not built yet (phase D). pipekit-train dropped Lightning (its D15), and its Keras backend returns its own KerasModelOp with a weight blob (its D20), not ModelOp.
For sklearn-style estimators on named carriers, Estimator ships instead (OP-O3): it is fitted and applied by dim name, and sets forbid_in_yaml.
A9. Named carriers: DimArray, through pipekit’s adapter registry¶
Decision (PK-P7, 23 Oct 2026): pipekit-array’s plain named carrier is DimArray(data, dims, labels), a JAX pytree whose only leaf is the data.
It is what a geo carrier becomes when a kernel consumes one of its spatial dims (per-column statistics consume row and keep col), and the carrier for tests and for libraries with none of their own.
Its adapter, DimArrayAdapter, is registered with pipekit_ops.register_adapter on import, and it is the reference adapter every other one is tested against.
DimArray holds no georeference, no coordinates beyond static labels and no attrs, and does no alignment, arithmetic or selection by value.
It crosses to xarray with to_xarray() when an analysis needs those.
The design pages’ separate two-field Named record (data, dims) is folded into DimArray: a DimArray with no labels is that record.
Rationale: one plain carrier, not two, and one registry (pipekit core’s, PK-P1) through which the dim-level functions and KernelOp reach it, xr.DataArray and geoarray’s carriers alike.
See geostack’s docs/design/pipekit_kernels.md.
A10. Padded batches: batch, Padded, stack_items, reduce(where=)¶
Decision (#119): a fixed-size batch is Padded(value, valid), a NamedTuple of the items stacked along a new leading dim and a (n,) bool mask of the real ones, made by batch(items, *, size, dim, pad="last" | "none" | "drop").
Padding copies the last real item. Values stay finite and in distribution, so a masked loss, its gradient and a normalisation over the batch behave (the rule geoarray’s
pad_pointsand geopatcher’sPatchBatchalready follow).Policy strings, not
pad_last/drop_lastflags: one argument, three outcomes, no invalid combination.stack_items, notstack.stackjoins carriers on one shared grid (geoarray’s never aligns two). A batch’s items may each carry their own geometry (patch transforms), the inverse of the splitmap_overmakes, so it is a separate adapter verb. Without a fast path it isstack.Masks are
reduce(..., where=), not amasked_mean: every reduction, with the kept-count denominator, passed through to the namespace’swhere=. A named mask aligns by dim name; a plain array must match the carrier’s leading dims (a(sample,)mask on(sample, y, x)), never NumPy’s right-broadcast; a named mask’s lengths must match the data’s (or be 1). Only NumPy and JAX reductions takewhere=; dask, CuPy and PyTorch carriers raiseTypeError.The name is
Padded, withvalid. “Masked” invites polarity bugs: geotoolz masks andnp.mamasks are True = drop, whilevalidis True = keep.Batchis taken by pipekit-train’s(x, y)tuples.
Rationale: three copies of “group, pad, mask” across the stack (geoarray pad_points, geopatcher PatchBatch, pipekit-train’s eval batches with no mask), and one home for the rule.
A11 to A22. The missing dim-level functions¶
Decision (6 Nov 2026): sixteen dim-level functions join the named layer, each with an operator twin in dim_operators.
The full catalogue, the xarray parity table and the testing gates are in Dim-level functions: the missing ones; the decisions are summarised here.
All sixteen shipped in #204 to #207, together with ApplyAlong, BatchAlong and relabel on both shipped adapters.
A11. Scope. Only functions that change dims or move data by position; element-wise maths stays
combine.A12. xarray’s names and argument names (
rename,expand_dims,squeeze,broadcast_like,pad,roll,shift,diff,coarsen,quantile,where,dot), with stated divergences: labels follow positions, shared dims agree exactly instead of outer-joining, no implicitskipna, dtype preserved, sizes static.A13. No methods on
DimArray. A method would exist only onDimArray; a free function runs on every registered carrier.A14.
merge_dims/split_dims, notstack/unstack, becausestackalready means a new dim from several carriers; merged labels are tuples, so the round trip is exact.A15. Windows.
windowreturns full windows only;coarsenissplit_dimsthenreduce;ApplyAlong(inner, dim)replaces the plannedApplyToBands, and the plannedSubsampleisiselwith a stepped slice.A16.
where, notfill_where: True keeps, as in xarray and asPadded.validdoes (A10).A17.
dot, notcontract, withdimrequired so a dim shared by accident is never summed; shared dims not indimare batch dims, so the generic path is a named-indexeinsum, nottensordot.A18.
quantileis a function, because a list of adds a dim thatreducecannot name.A19.
BatchAlongsupersedes A5. The planned array-shapedBatchedMapis renamedBatchAlong(inner, size, dim, pad="none"), so it no longer shares a name withpipekit_ops.BatchedMap.A20. Label-value operations stay in xarray:
groupby,resample,swap_dims,reindex,interp,idxmax,polyfit,differentiate,interpolate_na,rolling_exp.A21. The planned QC
DiffbecomesAssertClose, soDiffis the twin ofdiff.A22. An optional
relabeladapter method (in theLabelledAdapterprotocol ofpipekit_ops) sets the labelsrewrapcannot carry (renamed, merged, split, quantile, broadcast and contracted-in dims); without it those functions raise instead of dropping labels. The seven required methods do not change.
As built (#204 to #207). The PRs departed from these decisions in the following ways; Dim-level functions: the missing ones §6 has the detail under each ID.
Placement. The functions live in four new modules,
dim_shapes,dim_shifts,dim_windowsanddim_algebra, not indims, and are re-exported frompipekit_array.A14.
merge_dimsgives the merged dim no labels when none of its sources has any, andsplit_dimsreturns a part unlabelled when its recovered labels are exactly its positions.A15. The xarray
windowfast path fills with zero, not NaN, beforeiseldrops the partial windows, so integer and bool input keep their dtype. A dim cannot be named like a keyword-only argument (window_dimorstrideforwindow,boundaryforcoarsen), because Python binds the keyword first.A16.
whereon integer or bool data withoutotherraisesTypeError, the same rule asshiftandpad.A17, A18. There are no xarray fast paths for
dotorquantile:xr.dotsilently inner-joins mismatched coordinates, andDataArray.quantileadds a scalarquantilecoordinate for a floatq.quantilecastsqto the input’s float dtype, and raisesValueErrorfor aqoutside [0, 1] or a listqthat meets a kept dim namedquantile.A19.
BatchAlongrestoresdim’s labels afterconcat(which drops them) when the output length matches the input, andpad="drop"raisesValueErrorwhen every entry would be dropped.A22. pipekit-array finds
relabelby name (getattr), so it still imports on a pipekit-ops withoutLabelledAdapter.
A23. Plain functions have their own array backend, with a host rule¶
Decision (23 Nov 2026, #244): pipekit_array.functions holds the array backend of plain functions, which are no operators: namespace_of, floating_inputs, like and elementwise.
Python numbers, sequences and NumPy arrays join the library and the device of the other arrays.
Two libraries other than NumPy in one call raise BackendError, and so does an array of an unknown library.
array_namespace (A1) and the named layer kept refusing NumPy next to JAX until A24.
BackendError derives from TypeError and ValueError.
Alternatives considered:
The host rule in
array_namespace: one rule for the package. Rejected: the named layer would then move a carrier’s data from NumPy to JAX without saying so.A backend in each library: geophysix, radiomax and gridax each had one. Rejected: the same device and torch fix was made twice on one day, and the copies of
elementwisedrifted on the same day.A public
geophysix.arrays: Rejected: gridax and radiomax would depend on a physics library for their array dispatch.
Rationale: a formula takes constants and coordinates from NumPy next to data on JAX or torch, and the user expects them to join.
An array of the call’s library is cast with astype(copy=False) and never rebuilt, because asarray detaches a torch tensor in torch 2.5 and 2.10.
A24. NumPy joins JAX in every layer, and guards are opt-in¶
Decision (24 Nov 2026, #253): a NumPy array next to a JAX one joins it, in either order, in array_namespace, the dim functions, KernelOp, StackAlong and ConcatenateAlong, and elementwise on carriers.
Under a trace the NumPy array is a constant.
pipekit_ops.guard reports each eager join of an array with one dimension or more, and a dtype it widens; without a guard nothing warns.
Any other mix raises BackendError, as before.
The result of combine is what the caller’s function returns: np.add of JAX arrays is NumPy’s.
Alternatives considered:
Refuse (A1 and A23 until this decision): it finds a host copy for everybody, and makes everybody convert by hand. It also stopped jittable code:
combineraised on a NumPy constant insidejax.jit.jax.transfer_guardinstead of a guard of our own: Rejected: at"disallow"it refusesx * 2.0, and on CPU it does not see a copy from JAX to NumPy (jax 0.12.1).Join dask too: Rejected: it would compute a lazy array, or wrap an eager one, without being asked.
Rationale: a NumPy mask, coordinate or constant next to a field on JAX is ordinary code. The cost of joining silently (a host copy, or float32 widened to float64) matters to an app, and an app can switch the guard on.
A25. Masked reductions and records of plain functions live here too¶
Decision (24 Nov 2026): what a library of plain functions needs and is about no field of science goes next to pipekit_array.functions: table_like, boolean_like and divide_or_nan in it, weighted_sum, weighted_mean and Groups in pipekit_array.weighted, and register_record in pipekit_array.records.
They come from diagnostix v0.0.1, and register_record had copies in geophysix and radiomax.
Alternatives considered:
Each library keeps its own: Rejected: three copies of
register_recordexist, two of them with an import hook of their own besidepipekit_ops.on_import.reduce(where=)of the named layer (A10): it takes carriers, has no weights and no groups, and an all-masked mean is the namespace’s.nanmean,nansum: Rejected, as in the non-goals: a NaN in a valid sample must give NaN, and a mask says what is missing.
Rationale: Groups is a padded gather, because the standard has no bincount and a difference of cumulative sums loses float32’s precision.
A library’s own exception is its own business: these raise ValueError and BackendError.
A26. The helpers of a plain function live here, and the subject stays in its library¶
Decision (25 Nov 2026, #272): pipekit-array is a core library, and every library of the stack may import it. A helper belongs here if its description needs no grid, Earth, kernel, spectrum, operator or solver: safe roots, tables of numbers, integers to floats, the inputs of a reduction. A root is 0 with a zero gradient at x ≤ 0, and NaN at NaN.
Alternatives considered:
NaN at 0 too (three of the four
safe_sqrtthat this replaces):where(x > 0, √x, 0)sends NaN to 0. Rejected: a missing value must not become a number.NaN at x < 0 (the fourth): Rejected: a difference of squares rounds below 0, and every caller would clip first.
Rationale: each library wrote these for what the array API standard leaves out, and the copies no longer agreed.
A27. A hook is JAX’s own call on JAX data¶
Decision (25 Nov 2026, #273, #274, #275): pipekit_array.hooks gives an equivalent off JAX for x.at[index].set, .add and .multiply, jax.vmap, jax.lax.scan, jnp.pad, jax.lax.stop_gradient and jax.lax.optimization_barrier.
On JAX data the jaxpr is that of the JAX function, and the tests compare the two.
add_at and multiply_at count a repeated index each time; with an integer array they run on NumPy and JAX only, and raise BackendError elsewhere.
Alternatives considered:
while_loopandcond: left out, because nothing outside JAX needs them yet.A functional update through
whereand a mask: it needs no assignment, but reads the whole array for one entry, and does not lower to JAX’s scatter.y[index] += von NumPy: Rejected: it adds to a repeated entry once.
Rationale: a library that stays on JAX loses nothing, and a function that only used one of these becomes array agnostic where it is. An index out of bounds raises on NumPy, and JAX does not report it; a hook does not hide that difference.
A28. A check under a trace needs equinox¶
Decision (25 Nov 2026, #278): check_values raises at once on a concrete array, and returns equinox.error_if under a trace.
equinox is no dependency: it is imported under a trace only, and an ImportError names it if it is missing.
Alternatives considered:
Skip the check under a trace: Rejected: a bad value passes through.
jax.experimental.checkify: Rejected: the caller has to transform the whole function to see the error.
Rationale: the libraries that call it under a trace all depend on equinox.
A29. The checks of a test suite ship in the wheel¶
Decision (25 Nov 2026, #282): pipekit_array.testing holds the checks that six libraries copied into their tests/: the array libraries, the oracle, the adjoint, JAX’s transforms, the gradients and the samples.
assert_backends_agree is the union of three copies: every kind of array that is installed, both precisions, the device, and JAX under jit.
A DataArray is checked on request only, because a function over an axis refuses it.
Alternatives considered:
A pytest plugin: Rejected: it would need pytest; a check that cannot run raises
unittest.SkipTest, which pytest reports as a skip.A list of kinds at import (
KINDS, as in the copies): Rejected: importing the test kit of a carrier library would import JAX and torch.array_kinds()imports them when called.
Rationale: the copies had drifted, so a library’s coverage depended on which one it had copied. Two faults of the copies are fixed here: an infinite reference, or a NaN finite difference, made the tolerance NaN or infinite, and every value passed.
A30. Six areas, one import direction, and a recorded module¶
Decision (25 Nov 2026, #291): the package is arrays, named, kernels, operators, bridges and testing.
An area imports only from the ones before it, and a name is imported from its area.
A saved pipeline records an operator under pipekit_array, wherever its file is, and __former_modules__ loads the states saved before.
The decisions above name the modules of their day: functions, hooks, checks, weighted and records are arrays, dims, dim_*, dimarray, rows and batching are named, kernel is kernels, dim_operators, combinators and reductions are operators, and xarray, einx and estimator are bridges.
Alternatives considered:
A second distribution for the named layer: Rejected: one more pin in every library that uses both, and the import direction makes a later split easy.
Names loaded on first use: Rejected:
Operator.from_statelooks among the operators that are loaded, so a saved pipeline would not load; and the eager import costs about 11 ms, next to 77 ms for pipekit-ops (measured with-X importtime).Operators recorded under their files: Rejected: the module is part of
pipeline_hash, so each later move would change every hash again. They changed once, here.
register_record needed no array library in records; in arrays it needs [numpy,compat], which each library that uses it has.
Rationale: geophysix, radiomax and diagnostix use only plain arrays and geotoolz only named carriers, and the flat list of modules said neither.
functions imported kernel, so the bottom depended on the top; elementwise, which needs both, is now a kernel.
Optional extras matrix¶
For reference, the extras that follow from these decisions, as declared in packages/pipekit-array/pyproject.toml:
| Extra | Pins | Why |
|---|---|---|
[numpy] | numpy>=2.0 | Array API conformance landed in NumPy 2.0 |
[jax] | jax>=0.4.20 | Array API conformance landed in jax 0.4.20 |
[torch] | torch>=2.0 | Array API namespace in torch 2.0+ (dispatch needs [compat]) |
[cupy] | cupy>=13 | Array API conformance from CuPy 13 |
[dask] | dask[array]>=2024 | Partial conformance; lazy |
[xarray] | xarray>=2024.6 | DimArray.to_xarray; the DataArray adapter (A9) |
[sklearn] | scikit-learn>=1.4 | Estimator (geostack OP-O3) |
[einx] | einx>=0.4 | pipekit_array.bridges.einx (geostack OP-O2) |
[compat] | array-api-compat>=1.11 | The first path of array_namespace; required for PyTorch and, with [numpy], for pipekit_array.arrays (A23) |
The first design marked [compat] as a proposed v0.2 addition; it ships, together with the shim’s array_api_compat path (architecture.md §4).
The default install (pip install pipekit-array) brings only pipekit-ops.
Backend availability is determined at call time via array_namespace(x): if the input doesn’t implement the Array API, TypeError is raised at call time, not at construction.
The recommended user install is pipekit-array[numpy].