Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Decisions (ADRs)

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:

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:

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:

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:

Alternatives considered:

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 typeUse
iterable of carrierspipekit_ops.execution.BatchedMap
single large arraypipekit_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:

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:

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:

Alternatives considered:

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").

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.

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.

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:

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:

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:

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:

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:

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:

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:

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:

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:

ExtraPinsWhy
[numpy]numpy>=2.0Array API conformance landed in NumPy 2.0
[jax]jax>=0.4.20Array API conformance landed in jax 0.4.20
[torch]torch>=2.0Array API namespace in torch 2.0+ (dispatch needs [compat])
[cupy]cupy>=13Array API conformance from CuPy 13
[dask]dask[array]>=2024Partial conformance; lazy
[xarray]xarray>=2024.6DimArray.to_xarray; the DataArray adapter (A9)
[sklearn]scikit-learn>=1.4Estimator (geostack OP-O3)
[einx]einx>=0.4pipekit_array.bridges.einx (geostack OP-O2)
[compat]array-api-compat>=1.11The 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].