Skip to content

Fix Matrix.fromColumns column/row indexing and add regression tests#2

Open
Ezrnest wants to merge 1 commit intomasterfrom
codex/fix-matrix.fromcolumns-index-issue-and-add-tests
Open

Fix Matrix.fromColumns column/row indexing and add regression tests#2
Ezrnest wants to merge 1 commit intomasterfrom
codex/fix-matrix.fromcolumns-index-issue-and-add-tests

Conversation

@Ezrnest
Copy link
Copy Markdown
Owner

@Ezrnest Ezrnest commented Feb 20, 2026

Motivation

  • Matrix.Companion.fromColumns was constructing matrices with the wrong index order, causing (row, col) to read from the wrong element of the supplied column vectors.

Description

  • Corrected Matrix.Companion.fromColumns to build entries with columns[j][i] so that matrix[i, j] equals the i-th element of the j-th input column vector (src/main/kotlin/.../Matrix.kt).
  • Added a regression test fromColumnsKeepsColumnMajorPlacement that constructs 3 column vectors with distinguishable values (10 * col + row) and asserts matrix[row, col] == columns[col][row] (src/test/kotlin/linear/MatrixTest.kt).
  • Added a rectangular (2x3) regression test fromColumnsKeepsColumnMajorPlacementForRectangularMatrix which asserts dimensions and per-element mapping to prevent square-matrix masking of indexing errors (src/test/kotlin/linear/MatrixTest.kt).

Testing

  • Attempted to run sh gradlew test --tests 'linear.MatrixTest', but the Gradle wrapper failed to download due to a network connection error to services.gradle.org, so tests could not be executed in this environment.
  • The change is minimal and covered by the added unit tests which should pass once the test environment can run Gradle.

Codex Task

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant