857 lines
12 KiB
HTML
857 lines
12 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of Bigarray.Genarray</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>Bigarray.Genarray</H1>
|
|
Section: OCaml library (3o)<BR>Updated: 2020-01-30<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
Bigarray.Genarray - no description
|
|
<A NAME="lbAC"> </A>
|
|
<H2>Module</H2>
|
|
|
|
Module Bigarray.Genarray
|
|
<A NAME="lbAD"> </A>
|
|
<H2>Documentation</H2>
|
|
|
|
<P>
|
|
Module
|
|
<B>Genarray</B>
|
|
|
|
<BR> :
|
|
<B>sig end</B>
|
|
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>type </I>
|
|
|
|
<B>('a, 'b, 'c)</B>
|
|
|
|
<I>t </I>
|
|
|
|
<P>
|
|
<P>
|
|
The type
|
|
<B>Genarray.t</B>
|
|
|
|
is the type of Bigarrays with variable
|
|
numbers of dimensions. Any number of dimensions between 0 and 16
|
|
is supported.
|
|
<P>
|
|
The three type parameters to
|
|
<B>Genarray.t</B>
|
|
|
|
identify the array element
|
|
kind and layout, as follows:
|
|
<P>
|
|
-the first parameter,
|
|
<B>'a</B>
|
|
|
|
, is the OCaml type for accessing array
|
|
elements (
|
|
<B>float</B>
|
|
|
|
,
|
|
<B>int</B>
|
|
|
|
,
|
|
<B>int32</B>
|
|
|
|
,
|
|
<B>int64</B>
|
|
|
|
,
|
|
<B>nativeint</B>
|
|
|
|
);
|
|
<P>
|
|
-the second parameter,
|
|
<B>'b</B>
|
|
|
|
, is the actual kind of array elements
|
|
(
|
|
<B>float32_elt</B>
|
|
|
|
,
|
|
<B>float64_elt</B>
|
|
|
|
,
|
|
<B>int8_signed_elt</B>
|
|
|
|
,
|
|
<B>int8_unsigned_elt</B>
|
|
|
|
,
|
|
etc);
|
|
<P>
|
|
-the third parameter,
|
|
<B>'c</B>
|
|
|
|
, identifies the array layout
|
|
(
|
|
<B>c_layout</B>
|
|
|
|
or
|
|
<B>fortran_layout</B>
|
|
|
|
).
|
|
<P>
|
|
For instance,
|
|
<B>(float, float32_elt, fortran_layout) Genarray.t</B>
|
|
|
|
is the type of generic Bigarrays containing 32-bit floats
|
|
in Fortran layout; reads and writes in this array use the
|
|
OCaml type
|
|
<B>float</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val create </I>
|
|
|
|
:
|
|
<B>('a, 'b) Bigarray.kind -></B>
|
|
|
|
<B>'c Bigarray.layout -> int array -> ('a, 'b, 'c) t</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>Genarray.create kind layout dimensions</B>
|
|
|
|
returns a new Bigarray
|
|
whose element kind is determined by the parameter
|
|
<B>kind</B>
|
|
|
|
(one of
|
|
<B>float32</B>
|
|
|
|
,
|
|
<B>float64</B>
|
|
|
|
,
|
|
<B>int8_signed</B>
|
|
|
|
, etc) and whose layout is
|
|
determined by the parameter
|
|
<B>layout</B>
|
|
|
|
(one of
|
|
<B>c_layout</B>
|
|
|
|
or
|
|
<B>fortran_layout</B>
|
|
|
|
). The
|
|
<B>dimensions</B>
|
|
|
|
parameter is an array of
|
|
integers that indicate the size of the Bigarray in each dimension.
|
|
The length of
|
|
<B>dimensions</B>
|
|
|
|
determines the number of dimensions
|
|
of the Bigarray.
|
|
<P>
|
|
For instance,
|
|
<B>Genarray.create int32 c_layout [|4;6;8|]</B>
|
|
|
|
returns a fresh Bigarray of 32-bit integers, in C layout,
|
|
having three dimensions, the three dimensions being 4, 6 and 8
|
|
respectively.
|
|
<P>
|
|
Bigarrays returned by
|
|
<B>Genarray.create</B>
|
|
|
|
are not initialized:
|
|
the initial values of array elements is unspecified.
|
|
<P>
|
|
<P>
|
|
<B>Genarray.create</B>
|
|
|
|
raises
|
|
<B>Invalid_argument</B>
|
|
|
|
if the number of dimensions
|
|
is not in the range 0 to 16 inclusive, or if one of the dimensions
|
|
is negative.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val num_dims </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> int</B>
|
|
|
|
<P>
|
|
Return the number of dimensions of the given Bigarray.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val dims </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> int array</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>Genarray.dims a</B>
|
|
|
|
returns all dimensions of the Bigarray
|
|
<B>a</B>
|
|
|
|
,
|
|
as an array of integers of length
|
|
<B>Genarray.num_dims a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val nth_dim </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> int -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>Genarray.nth_dim a n</B>
|
|
|
|
returns the
|
|
<B>n</B>
|
|
|
|
-th dimension of the
|
|
Bigarray
|
|
<B>a</B>
|
|
|
|
. The first dimension corresponds to
|
|
<B>n = 0</B>
|
|
|
|
;
|
|
the second dimension corresponds to
|
|
<B>n = 1</B>
|
|
|
|
; the last dimension,
|
|
to
|
|
<B>n = Genarray.num_dims a - 1</B>
|
|
|
|
.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>n</B>
|
|
|
|
is less than 0 or greater or equal than
|
|
<B>Genarray.num_dims a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val kind </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> ('a, 'b) Bigarray.kind</B>
|
|
|
|
<P>
|
|
Return the kind of the given Bigarray.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val layout </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> 'c Bigarray.layout</B>
|
|
|
|
<P>
|
|
Return the layout of the given Bigarray.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val change_layout </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -></B>
|
|
|
|
<B>'d Bigarray.layout -> ('a, 'b, 'd) t</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>Genarray.change_layout a layout</B>
|
|
|
|
returns a Bigarray with the
|
|
specified
|
|
<B>layout</B>
|
|
|
|
, sharing the data with
|
|
<B>a</B>
|
|
|
|
(and hence having
|
|
the same dimensions as
|
|
<B>a</B>
|
|
|
|
). No copying of elements is involved: the
|
|
new array and the original array share the same storage space.
|
|
The dimensions are reversed, such that
|
|
<B>get v [| a; b |]</B>
|
|
|
|
in
|
|
C layout becomes
|
|
<B>get v [| b+1; a+1 |]</B>
|
|
|
|
in Fortran layout.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.04.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val size_in_bytes </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> int</B>
|
|
|
|
<P>
|
|
<P>
|
|
<B>size_in_bytes a</B>
|
|
|
|
is the number of elements in
|
|
<B>a</B>
|
|
|
|
multiplied
|
|
by
|
|
<B>a</B>
|
|
|
|
's
|
|
<B>Bigarray.kind_size_in_bytes</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Since</B>
|
|
|
|
4.03.0
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val get </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> int array -> 'a</B>
|
|
|
|
<P>
|
|
Read an element of a generic Bigarray.
|
|
<B>Genarray.get a [|i1; ...; iN|]</B>
|
|
|
|
returns the element of
|
|
<B>a</B>
|
|
|
|
whose coordinates are
|
|
<B>i1</B>
|
|
|
|
in the first dimension,
|
|
<B>i2</B>
|
|
|
|
in
|
|
the second dimension, ...,
|
|
<B>iN</B>
|
|
|
|
in the
|
|
<B>N</B>
|
|
|
|
-th dimension.
|
|
<P>
|
|
If
|
|
<B>a</B>
|
|
|
|
has C layout, the coordinates must be greater or equal than 0
|
|
and strictly less than the corresponding dimensions of
|
|
<B>a</B>
|
|
|
|
.
|
|
If
|
|
<B>a</B>
|
|
|
|
has Fortran layout, the coordinates must be greater or equal
|
|
than 1 and less or equal than the corresponding dimensions of
|
|
<B>a</B>
|
|
|
|
.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if the array
|
|
<B>a</B>
|
|
|
|
does not have exactly
|
|
<B>N</B>
|
|
|
|
dimensions, or if the coordinates are outside the array bounds.
|
|
<P>
|
|
If
|
|
<B>N > 3</B>
|
|
|
|
, alternate syntax is provided: you can write
|
|
<B>a.{i1, i2, ..., iN}</B>
|
|
|
|
instead of
|
|
<B>Genarray.get a [|i1; ...; iN|]</B>
|
|
|
|
.
|
|
(The syntax
|
|
<B>a.{...}</B>
|
|
|
|
with one, two or three coordinates is
|
|
reserved for accessing one-, two- and three-dimensional arrays
|
|
as described below.)
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val set </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> int array -> 'a -> unit</B>
|
|
|
|
<P>
|
|
Assign an element of a generic Bigarray.
|
|
<B>Genarray.set a [|i1; ...; iN|] v</B>
|
|
|
|
stores the value
|
|
<B>v</B>
|
|
|
|
in the
|
|
element of
|
|
<B>a</B>
|
|
|
|
whose coordinates are
|
|
<B>i1</B>
|
|
|
|
in the first dimension,
|
|
<B>i2</B>
|
|
|
|
in the second dimension, ...,
|
|
<B>iN</B>
|
|
|
|
in the
|
|
<B>N</B>
|
|
|
|
-th dimension.
|
|
<P>
|
|
The array
|
|
<B>a</B>
|
|
|
|
must have exactly
|
|
<B>N</B>
|
|
|
|
dimensions, and all coordinates
|
|
must lie inside the array bounds, as described for
|
|
<B>Genarray.get</B>
|
|
|
|
;
|
|
otherwise,
|
|
<B>Invalid_argument</B>
|
|
|
|
is raised.
|
|
<P>
|
|
If
|
|
<B>N > 3</B>
|
|
|
|
, alternate syntax is provided: you can write
|
|
<B>a.{i1, i2, ..., iN} <- v</B>
|
|
|
|
instead of
|
|
<B>Genarray.set a [|i1; ...; iN|] v</B>
|
|
|
|
.
|
|
(The syntax
|
|
<B>a.{...} <- v</B>
|
|
|
|
with one, two or three coordinates is
|
|
reserved for updating one-, two- and three-dimensional arrays
|
|
as described below.)
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sub_left </I>
|
|
|
|
:
|
|
<B>('a, 'b, Bigarray.c_layout) t -></B>
|
|
|
|
<B>int -> int -> ('a, 'b, Bigarray.c_layout) t</B>
|
|
|
|
<P>
|
|
Extract a sub-array of the given Bigarray by restricting the
|
|
first (left-most) dimension.
|
|
<B>Genarray.sub_left a ofs len</B>
|
|
|
|
returns a Bigarray with the same number of dimensions as
|
|
<B>a</B>
|
|
|
|
,
|
|
and the same dimensions as
|
|
<B>a</B>
|
|
|
|
, except the first dimension,
|
|
which corresponds to the interval
|
|
<B>[ofs ... ofs + len - 1]</B>
|
|
|
|
of the first dimension of
|
|
<B>a</B>
|
|
|
|
. No copying of elements is
|
|
involved: the sub-array and the original array share the same
|
|
storage space. In other terms, the element at coordinates
|
|
<B>[|i1; ...; iN|]</B>
|
|
|
|
of the sub-array is identical to the
|
|
element at coordinates
|
|
<B>[|i1+ofs; ...; iN|]</B>
|
|
|
|
of the original
|
|
array
|
|
<B>a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Genarray.sub_left</B>
|
|
|
|
applies only to Bigarrays in C layout.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>ofs</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate
|
|
a valid sub-array of
|
|
<B>a</B>
|
|
|
|
, that is, if
|
|
<B>ofs < 0</B>
|
|
|
|
, or
|
|
<B>len < 0</B>
|
|
|
|
,
|
|
or
|
|
<B>ofs + len > Genarray.nth_dim a 0</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val sub_right </I>
|
|
|
|
:
|
|
<B>('a, 'b, Bigarray.fortran_layout) t -></B>
|
|
|
|
<B>int -> int -> ('a, 'b, Bigarray.fortran_layout) t</B>
|
|
|
|
<P>
|
|
Extract a sub-array of the given Bigarray by restricting the
|
|
last (right-most) dimension.
|
|
<B>Genarray.sub_right a ofs len</B>
|
|
|
|
returns a Bigarray with the same number of dimensions as
|
|
<B>a</B>
|
|
|
|
,
|
|
and the same dimensions as
|
|
<B>a</B>
|
|
|
|
, except the last dimension,
|
|
which corresponds to the interval
|
|
<B>[ofs ... ofs + len - 1]</B>
|
|
|
|
of the last dimension of
|
|
<B>a</B>
|
|
|
|
. No copying of elements is
|
|
involved: the sub-array and the original array share the same
|
|
storage space. In other terms, the element at coordinates
|
|
<B>[|i1; ...; iN|]</B>
|
|
|
|
of the sub-array is identical to the
|
|
element at coordinates
|
|
<B>[|i1; ...; iN+ofs|]</B>
|
|
|
|
of the original
|
|
array
|
|
<B>a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<B>Genarray.sub_right</B>
|
|
|
|
applies only to Bigarrays in Fortran layout.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>ofs</B>
|
|
|
|
and
|
|
<B>len</B>
|
|
|
|
do not designate
|
|
a valid sub-array of
|
|
<B>a</B>
|
|
|
|
, that is, if
|
|
<B>ofs < 1</B>
|
|
|
|
, or
|
|
<B>len < 0</B>
|
|
|
|
,
|
|
or
|
|
<B>ofs + len > Genarray.nth_dim a (Genarray.num_dims a - 1)</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val slice_left </I>
|
|
|
|
:
|
|
<B>('a, 'b, Bigarray.c_layout) t -></B>
|
|
|
|
<B>int array -> ('a, 'b, Bigarray.c_layout) t</B>
|
|
|
|
<P>
|
|
Extract a sub-array of lower dimension from the given Bigarray
|
|
by fixing one or several of the first (left-most) coordinates.
|
|
<B>Genarray.slice_left a [|i1; ... ; iM|]</B>
|
|
|
|
returns the 'slice'
|
|
of
|
|
<B>a</B>
|
|
|
|
obtained by setting the first
|
|
<B>M</B>
|
|
|
|
coordinates to
|
|
<B>i1</B>
|
|
|
|
, ...,
|
|
<B>iM</B>
|
|
|
|
. If
|
|
<B>a</B>
|
|
|
|
has
|
|
<B>N</B>
|
|
|
|
dimensions, the slice has
|
|
dimension
|
|
<B>N - M</B>
|
|
|
|
, and the element at coordinates
|
|
<B>[|j1; ...; j(N-M)|]</B>
|
|
|
|
in the slice is identical to the element
|
|
at coordinates
|
|
<B>[|i1; ...; iM; j1; ...; j(N-M)|]</B>
|
|
|
|
in the original
|
|
array
|
|
<B>a</B>
|
|
|
|
. No copying of elements is involved: the slice and
|
|
the original array share the same storage space.
|
|
<P>
|
|
<P>
|
|
<B>Genarray.slice_left</B>
|
|
|
|
applies only to Bigarrays in C layout.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>M >= N</B>
|
|
|
|
, or if
|
|
<B>[|i1; ... ; iM|]</B>
|
|
|
|
is outside the bounds of
|
|
<B>a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val slice_right </I>
|
|
|
|
:
|
|
<B>('a, 'b, Bigarray.fortran_layout) t -></B>
|
|
|
|
<B>int array -> ('a, 'b, Bigarray.fortran_layout) t</B>
|
|
|
|
<P>
|
|
Extract a sub-array of lower dimension from the given Bigarray
|
|
by fixing one or several of the last (right-most) coordinates.
|
|
<B>Genarray.slice_right a [|i1; ... ; iM|]</B>
|
|
|
|
returns the 'slice'
|
|
of
|
|
<B>a</B>
|
|
|
|
obtained by setting the last
|
|
<B>M</B>
|
|
|
|
coordinates to
|
|
<B>i1</B>
|
|
|
|
, ...,
|
|
<B>iM</B>
|
|
|
|
. If
|
|
<B>a</B>
|
|
|
|
has
|
|
<B>N</B>
|
|
|
|
dimensions, the slice has
|
|
dimension
|
|
<B>N - M</B>
|
|
|
|
, and the element at coordinates
|
|
<B>[|j1; ...; j(N-M)|]</B>
|
|
|
|
in the slice is identical to the element
|
|
at coordinates
|
|
<B>[|j1; ...; j(N-M); i1; ...; iM|]</B>
|
|
|
|
in the original
|
|
array
|
|
<B>a</B>
|
|
|
|
. No copying of elements is involved: the slice and
|
|
the original array share the same storage space.
|
|
<P>
|
|
<P>
|
|
<B>Genarray.slice_right</B>
|
|
|
|
applies only to Bigarrays in Fortran layout.
|
|
Raise
|
|
<B>Invalid_argument</B>
|
|
|
|
if
|
|
<B>M >= N</B>
|
|
|
|
, or if
|
|
<B>[|i1; ... ; iM|]</B>
|
|
|
|
is outside the bounds of
|
|
<B>a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val blit </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unit</B>
|
|
|
|
<P>
|
|
Copy all elements of a Bigarray in another Bigarray.
|
|
<B>Genarray.blit src dst</B>
|
|
|
|
copies all elements of
|
|
<B>src</B>
|
|
|
|
into
|
|
<B>dst</B>
|
|
|
|
. Both arrays
|
|
<B>src</B>
|
|
|
|
and
|
|
<B>dst</B>
|
|
|
|
must have the same number of
|
|
dimensions and equal dimensions. Copying a sub-array of
|
|
<B>src</B>
|
|
|
|
to a sub-array of
|
|
<B>dst</B>
|
|
|
|
can be achieved by applying
|
|
<B>Genarray.blit</B>
|
|
|
|
to sub-array or slices of
|
|
<B>src</B>
|
|
|
|
and
|
|
<B>dst</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
<I>val fill </I>
|
|
|
|
:
|
|
<B>('a, 'b, 'c) t -> 'a -> unit</B>
|
|
|
|
<P>
|
|
Set all elements of a Bigarray to a given value.
|
|
<B>Genarray.fill a v</B>
|
|
|
|
stores the value
|
|
<B>v</B>
|
|
|
|
in all elements of
|
|
the Bigarray
|
|
<B>a</B>
|
|
|
|
. Setting only some elements of
|
|
<B>a</B>
|
|
|
|
to
|
|
<B>v</B>
|
|
|
|
can be achieved by applying
|
|
<B>Genarray.fill</B>
|
|
|
|
to a sub-array
|
|
or a slice of
|
|
<B>a</B>
|
|
|
|
.
|
|
<P>
|
|
<P>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="1"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="2"><A HREF="#lbAC">Module</A><DD>
|
|
<DT id="3"><A HREF="#lbAD">Documentation</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:36 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|