ATSLIB/libats/ML/matrix0
The functions declared in this package are primarily for supporting
ML-style processing of persistent matrices. Note that a plain matrix (as is in
C) is not available in languages such as Java and ML due to the need for
performing matrix-bounds checking at run-time. Instead, matrices in these
languages are always bundled together with their dimensions. In ATS, the type
matrix0(T) is for a matrix paired with its dimension in which
elements of the type T are stored.
Synopsis
stadef matrix0 = matrix0_vt0ype_type
Synopsis
abstype
matrix0_vt0ype_type
(a: vt@ype) = ptr
Synopsis
fun{}
matrix0_of_mtrxszref
{a:vt0p}(mtrxszref(a)):<> matrix0(a)
Synopsis
fun{}
mtrxszref_of_matrix0
{a:vt0p}(M: matrix0(a)):<> mtrxszref(a)
Synopsis
fun{}
matrix0_get_nrow{a:vt0p}(M: matrix0 a):<> size_t
Description
This function returns the number of rows of the matrix associated with a given
matrix0-value.
Synopsis
fun{}
matrix0_get_ncol{a:vt0p}(M: matrix0 a):<> size_t
Description
This function returns the number of columns of the matrix associated with a given
matrix0-value.
Synopsis
overload matrix0_make_elt with matrix0_make_elt_int
overload matrix0_make_elt with matrix0_make_elt_size
Description
This function creates a matrix0-value of a given dimension in
which each matrix-cell is initialized with a given value (3rd argument).
Synopsis
overload matrix0_get_at with matrix0_get_at_int
overload matrix0_get_at with matrix0_get_at_size
Synopsis
fun{a:t0p}
matrix0_get_at_int
(M: matrix0(a), i: int, j: int):<!exnref> a
Description
Given an matrix0-value M of dimension m by n and two indices i and j, this
function returns M[i,j] if i and j are valid (that is, 0 <= i < m and 0 <=
j < n), or it raises the exception MatrixSubscriptExn.
Synopsis
overload matrix0_set_at with matrix0_set_at_int
overload matrix0_set_at with matrix0_set_at_size
Synopsis
fun{a:t0p}
matrix0_set_at_int
(M: matrix0(a), i: int, j: int, x: a):<!exnrefwrt> void
Description
Given an matrix0-value M of dimension m by n, two indicies i and j, and a
value x, this function assigns x to M[i,j] if i and j are valid (that is, 0
<= i < m and 0 <= j < n), or it raises the exception
MatrixSubscriptExn.
Synopsis
fun
{a:vt0p}
matrix0_tabulate
{m,n:int}
( nrow: size_t(m)
, ncol: size_t(n)
, fopr: cfun(sizeLt(m), sizeLt(n), a)
) : matrix0(a)
Description
Given sizes nrow and ncol and a function f, this function returns a
matrix0-value M of dimension nrow by ncol such that each M[i,j] is
initialized with the value returned by f(i,j), where i ranges from 0 until
nrow-1, inclusive, and j from 0 until ncol-1, inclusive.
Synopsis
fun
{a:vt0p}
matrix0_foreach
(
M : matrix0(a), fwork: (&a >> _) -<cloref1> void
) : void
Description
Given a matrix0-value M and a closure-function f,
matrix0_foreach applies f to each matrix-cell contained in M.
Synopsis
fun
{a:vt0p}
matrix0_iforeach
(
M : matrix0(a), fwork: (size_t, size_t, &a >> _) -<cloref1> void
) : void
Description
Given a matrix0-value M of dimension m by n and a closure-function f,
matrix0_iforeach applies f to i, j and the matrix-cell (i, j),
where i ranges from 0 to m-1, inclusive, and j from 0 to n-1, inclusive.
Synopsis
fun{
res:vt0p}{a:vt0p
} matrix0_foldleft
(
M: matrix0(a), ini: res, fopr: (res, &a) -<cloref1> res
) : res
Synopsis
fun{
res:vt0p}{a:vt0p
} matrix0_ifoldleft
(
M: matrix0(a), ini: res, fopr: (res, size_t, size_t, &a) -<cloref1> res
) : res
Synopsis
overload [] with matrix0_get_at_int of 0
overload [] with matrix0_set_at_int of 0
overload [] with matrix0_get_at_size of 0
overload [] with matrix0_set_at_size of 0
Synopsis
overload .nrow with matrix0_get_nrow
Synopsis
overload .ncol with matrix0_get_ncol
Synopsis
overload fprint with fprint_matrix0
overload fprint with fprint_matrix0_sep