module Slap_size:sig
..end
Slap.Size
contains operations on sizes (the dimensions of vectors and
matrices).type'n
t = privateint
Evaluation of a term with singleton type 'n size
always results
in the natural number corresponding to phantom type parameter 'n
.
'n
is instantiated to a generative phantom type or a (phantom) type that
represents an arithmetic operation defined in this module. In either case,
only the equality of sizes is verified statically.
type
z
type 'n
s
'n s
corresponds to 'n + 1
.val zero : z t
typeone =
z s
val one : one t
typetwo =
z s s
val two : two t
typethree =
z s s s
val three : three t
typefour =
z s s s s
val four : four t
typefive =
z s s s s s
val five : five t
typesix =
z s s s s s
s
val six : six t
typeseven =
z s s s s s
s s
val seven : seven t
typeeight =
z s s s s s
s s s
val eight : eight t
typenine =
z s s s s s
s s s s
val nine : nine t
typeten =
z s s s s s
s s s s s
val ten : ten t
val succ : 'n t -> 'n s t
succ n
n
+ 1
val pred : 'n s t -> 'n t
pred n
returnsn - 1
type 'n
p
val pred_dyn : 'n t -> 'n p t
pred_dyn n
Invalid_arg
if n <= 0
.n
- 1
type ('m, 'n)
add
val add : 'm t -> 'n t -> ('m, 'n) add t
add m n
m
+ n
type ('m, 'n)
sub
val sub_dyn : 'm t -> 'n t -> ('m, 'n) sub t
sub_dyn m n
Invalid_argument
m
< n
m
- n
type ('m, 'n)
mul
val mul : 'm t -> 'n t -> ('m, 'n) mul t
mul m n
m
and n
type ('m, 'n)
div
val div_dyn : 'm t -> 'n t -> ('m, 'n) div t
div_dyn m n
Invalid_argument
n
is zerom
/ n
type ('m, 'n)
min
val min : 'm t -> 'n t -> ('m, 'n) min t
min m n
m
and n
type ('m, 'n)
max
val max : 'm t -> 'n t -> ('m, 'n) max t
max m n
m
and n
type 'n
packed
'n packed
corresponds to the packed storage size of a n
-by-n
matrix.val packed : 'n t -> 'n packed t
packed n
computes the packed storage size of a n
-by-n
matrix.val unpacked : 'n packed t -> 'n t
unpacked n
computes the inverse of the packed storage size, i.e.,
unpacked (packed n) = n
for all n
.type ('m, 'n, 'kl, 'ku)
geband
('m, 'n, 'kl, 'ku) geband
represents band storage size:
A 'm
-by-'n
band matrix with 'kl
subdiagonals and 'ku
superdiagonals
is stored in a ('kl+'ku+1)
-by-'n
matrix where 'kl, 'ku << min('m, 'n)
.
('m, 'n, 'kl, 'ku) geband
corresponds to the number of columns of a
band-storage-format matrix for such a band matrix.val geband_dyn : 'm t ->
'n t ->
'kl t ->
'ku t -> ('m, 'n, 'kl, 'ku) geband t
geband_dyn m n kl ku
computs the band storage size of m
-by-n
band
matrices with kl
subdiagonals and ku
superdiagonals.Invalid_argument
if m >= kl
and n >= ku
.type ('n, 'kd)
syband
('n, 'kd) syband
represents symmetric or Hermitian band storage size:
A n
-by-n
symmetric or Hermitian band matrix with kd
superdiagonals or
subdiagonals is stored in a (kd+1)
-by-n
matrix where kd << n
.
('n, 'kd) syband
corresponds to the number of columns of a
band-storage-format matrix for such a symmetric band matrix.val syband_dyn : 'n t -> 'kd t -> ('n, 'kd) syband t
syband_dyn n kd
computs the band storage size of symmetric or Hermitian
band matrices with kd
superdiagonals or subdiagonals.Invalid_argument
if kd >= n
.type('m, 'n, 'kl, 'ku)
luband =('m, 'n, 'kl, ('kl, 'ku) add) geband
('m, 'n, 'kl, 'ku) luband
represents band storage size for LU
factorization: A 'm
-by-'n
band matrix with 'kl
subdiagonals and 'ku
superdiagonals for LU factorization is stored in band storage format with
'kl+'ku
superdiagonals.val luband_dyn : 'm t ->
'n t ->
'kl t ->
'ku t -> ('m, 'n, 'kl, 'ku) luband t
luband_dyn m n kl ku
computs the band storage size for LU factorization of
m
-by-n
band matrices with kl
subdiagonals and ku
superdiagonals.Invalid_argument
if m >= kl
and n >= ku
.module type SIZE =sig
..end
exists n. n Size.t
.
val to_int : 'n t -> int
val of_int_dyn : int -> (module Slap_size.SIZE)
module N = (val of_int_dyn n : SIZE)
Invalid_argument
the given size is negative.N
containing the size N.value
(= n
) that has the type
N.n Size.t
with a generative phantom type N.n
as a package of an
existential quantified sized type like exists n. n Size.t
.val unsafe_of_int : int -> (module Slap_size.SIZE)
of_int_dyn
, but dynamic size checking is not performed.module Of_int_dyn:
of_int_dyn
.
type
dyn =
| |
SIZE : |
dyn
= exists n. n Size.t
.val of_int_c_dyn : int -> dyn
let SIZE n = of_int_c_dyn i
Invalid_argument
the given size is negative.SIZE
that has the size n
(= i
) that has the
existential quantified sized type exists n. n Size.t
.
"c" of of_int_c_dyn
means a "c"onstructor of GADT. This function is
available in OCaml 4.00 or above.
The following functions are iterators over [1; 2; ...; n]
where n
is a
size.
val fold_left : ('accum -> (module Slap_size.SIZE) -> 'accum) ->
'accum -> 'n t -> 'accum
fold_left f init n
is f (... (f (f init 1) 2) ...) n
.val fold_right : ((module Slap_size.SIZE) -> 'accum -> 'accum) ->
'n t -> 'accum -> 'accum
fold_right f n init
is f 1 (f 2 (... (f n init) ...))
.val iter : ((module Slap_size.SIZE) -> unit) -> 'n t -> unit
iter f n
is f 1; f 2; ...; f n
.val riter : ((module Slap_size.SIZE) -> unit) -> 'n t -> unit
riter f n
is f n; ...; f 2; f 1
.
The following functions are iterators over [1; 2; ...; to_int n]
where
n
is a size.
val fold_lefti : ('accum -> int -> 'accum) -> 'accum -> 'n t -> 'accum
fold_lefti f init n
is f (... (f (f init 1) 2) ...) (to_int n)
.val fold_righti : (int -> 'accum -> 'accum) -> 'n t -> 'accum -> 'accum
fold_righti f n init
is f 1 (f 2 (... (f (to_int n) init) ...))
.val iteri : (int -> unit) -> 'n t -> unit
iteri f n
is f 1; f 2; ...; f (to_int n)
.val riteri : (int -> unit) -> 'n t -> unit
riteri f n
is f (to_int n); ...; f 2; f 1
.val iszero : 'n t -> bool
iszero n
returns true
if size n
is zero.val nonzero : 'n t -> bool
nonzero n
returns true
if size n
is not zero.val __expose : 'n t -> int
val __unexpose : int -> 'n t