Skip to content

Allow plain Int for row/column in Matrix slice syntax#88

Merged
Quafadas merged 2 commits intomainfrom
copilot/fix-matrix-slice-syntax
Apr 13, 2026
Merged

Allow plain Int for row/column in Matrix slice syntax#88
Quafadas merged 2 commits intomainfrom
copilot/fix-matrix-slice-syntax

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 13, 2026

mat(::, Array(0)) worked but the more natural mat(::, 0) did not, requiring users to unnecessarily wrap single-index selections in Array(...).

Changes

  • MatrixInstance.scala: Two new apply overloads that accept a plain Int for either dimension alongside a RangeExtender, delegating to the existing Array-based slice implementation:
    • apply(rowRange: RangeExtender, col: Int)
    • apply(row: Int, colRange: RangeExtender)

No changes to RangeExtender itself — avoids ambiguity with the existing element-access apply(row: Row, col: Col): A.

Example

val mat = Matrix.fromRows(
  Array[Double](1.0, 2.0, 3.0),
  Array[Double](4.0, 5.0, 6.0),
  Array[Double](7.0, 8.0, 9.0)
)

mat(::, 1)    // column 1 — equivalent to mat(::, Array(1))
mat(1, ::)    // row 1    — equivalent to mat(Array(1), ::)
mat(0 to 1, 1) // rows 0–1, column 1
mat(1, 0 to 1) // row 1, columns 0–1

Copilot AI linked an issue Apr 13, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Fix slice syntax on Matrix to simplify usage Allow plain Int for row/column in Matrix slice syntax Apr 13, 2026
Copilot AI requested a review from Quafadas April 13, 2026 10:04
@Quafadas Quafadas marked this pull request as ready for review April 13, 2026 12:28
@Quafadas Quafadas merged commit d827c11 into main Apr 13, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slice syntax on Matrix is jarring

2 participants