Semi-persistent Matrices
build-matrix
matrix?
matrix-rows
matrix-cols
matrix-valid-ref?
matrix-ref
matrix-set
matrix-set!
matrix-fold
display-matrix
8.16

Semi-persistent MatricesπŸ”—β„Ή

Jay McCarthy <jay@racket-lang.org>

 (require data/spmatrix) package: spmatrix

This package defines matrices using semi-persistent vectors from data/spvector

procedure

(build-matrix rows cols cell-f) β†’ matrix?

  rows : exact-positive-integer?
  cols : exact-positive-integer?
  cell-f : (exact-nonnegative-integer? exact-nonnegative-integer? . -> . any/c)
Constructs a matrix m such that (matrix-ref m ri ci) is (cell-f ri ci).

procedure

(matrix? v) β†’ boolean?

  v : any/c
Determines if v is a valid matrix.

procedure

(matrix-rows m) β†’ exact-positive-integer?

  m : matrix?
Returns how many rows m has.

procedure

(matrix-cols m) β†’ exact-positive-integer?

  m : matrix?
Returns how many cols m has.

procedure

(matrix-valid-ref? m ri ci) β†’ boolean?

  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?
Determines if (matrix-ref m ri ci) would error.

procedure

(matrix-ref m ri ci) β†’ any/c

  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?
Extracts the value of a cell in the matrix.

procedure

(matrix-set m ri ci v) β†’ matrix?

  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?
  v : any/c
Semi-persistently modifies m.

procedure

(matrix-set! m ri ci v) β†’ void

  m : matrix?
  ri : exact-nonnegative-integer?
  ci : exact-nonnegative-integer?
  v : any/c
Destructively modifies m.

procedure

(matrix-fold m row-f cell-f acc) β†’ any/c

  m : matrix?
  row-f : (exact-nonnegative-integer? any/c . -> . any/c)
  cell-f : (exact-nonnegative-integer? exact-nonnegative-integer? any/c any/c . -> . any/c)
  acc : any/c
Like foldr but for matrices. row-f is called with the result of cell-f from the last column in the row. cell-f is called from left to right.

procedure

(display-matrix m) β†’ void

  m : matrix?
displays the cells of m with (newline) separating rows.