module Array2: sig .. end
Two-dimensional arrays. The Array2
structure provides operations
similar to those of Bigarray.Genarray
, but specialized to the
case of two-dimensional arrays.
type t('a, 'b, 'c);
The type of two-dimensional Bigarrays whose elements have
OCaml type 'a
, representation kind 'b
, and memory layout 'c
.
let create:
(Bigarray.kind('a, 'b), Bigarray.layout('c), int, int) => t('a, 'b, 'c);
Array2.create kind layout dim1 dim2
returns a new Bigarray of
two dimensions, whose size is dim1
in the first dimension
and dim2
in the second dimension. kind
and layout
determine the array element kind and the array layout
as described for Bigarray.Genarray.create
.
let init:
(Bigarray.kind('a, 'b), Bigarray.layout('c), int, int, (int, int) => 'a) =>
t('a, 'b, 'c);
Array2.init kind layout dim1 dim2 f
returns a new Bigarray b
of two dimensions, whose size is dim2
in the first dimension
and dim2
in the second dimension. kind
and layout
determine the array element kind and the array layout
as described for Bigarray.Genarray.create
.
Each element Array2.get b i j
of the array is initialized to
the result of f i j
.
In other words, Array2.init kind layout dim1 dim2 f
tabulates
the results of f
applied to the indices of a new Bigarray whose
layout is described by kind
, layout
, dim1
and dim2
.
let dim1: t('a, 'b, 'c) => int;
Return the first dimension of the given two-dimensional Bigarray.
let dim2: t('a, 'b, 'c) => int;
Return the second dimension of the given two-dimensional Bigarray.
let kind: t('a, 'b, 'c) => Bigarray.kind('a, 'b);
Return the kind of the given Bigarray.
let layout: t('a, 'b, 'c) => Bigarray.layout('c);
Return the layout of the given Bigarray.
let change_layout: (t('a, 'b, 'c), Bigarray.layout('d)) => t('a, 'b, 'd);
Array2.change_layout a layout
returns a Bigarray with the
specified layout
, sharing the data with a
(and hence having
the same dimensions as a
). No copying of elements is involved: the
new array and the original array share the same storage space.
The dimensions are reversed, such that get v [| a; b |]
in
C layout becomes get v [| b+1; a+1 |]
in Fortran layout.
let size_in_bytes: t('a, 'b, 'c) => int;
size_in_bytes a
is the number of elements in a
multiplied by a
's Bigarray.kind_size_in_bytes
.
let get: (t('a, 'b, 'c), int, int) => 'a;
Array2.get a x y
, also written a.{x,y}
,
returns the element of a
at coordinates (x
, y
).
x
and y
must be within the bounds
of a
, as described for Bigarray.Genarray.get
;
otherwise, Invalid_argument
is raised.
let set: (t('a, 'b, 'c), int, int, 'a) => unit;
Array2.set a x y v
, or alternatively a.{x,y} <- v
,
stores the value v
at coordinates (x
, y
) in a
.
x
and y
must be within the bounds of a
,
as described for Bigarray.Genarray.set
;
otherwise, Invalid_argument
is raised.
let sub_left:
(t('a, 'b, Bigarray.c_layout), int, int) => t('a, 'b, Bigarray.c_layout);
Extract a two-dimensional sub-array of the given two-dimensional
Bigarray by restricting the first dimension.
See Bigarray.Genarray.sub_left
for more details.
Array2.sub_left
applies only to arrays with C layout.
let sub_right:
(t('a, 'b, Bigarray.fortran_layout), int, int) =>
t('a, 'b, Bigarray.fortran_layout);
Extract a two-dimensional sub-array of the given two-dimensional
Bigarray by restricting the second dimension.
See Bigarray.Genarray.sub_right
for more details.
Array2.sub_right
applies only to arrays with Fortran layout.
let slice_left:
(t('a, 'b, Bigarray.c_layout), int) =>
Bigarray.Array1.t('a, 'b, Bigarray.c_layout);
Extract a row (one-dimensional slice) of the given two-dimensional
Bigarray. The integer parameter is the index of the row to
extract. See Bigarray.Genarray.slice_left
for more details.
Array2.slice_left
applies only to arrays with C layout.
let slice_right:
(t('a, 'b, Bigarray.fortran_layout), int) =>
Bigarray.Array1.t('a, 'b, Bigarray.fortran_layout);
Extract a column (one-dimensional slice) of the given
two-dimensional Bigarray. The integer parameter is the
index of the column to extract. See Bigarray.Genarray.slice_right
for more details. Array2.slice_right
applies only to arrays
with Fortran layout.
let blit: (t('a, 'b, 'c), t('a, 'b, 'c)) => unit;
Copy the first Bigarray to the second Bigarray.
See Bigarray.Genarray.blit
for more details.
let fill: (t('a, 'b, 'c), 'a) => unit;
Fill the given Bigarray with the given value.
See Bigarray.Genarray.fill
for more details.
let of_array:
(Bigarray.kind('a, 'b), Bigarray.layout('c), array(array('a))) =>
t('a, 'b, 'c);
Build a two-dimensional Bigarray initialized from the given array of arrays.
let unsafe_get: (t('a, 'b, 'c), int, int) => 'a;
Like Bigarray.Array2.get
, but bounds checking is not always
performed.
let unsafe_set: (t('a, 'b, 'c), int, int, 'a) => unit;
Like Bigarray.Array2.set
, but bounds checking is not always
performed.