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

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.