go-ruby-matrix is a pure-Go (no cgo) reimplementation of Ruby's matrix standard library — Matrix and Vector with MRI 4.0.5-faithful behaviour. It matches MRI's to_s / inspect formatting, its error classes, and — crucially — its exact arithmetic: an Integer matrix's determinant stays an Integer, and inverse produces exact Rationals (Matrix[[1,2],[3,4]].inverse → Matrix[[(-2/1), (1/1)], [(3/2), (-1/2)]]) — without any Ruby runtime. Entries flow through a Num tower built on math/big, reproducing MRI's inverse_from Gauss-Jordan step for step. It is the matrix backend for go-embedded-ruby, a standalone sibling of go-ruby-regexp, go-ruby-erb and go-ruby-yaml — differential-tested against MRI, 100% coverage, CI green across 6 arches and 3 OSes.
The Num numeric tower ready
Entries flow through Num — *big.Int for Integers, *big.Rat for Rationals, float64 for Floats — with Ruby’s promotion: Integer op Integer stays Integer, any Rational stays Rational even when whole, any Float dominates.
Constructors & accessors ready
New / Build / Identity / Zero / Diagonal / Scalar / RowVector / ColumnVector / Rows / Columns / HStack / VStack, plus RowCount / ColumnCount / At / Row / Column / Each / Minor / FirstMinor / ToA.
Exact operations ready
Add / Sub / Neg / Mul (matrix·matrix, ·scalar, ·vector) / Div / Pow / Transpose / Trace / Determinant / Inverse / Rank — exact over the tower, so an Integer matrix’s determinant stays Integer and inverse produces exact Rationals.
Predicates & formatting ready
Square / IsDiagonal / Symmetric / Orthogonal / Singular / Regular / LowerTriangular / UpperTriangular / IsZero, Eql (==) and Hash, and ToS / Inspect matching MRI’s Matrix[[…], […]] / Matrix.empty(r, c) formatting.
Vector ready
Elements / At / Size / Add / Sub / Mul / InnerProduct (dot) / CrossProduct / Magnitude (norm) / Normalize / Each / Map / Angle / Eql / Independent, with the same exact numeric tower and MRI-faithful errors.
MRI oracle & coverage ready
Deterministic ruby-free tests hold coverage at 100%; a differential oracle compares every operation’s ToS against ruby -rmatrix … .inspect, including the exact-arithmetic results and the Ruby-faithful float formatter. Green across all six 64-bit Go arches and three OSes, cgo disabled.
- ready capability complete (exit criteria met, nothing material left)
- active in progress (substantial work shipped, not yet finished)
- planned not started yet (or downstream by design)
A faithful port of Ruby's Matrix and Vector in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. Arithmetic is exact wherever MRI's is: a Num tower on math/big keeps Integer and Rational entries exact, reproducing MRI's Gauss-Jordan inverse step for step. Validated differentially against the system ruby -rmatrix — every operation's inspect compared to MRI. It is a standalone, reusable module and the matrix backend for the sibling org github.com/go-embedded-ruby.