OCaml library : Bigarray.Array2 (original) (raw)
Module Bigarray.Array2
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 (!'a, !'b, !'c)
t
The type of two-dimensional Bigarrays whose elements have OCaml type 'a
, representation kind 'b
, and memory layout 'c
.
val create : ('a, 'b) [Bigarray.kind](Bigarray.html#TYPEkind) -> 'c [Bigarray.layout](Bigarray.html#TYPElayout) -> int -> int -> ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt)
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.
val init : ('a, 'b) [Bigarray.kind](Bigarray.html#TYPEkind) -> 'c [Bigarray.layout](Bigarray.html#TYPElayout) -> int -> int -> (int -> int -> 'a) -> ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt)
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
.
- Since 4.12
val dim1 : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> int
Return the first dimension of the given two-dimensional Bigarray.
val dim2 : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> int
Return the second dimension of the given two-dimensional Bigarray.
val kind : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> ('a, 'b) [Bigarray.kind](Bigarray.html#TYPEkind)
Return the kind of the given Bigarray.
val layout : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> 'c [Bigarray.layout](Bigarray.html#TYPElayout)
Return the layout of the given Bigarray.
val change_layout : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> 'd [Bigarray.layout](Bigarray.html#TYPElayout) -> ('a, 'b, 'd) [t](Bigarray.Array2.html#TYPEt)
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.
- Since 4.06
val size_in_bytes : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> int
- Since 4.03
val get : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> 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.
val set : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> 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.
val sub_left : ('a, 'b, [Bigarray.c_layout](Bigarray.html#TYPEc%5Flayout)) [t](Bigarray.Array2.html#TYPEt) -> int -> int -> ('a, 'b, [Bigarray.c_layout](Bigarray.html#TYPEc%5Flayout)) [t](Bigarray.Array2.html#TYPEt)
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.
val sub_right : ('a, 'b, [Bigarray.fortran_layout](Bigarray.html#TYPEfortran%5Flayout)) [t](Bigarray.Array2.html#TYPEt) -> int -> int -> ('a, 'b, [Bigarray.fortran_layout](Bigarray.html#TYPEfortran%5Flayout)) [t](Bigarray.Array2.html#TYPEt)
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.
val slice_left : ('a, 'b, [Bigarray.c_layout](Bigarray.html#TYPEc%5Flayout)) [t](Bigarray.Array2.html#TYPEt) -> int -> ('a, 'b, [Bigarray.c_layout](Bigarray.html#TYPEc%5Flayout)) [Bigarray.Array1.t](Bigarray.Array1.html#TYPEt)
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.
val slice_right : ('a, 'b, [Bigarray.fortran_layout](Bigarray.html#TYPEfortran%5Flayout)) [t](Bigarray.Array2.html#TYPEt) -> int -> ('a, 'b, [Bigarray.fortran_layout](Bigarray.html#TYPEfortran%5Flayout)) [Bigarray.Array1.t](Bigarray.Array1.html#TYPEt)
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.
val blit : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> unit
val fill : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> 'a -> unit
val of_array : ('a, 'b) [Bigarray.kind](Bigarray.html#TYPEkind) -> 'c [Bigarray.layout](Bigarray.html#TYPElayout) -> 'a array array -> ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt)
Build a two-dimensional Bigarray initialized from the given array of arrays.
val unsafe_get : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> int -> int -> 'a
val unsafe_set : ('a, 'b, 'c) [t](Bigarray.Array2.html#TYPEt) -> int -> int -> 'a -> unit