module Bigarray: sig end
This module implements multidimensional arrays of integers and floatingpoint numbers, thereafter referred to as ``big arrays''. The implementation allows efficient sharing of large numerical arrays between Caml code and C or Fortran numerical libraries.
Concerning the naming conventions, users of this module are encouraged
to do open Bigarray
in their source, then refer to array types and
operations via short dot notation, e.g. Array1.t
or Array2.sub
.
Big arrays support all the Caml adhoc polymorphic operations:
=
, <>
, <=
, etc, as well as Pervasives.compare
);Hash
);Pervasives.output_value
and Pervasives.input_value
, as well as the functions from the
Marshal
module).
Element kinds

Bigarray.float32_elt
),Bigarray.float64_elt
),Bigarray.complex32_elt
),Bigarray.complex64_elt
),Bigarray.int8_signed_elt
or Bigarray.int8_unsigned_elt
),Bigarray.int16_signed_elt
or Bigarray.int16_unsigned_elt
),Bigarray.int_elt
),Bigarray.int32_elt
),Bigarray.int64_elt
),Bigarray.nativeint_elt
).type float32_elt
type float64_elt
type complex32_elt
type complex64_elt
type int8_signed_elt
type int8_unsigned_elt
type int16_signed_elt
type int16_unsigned_elt
type int_elt
type int32_elt
type int64_elt
type nativeint_elt
type ('a, 'b
) kind
float32_elt
contains
32bit single precision floats, but reading or writing one of
its elements from Caml uses the Caml type float
, which is
64bit double precision floats.
The abstract type ('a, 'b) kind
captures this association
of a Caml type 'a
for values read or written in the big array,
and of an element kind 'b
which represents the actual contents
of the big array. The following predefined values of type
kind
list all possible associations of Caml types with
element kinds:
val float32 : (float, float32_elt) kind
Bigarray.char
.val float64 : (float, float64_elt) kind
Bigarray.char
.val complex32 : (Complex.t, complex32_elt) kind
Bigarray.char
.val complex64 : (Complex.t, complex64_elt) kind
Bigarray.char
.val int8_signed : (int, int8_signed_elt) kind
Bigarray.char
.val int8_unsigned : (int, int8_unsigned_elt) kind
Bigarray.char
.val int16_signed : (int, int16_signed_elt) kind
Bigarray.char
.val int16_unsigned : (int, int16_unsigned_elt) kind
Bigarray.char
.val int : (int, int_elt) kind
Bigarray.char
.val int32 : (int32, int32_elt) kind
Bigarray.char
.val int64 : (int64, int64_elt) kind
Bigarray.char
.val nativeint : (nativeint, nativeint_elt) kind
Bigarray.char
.val char : (char, int8_unsigned_elt) kind
float32_elt
and float64_elt
are
accessed using the Caml type float
. Big arrays of complex kinds
complex32_elt
, complex64_elt
are accessed with the Caml type
Complex.t
. Big arrays of
integer kinds are accessed using the smallest Caml integer
type large enough to represent the array elements:
int
for 8 and 16bit integer bigarrays, as well as Camlinteger
bigarrays; int32
for 32bit integer bigarrays; int64
for 64bit integer bigarrays; and nativeint
for
platformnative integer bigarrays. Finally, big arrays of
kind int8_unsigned_elt
can also be accessed as arrays of
characters instead of arrays of small integers, by using
the kind value char
instead of int8_unsigned
.
Array layouts

type c_layout
type fortran_layout
In the Cstyle layout, array indices start at 0, and
multidimensional arrays are laid out in rowmajor format.
That is, for a twodimensional array, all elements of
row 0 are contiguous in memory, followed by all elements of
row 1, etc. In other terms, the array elements at (x,y)
and (x, y+1)
are adjacent in memory.
In the Fortranstyle layout, array indices start at 1, and
multidimensional arrays are laid out in columnmajor format.
That is, for a twodimensional array, all elements of
column 0 are contiguous in memory, followed by all elements of
column 1, etc. In other terms, the array elements at (x,y)
and (x+1, y)
are adjacent in memory.
Each layout style is identified at the type level by the
abstract types Bigarray.c_layout
and fortran_layout
respectively.
type 'a
layout
'a layout
represents one of the two supported
memory layouts: Cstyle if 'a
is Bigarray.c_layout
, Fortranstyle
if 'a
is Bigarray.fortran_layout
.
Supported layouts

The abstract values c_layout
and fortran_layout
represent
the two supported layouts at the level of values.
val c_layout : c_layout layout
val fortran_layout : fortran_layout layout
Generic arrays (of arbitrarily many dimensions)

module Genarray: sig end
Onedimensional arrays

module Array1: sig end
Twodimensional arrays

module Array2: sig end
Threedimensional arrays

module Array3: sig end
Coercions between generic big arrays and fixeddimension big arrays

val genarray_of_array1 : ('a, 'b, 'c) Array1.t > ('a, 'b, 'c) Genarray.t
val genarray_of_array2 : ('a, 'b, 'c) Array2.t > ('a, 'b, 'c) Genarray.t
val genarray_of_array3 : ('a, 'b, 'c) Array3.t > ('a, 'b, 'c) Genarray.t
val array1_of_genarray : ('a, 'b, 'c) Genarray.t > ('a, 'b, 'c) Array1.t
Invalid_arg
if the generic big array
does not have exactly one dimension.val array2_of_genarray : ('a, 'b, 'c) Genarray.t > ('a, 'b, 'c) Array2.t
Invalid_arg
if the generic big array
does not have exactly two dimensions.val array3_of_genarray : ('a, 'b, 'c) Genarray.t > ('a, 'b, 'c) Array3.t
Invalid_arg
if the generic big array
does not have exactly three dimensions.
Reshaping big arrays

val reshape : ('a, 'b, 'c) Genarray.t >
int array > ('a, 'b, 'c) Genarray.t
reshape b [d1;...;dN]
converts the big array b
to a
N
dimensional array of dimensions d1
...dN
. The returned
array and the original array b
share their data
and have the same layout. For instance, assuming that b
is a onedimensional array of dimension 12, reshape b [3;4]
returns a twodimensional array b'
of dimensions 3 and 4.
If b
has C layout, the element (x,y)
of b'
corresponds
to the element x * 3 + y
of b
. If b
has Fortran layout,
the element (x,y)
of b'
corresponds to the element
x + (y  1) * 4
of b
.
The returned big array must have exactly the same number of
elements as the original big array b
. That is, the product
of the dimensions of b
must be equal to i1 * ... * iN
.
Otherwise, Invalid_arg
is raised.val reshape_1 : ('a, 'b, 'c) Genarray.t > int > ('a, 'b, 'c) Array1.t
Bigarray.reshape
for reshaping to onedimensional arrays.val reshape_2 : ('a, 'b, 'c) Genarray.t >
int > int > ('a, 'b, 'c) Array2.t
Bigarray.reshape
for reshaping to twodimensional arrays.val reshape_3 : ('a, 'b, 'c) Genarray.t >
int > int > int > ('a, 'b, 'c) Array3.t
Bigarray.reshape
for reshaping to threedimensional arrays.