Repository navigation
Conversation
A selection like `a[:, :, np.r_[0:90, 100:190, 200:290]]` has no shorthand
today. The only encoding is a `transform` whose last output map lists all 270
coordinates, and a selection covering an array's domain minus a few holes
grows with the array rather than with the number of holes.
`outer` selects each dimension independently, by one of four per-axis forms:
`null` (the whole axis), a `{start, stop, step?}` range, an `{indices}` list,
or an `{intervals}` list of half-open `[lo, hi)` runs. The first three are
TensorStore's `oindex` given a JSON form; intervals are ndsel's own, because
`oindex` accepts one slice or one integer array per axis and nothing that
combines ranges.
The desugaring matches TensorStore: a whole axis gets implicit infinite
bounds, which TensorStore resolves against the array when the transform is
applied; a range is exactly one dimension of `slice`; an index or interval
list becomes an `index_array` shaped to broadcast along its own dimension,
with empty and single-element lists collapsed to `constant` maps as `oindex`
does. Every success fixture was generated from the spec rules and checked
equal to TensorStore's `oindex` on the same selection. The one deliberate
difference is labels: `oindex` clears the label of an array-indexed
dimension, and `outer` keeps the labels the message declares.
No error codes are added. Selector forms are untagged, like output maps, so
a selector carrying members of two forms is `unknown_field`.
Also fixes the broadcasting of `index_array` in the NumPy example executor
and oracle test, which indexed a size-1 array dimension by the full input
coordinate and so failed on any broadcast-shaped array.
Assisted-by: ClaudeCode:claude-opus-5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 AI text below 🤖
Motivated by zarr-developers/zarr-extensions#74 (comment), which needs "a JSON serialization of orthogonal indexing with slices instead of explicit indices". The use case there is declaring an array's domain as a subset of its stored domain, such as HDF5's padded boundary chunks with the padding excluded.
What this adds
A sixth message kind,
outer, where each dimension is selected independently:{ "kind": "outer", "axes": [null, null, { "intervals": [[0, 90], [100, 190], [200, 290]] }] }This is
a[:, :, np.r_[0:90, 100:190, 200:290]]. Today the only encoding is atransformwhose last map lists all 270 coordinates.Each entry in
axestakes one of four forms:null(-inf, +inf)domain, identity map{start, stop, step?}slice(source frame kept){indices: [...]}index_arraybroadcast along dimk, domain[0, m){intervals: [[lo, hi), ...]}indices, after expansionThe first three are TensorStore's
oindexin JSON form. TensorStore has no JSON encoding for index expressions, andoindextakes one slice or one integer array per axis, so intervals are new to ndsel.TensorStore parity
conformance/outer.jsonwas generated from the spec rules, then checked equal (IndexTransform ==) tots.IndexTransform(input_rank=n).oindex[...]for the same selection.nullaxis resolve to the array's extent when TensorStore applies the transform. I checked this on a(100, 200, 300)array.constant: empty and single-element lists becomeconstantmaps, asoindexdoes. This also avoids the empty-array rank problem in §7.1.oindexclears the label of a dimension it indexes with an array.outerkeeps the labels the message declares.Changes
outerbranch and anouterAxisdefinition.conformance/outer.jsonand 18 error fixtures inerrors.json. No new error codes: selectors are untagged like output maps, so a selector mixing two forms isunknown_field.normalizesupport, a builder (Outer/Outer::new/outer), unit tests and a usage example. Each factors the per-dimensionslicerule into a helper shared bysliceandouter.outerfixtures are checked againstsource[np.ix_(...)].index_arraydimension by the full input coordinate, so any broadcast-shaped array failed.Open questions
IndexTransform. The spec says so in a non-normative note, and suggests consumers use theoutermessage directly when they only need per-axis selections. For the zarr use case (a domain declaration in attributes) the stored message stays compact, but anything that normalizes it pays O(n).indicesandintervalsmay be unsorted, overlapping or repeated, which matchespointsandindex_array. A domain declaration probably wants sorted, disjoint intervals. That could be a consumer-side rule, or a stricter form here with a new error code.Testing
uv run pytestgives 189 passed and 11 skipped;pyrightis clean.cargo testpasses all unit tests and the corpus.npm testgives 137 passed;npm run typecheckis clean.🤖 Generated with Claude Code