Swap rows i and j in a dense matrix.
Implemented with Vector.swap, which updates the dense backing store in place
when M is uniquely referenced, rather than reading both rows and writing them
back through two sets (which forces a copy of the outer vector).
Instances For
Diagonal-entry corollary of getElem_rowSwap for square matrices: when
pivot ≠ k, the (k, k) entry of rowSwap M k pivot is the original
(pivot, k) entry.
Scale row i by c.
Per-entry in place via Hex.Matrix.modifyEntries: each of the row's m
entries is a single Vector.modify of the flat backing buffer, with no row
materialization, when M is uniquely referenced.
Equations
- M.rowScale i c = M.modifyEntries ↑i fun (x : Fin m) (x_1 : R) => c * x_1
Instances For
Replace row dst by row dst + c * row src.
The source row is read once into rsrc (one contiguous copy, a borrowed read
taken before the write); the subsequent Hex.Matrix.modifyEntries then holds the only
live reference to the buffer and updates the dst row's entries in place when
the runtime sees it uniquely referenced, with no destination-row
materialization.
Equations
Instances For
rowScale as a single set of the scaled row. The executable definition
goes through Vector.modify for in-place update; this is the value-level
characterization for callers that reason about the result as a set.
rowAdd as a single set of the combined row. The executable definition
goes through Vector.modify for in-place update; this is the value-level
characterization for callers that reason about the result as a set.
Replace column dst by col dst + c * col src.
The source column is read once into csrc (one contiguous copy, a borrowed read
taken before the write); the subsequent modifyCol then holds the only live
reference to the buffer and updates the dst column entry of each row in place —
one single-entry Vector.modify of the flat buffer per row (O(n) writes
total) — when the runtime sees it uniquely referenced, with no row
materialization; the source column is first snapshotted into one owned O(n)
vector via borrowed reads. This replaces the former mapRows pass, which
materialized and reflattened every row.
Instances For
Replace column dst by col dst + col src * c.
This is the right-scalar variant of colAdd, valid as a right-multiplication
wrapper over a noncommutative ring. Same flat per-entry column engine as
colAdd: read the source column once, then modifyCol the dst entries in
place.
Equations
Instances For
Read an entry of colAddRight M src dst c by cases on the column index:
column dst returns M[i][dst] + M[i][src] * c, any other column is
unchanged.
Column dst of colAddRight M src dst c is the pointwise column
combination with right scalar multiplication.
Any column other than dst is unchanged by colAddRight M src dst c.
Source-column entries are unchanged by colAddRight M src dst c when
src ≠ dst.
The source column is unchanged by colAddRight M src dst c when
src ≠ dst.
Row i of colAddRight M src dst c is row i of M with the dst entry
replaced by M[i][dst] + M[i][src] * c.
Swap columns i and j in a dense matrix.
Both columns are read once (two borrowed O(n) reads taken before the writes),
then written back with two Hex.Matrix.setCol passes that update one flat-buffer entry per
row in place, reusing the backing store when M is uniquely referenced. This
replaces the former Hex.Matrix.mapRows pass, which materialized and
reflattened every row. The column mirror of Hex.Matrix.rowSwap.
Equations
Instances For
Scale column j by c.
In-place per-entry column update via Hex.Matrix.modifyCol: each row's single j entry is
multiplied by c, reusing the freed row slot when M is uniquely referenced.
The column mirror of Hex.Matrix.rowScale.