NDArray M2: multi-dimensional slicing with :: syntax#75
Merged
Conversation
Closed
Agent-Logs-Url: https://github.com/Quafadas/vecxt/sessions/6bd40ae4-ecf0-45c0-96d3-30ead685ab02 Co-authored-by: Quafadas <24899792+Quafadas@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Implement multi-dimensional indexing for NDArray using
NDArray M2: multi-dimensional slicing with Apr 8, 2026
:::: syntax
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.
Extends
NDArray[A]with a varargsapply(selectors: RangeExtender*)that brings the same ergonomic slicing already available onMatrixto N-dimensional arrays.API
RangeExtender = Range | Array[Int] | ::.typeis reused as-is fromrangeExtender.scala.Implementation (
vecxt/src/ndarrayOps.scala)::, a step-1Range, or a contiguousArray[Int]: returns a strided view sharing the backing array, adjusting onlyoffsetandshape;stridesare unchanged.Array[Int]and iterates output indices in col-major order to fill a fresh contiguous array.transparent inline): validates selector count matchesndim, range start/end within shape, and eachArray[Int]element within shape.Note: a single
Array[Int]on a 1-D NDArray (arr(Array(0,3,7))) resolves via Scala's overload rules to the existing N-D element-accessapply(indices: Array[Int]), not the new slicing overload. Multi-argument calls (e.g.arr(Array(0,2), ::)) are unambiguous.Tests (
vecxt/test/src/ndarraySlicing.test.scala)Covers 1-D, 2-D, and 3-D cases across all selector types; zero-copy mutation visibility; consistency with
slice; and error paths (wrong selector count, out-of-bounds range, out-of-bounds gather index).