Maximum length of a normal array. The maximum length of a float array is
max_length/2
on 32-bit machines and max_length
on 64-bit machines.
Array.get a n
returns the element number n
of array a
.
The first element has number 0.
The last element has number Array.length a - 1
.
You can also write a.(n)
instead of Array.get a n
.
Raise Invalid_argument "index out of bounds"
if n
is outside the range 0 to (Array.length a - 1)
.
Array.set a n x
modifies array a
in place, replacing
element number n
with x
.
You can also write a.(n) <- x
instead of Array.set a n x
.
Raise Invalid_argument "index out of bounds"
if n
is outside the range 0 to Array.length a - 1
.
Unsafe version of get
. Can cause arbitrary behavior when used to for an
out-of-bounds array access
Unsafe version of set
. Can cause arbitrary behavior when used to for an
out-of-bounds array access
create ~len x
creates an array of length len
with the value x
populated in each
element
init n ~f
creates an array of length n
where the i
th element is initialized with
f i
(starting at zero)
Array.make_matrix dimx dimy e
returns a two-dimensional array
(an array of arrays) with first dimension dimx
and
second dimension dimy
. All the elements of this new matrix
are initially physically equal to e
.
The element (x,y
) of a matrix m
is accessed
with the notation m.(x).(y)
.
Raise Invalid_argument
if dimx
or dimy
is negative or
greater than Sys.max_array_length
.
If the value of e
is a floating-point number, then the maximum
size is only Sys.max_array_length / 2
.
Array.fill a ofs len x
modifies the array a
in place,
storing x
in elements number ofs
to ofs + len - 1
.
Raise Invalid_argument "Array.fill"
if ofs
and len
do not
designate a valid subarray of a
.
Array.fold_right f a ~init
computes
f a.(0) (f a.(1) ( ... (f a.(n-1) init) ...))
,
where n
is the length of the array a
.
normalize array index
returns a new index into the array such that if index is less
than zero, the returned index will "wrap around" -- i.e. array.(normalize array (-1))
returns the last element of the array.
slice array start stop
returns a fresh array including elements array.(start)
through array.(stop-1)
with the small tweak that the start and stop positions are
normalized and a stop index of 0 means the same thing a stop index of Array.length
array
. In summary, it's mostly like the slicing in Python or Matlab. One difference
is that a stop value of 0 here is like not specifying a stop value in Python.
of_list_map l ~f
is the same as of_list (List.map l ~f)
of_list_rev_map l ~f
is the same as rev_inplace (of_list_map l ~f)
modifies an array in place -- ar.(i)
will be set to f(ar.(i))
find_exn f t
returns the first a
in t
for which f t.(i)
is true.
It raises Not_found
if there is no such a
.
findi t f
returns the first index i
of t
for which f i t.(i)
is true
findi_exn t f
returns the first index i
of t
for which f i t.(i)
is
true. It raises Not_found
if there is no such element.
find_consecutive_duplicate t ~equal
returns the first pair of consecutive elements
(a1, a2)
in t
such that equal a1 a2
. They are returned in the same order as
they appear in t
.
reduce f [a1; ...; an]
is Some (f (... (f (f a1 a2) a3) ...) an)
.
Returns None
on the empty array.
permute ?random_state t
randomly permutes t
in place.
permute
side affects random_state
by repeated calls to Random.State.int
.
If random_state
is not supplied, permute
uses Random.State.default
.
truncate t ~len
drops length t - len
elements from the end of t
, changing t
so
that length t = len
afterwards. truncate
raises if len <= 0 || len > length
t
.