tur/sized-matrix
SizedMatrix: row-major 2D matrix with static size annotations.
Since: Phase SZ3
sized-matrix-new
(sized-matrix-new [rows cols])
allocate a rows x cols matrix (uninitialized).
| rows | number of rows | |
| cols | number of columns |
Opaque pointer to the new SizedMatrix.
(let [m (unsafe (sized-matrix-new 3 4))] ...)
Since: Phase SZ3
sized-matrix-new-zeroed
(sized-matrix-new-zeroed [rows cols])
allocate a rows x cols matrix, all zero.
| rows | number of rows | |
| cols | number of columns |
Opaque pointer to the new SizedMatrix with all elements set to 0.
(let [m (unsafe (sized-matrix-new-zeroed 3 4))] ...)
Since: Phase SZ3
sized-matrix-free
(sized-matrix-free [m])
free a heap-allocated SizedMatrix and its data.
| m | SizedMatrix pointer from sized-matrix-new or sized-matrix-new-zeroed |
nil
(unsafe (sized-matrix-free m))
Since: Phase SZ3
sized-matrix-rows
(sized-matrix-rows [m])
number of rows in the matrix.
| m | SizedMatrix pointer |
Row count as :int.
(sized-matrix-rows m) ; => 3
Since: Phase SZ3
sized-matrix-cols
(sized-matrix-cols [m])
number of columns in the matrix.
| m | SizedMatrix pointer |
Column count as :int.
(sized-matrix-cols m) ; => 4
Since: Phase SZ3
sized-matrix-size
(sized-matrix-size [m])
return the total element count as a Size expression.
| m | SizedMatrix pointer |
A (Static n) where n = rows * cols.
(size-eval (unsafe (sized-matrix-size m))) ; => rows*cols
Since: Phase SZ3
sized-matrix-row-size
(sized-matrix-row-size [m])
return the number of columns as a Size expression.
| m | SizedMatrix pointer |
A (Static cols).
(size-eval (unsafe (sized-matrix-row-size m))) ; => cols
Since: Phase SZ3
sized-matrix-col-size
(sized-matrix-col-size [m])
return the number of rows as a Size expression.
| m | SizedMatrix pointer |
A (Static rows).
(size-eval (unsafe (sized-matrix-col-size m))) ; => rows
Since: Phase SZ3
sized-matrix-get
(sized-matrix-get [m r c])
bounds-checked element read at (r, c).
| m | SizedMatrix pointer | |
| r | zero-based row index | |
| c | zero-based column index |
The int64 value at row r, column c.
(sized-matrix-get m 1 2) ; => element at row 1 col 2
Since: Phase SZ3
sized-matrix-set!
(sized-matrix-set! [m r c v])
bounds-checked element write at (r, c).
| m | SizedMatrix pointer | |
| r | zero-based row index | |
| c | zero-based column index | |
| v | value to store |
The same matrix pointer m (for chaining).
(sized-matrix-set! m 0 0 42)
Since: Phase SZ3
sized-matrix-fill!
(sized-matrix-fill! [m v])
set every element to v; returns the same matrix.
| m | SizedMatrix pointer | |
| v | value to store in every element |
The same matrix pointer m.
(sized-matrix-fill! m 0) ; zero-fill
Since: Phase SZ3
sized-matrix-row-sum
(sized-matrix-row-sum [m r])
sum all elements in row r.
| m | SizedMatrix pointer | |
| r | zero-based row index |
Integer sum of all elements in row r.
(sized-matrix-row-sum m 0) ; => sum of first row
Since: Phase SZ3
sized-matrix-col-sum
(sized-matrix-col-sum [m c])
sum all elements in column c.
| m | SizedMatrix pointer | |
| c | zero-based column index |
Integer sum of all elements in column c.
(sized-matrix-col-sum m 0) ; => sum of first column
Since: Phase SZ3
sized-matrix-total-sum
(sized-matrix-total-sum [m])
sum all elements in the matrix.
| m | SizedMatrix pointer |
Integer sum of all elements.
(sized-matrix-total-sum m)
Since: Phase SZ3
sized-matrix-assert-shape!
(sized-matrix-assert-shape! [m expected-rows expected-cols])
panic if the matrix does not have the expected shape.
| m | SizedMatrix pointer | |
| expected-rows | expected row count as a (Size) | |
| expected-cols | expected column count as a (Size) |
nil on success; panics with a descriptive message on shape mismatch.
(unsafe (sized-matrix-assert-shape! m (Static 3) (Static 4)))
Since: Phase SZ3