Provided by: ocaml-man_4.08.1-8_all

**NAME**

Stdlib.Bigarray - no description

**Module**

Module Stdlib.Bigarray

**Documentation**

ModuleBigarray:(moduleStdlib__bigarray)ElementkindsBigarrays can contain elements of the following kinds: -IEEE single precision (32 bits) floating-point numbers (Bigarray.float32_elt), -IEEE double precision (64 bits) floating-point numbers (Bigarray.float64_elt), -IEEE single precision (2 * 32 bits) floating-point complex numbers (Bigarray.complex32_elt), -IEEE double precision (2 * 64 bits) floating-point complex numbers (Bigarray.complex64_elt), -8-bit integers (signed or unsigned) (Bigarray.int8_signed_eltorBigarray.int8_unsigned_elt), -16-bit integers (signed or unsigned) (Bigarray.int16_signed_eltorBigarray.int16_unsigned_elt), -OCaml integers (signed, 31 bits on 32-bit architectures, 63 bits on 64-bit architectures) (Bigarray.int_elt), -32-bit signed integers (Bigarray.int32_elt), -64-bit signed integers (Bigarray.int64_elt), -platform-native signed integers (32 bits on 32-bit architectures, 64 bits on 64-bit architectures) (Bigarray.nativeint_elt). Each element kind is represented at the type level by one of the*_elttypes defined below (defined with a single constructor instead of abstract types for technical injectivity reasons).typefloat32_elt= | Float32_elttypefloat64_elt= | Float64_elttypeint8_signed_elt= | Int8_signed_elttypeint8_unsigned_elt= | Int8_unsigned_elttypeint16_signed_elt= | Int16_signed_elttypeint16_unsigned_elt= | Int16_unsigned_elttypeint32_elt= | Int32_elttypeint64_elt= | Int64_elttypeint_elt= | Int_elttypenativeint_elt= | Nativeint_elttypecomplex32_elt= | Complex32_elttypecomplex64_elt= | Complex64_elttype('a,'b)kind= | Float32:(float,float32_elt)kind| Float64:(float,float64_elt)kind| Int8_signed:(int,int8_signed_elt)kind| Int8_unsigned:(int,int8_unsigned_elt)kind| Int16_signed:(int,int16_signed_elt)kind| Int16_unsigned:(int,int16_unsigned_elt)kind| Int32:(int32,int32_elt)kind| Int64:(int64,int64_elt)kind| Int:(int,int_elt)kind| Nativeint:(nativeint,nativeint_elt)kind| Complex32:(Complex.t,complex32_elt)kind| Complex64:(Complex.t,complex64_elt)kind| Char:(char,int8_unsigned_elt)kindTo each element kind is associated an OCaml type, which is the type of OCaml values that can be stored in the Bigarray or read back from it. This type is not necessarily the same as the type of the array elements proper: for instance, a Bigarray whose elements are of kindfloat32_eltcontains 32-bit single precision floats, but reading or writing one of its elements from OCaml uses the OCaml typefloat, which is 64-bit double precision floats. The GADT type('a,'b)kindcaptures this association of an OCaml type'afor values read or written in the Bigarray, and of an element kind'bwhich represents the actual contents of the Bigarray. Its constructors list all possible associations of OCaml types with element kinds, and are re-exported below for backward-compatibility reasons. Using a generalized algebraic datatype (GADT) here allows writing well-typed polymorphic functions whose return type depend on the argument type, such as:letzero:typeab.(a,b)kind->a=function|Float32->0.0|Complex32->Complex.zero|Float64->0.0|Complex64->Complex.zero|Int8_signed->0|Int8_unsigned->0|Int16_signed->0|Int16_unsigned->0|Int32->0l|Int64->0L|Int->0|Nativeint->0n|Char->'\000'valfloat32:(float,float32_elt)kindSeeBigarray.char.valfloat64:(float,float64_elt)kindSeeBigarray.char.valcomplex32:(Complex.t,complex32_elt)kindSeeBigarray.char.valcomplex64:(Complex.t,complex64_elt)kindSeeBigarray.char.valint8_signed:(int,int8_signed_elt)kindSeeBigarray.char.valint8_unsigned:(int,int8_unsigned_elt)kindSeeBigarray.char.valint16_signed:(int,int16_signed_elt)kindSeeBigarray.char.valint16_unsigned:(int,int16_unsigned_elt)kindSeeBigarray.char.valint:(int,int_elt)kindSeeBigarray.char.valint32:(int32,int32_elt)kindSeeBigarray.char.valint64:(int64,int64_elt)kindSeeBigarray.char.valnativeint:(nativeint,nativeint_elt)kindSeeBigarray.char.valchar:(char,int8_unsigned_elt)kindAs shown by the types of the values above, Bigarrays of kindfloat32_eltandfloat64_eltare accessed using the OCaml typefloat. Bigarrays of complex kindscomplex32_elt,complex64_eltare accessed with the OCaml typeComplex.t. Bigarrays of integer kinds are accessed using the smallest OCaml integer type large enough to represent the array elements:intfor 8- and 16-bit integer Bigarrays, as well as OCaml-integer Bigarrays;int32for 32-bit integer Bigarrays;int64for 64-bit integer Bigarrays; andnativeintfor platform-native integer Bigarrays. Finally, Bigarrays of kindint8_unsigned_eltcan also be accessed as arrays of characters instead of arrays of small integers, by using the kind valuecharinstead ofint8_unsigned.valkind_size_in_bytes:('a,'b)kind->intkind_size_in_byteskis the number of bytes used to store an element of typek.Since4.03.0Arraylayoutstypec_layout= | C_layout_typ SeeBigarray.fortran_layout.typefortran_layout= | Fortran_layout_typ To facilitate interoperability with existing C and Fortran code, this library supports two different memory layouts for Bigarrays, one compatible with the C conventions, the other compatible with the Fortran conventions. In the C-style layout, array indices start at 0, and multi-dimensional arrays are laid out in row-major format. That is, for a two-dimensional 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 Fortran-style layout, array indices start at 1, and multi-dimensional arrays are laid out in column-major format. That is, for a two-dimensional 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 phantom typesBigarray.c_layoutandBigarray.fortran_layoutrespectively.SupportedlayoutsThe GADT type'alayoutrepresents one of the two supported memory layouts: C-style or Fortran-style. Its constructors are re-exported as values below for backward-compatibility reasons.type'alayout= | C_layout:c_layoutlayout| Fortran_layout:fortran_layoutlayoutvalc_layout:c_layoutlayoutvalfortran_layout:fortran_layoutlayoutGenericarrays(ofarbitrarilymanydimensions)moduleGenarray:sigendZero-dimensionalarraysmoduleArray0:sigendZero-dimensional arrays. TheArray0structure provides operations similar to those ofBigarray.Genarray, but specialized to the case of zero-dimensional arrays that only contain a single scalar value. Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking.Since4.05.0One-dimensionalarraysmoduleArray1:sigendOne-dimensional arrays. TheArray1structure provides operations similar to those ofBigarray.Genarray, but specialized to the case of one-dimensional arrays. (TheBigarray.Array2andBigarray.Array3structures below provide operations specialized for two- and three-dimensional arrays.) Statically knowing the number of dimensions of the array allows faster operations, and more precise static type-checking.Two-dimensionalarraysmoduleArray2:sigendTwo-dimensional arrays. TheArray2structure provides operations similar to those ofBigarray.Genarray, but specialized to the case of two-dimensional arrays.Three-dimensionalarraysmoduleArray3:sigendThree-dimensional arrays. TheArray3structure provides operations similar to those ofBigarray.Genarray, but specialized to the case of three-dimensional arrays.CoercionsbetweengenericBigarraysandfixed-dimensionBigarraysvalgenarray_of_array0:('a,'b,'c)Array0.t->('a,'b,'c)Genarray.tReturn the generic Bigarray corresponding to the given zero-dimensional Bigarray.Since4.05.0valgenarray_of_array1:('a,'b,'c)Array1.t->('a,'b,'c)Genarray.tReturn the generic Bigarray corresponding to the given one-dimensional Bigarray.valgenarray_of_array2:('a,'b,'c)Array2.t->('a,'b,'c)Genarray.tReturn the generic Bigarray corresponding to the given two-dimensional Bigarray.valgenarray_of_array3:('a,'b,'c)Array3.t->('a,'b,'c)Genarray.tReturn the generic Bigarray corresponding to the given three-dimensional Bigarray.valarray0_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Array0.tReturn the zero-dimensional Bigarray corresponding to the given generic Bigarray. RaiseInvalid_argumentif the generic Bigarray does not have exactly zero dimension.Since4.05.0valarray1_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Array1.tReturn the one-dimensional Bigarray corresponding to the given generic Bigarray. RaiseInvalid_argumentif the generic Bigarray does not have exactly one dimension.valarray2_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Array2.tReturn the two-dimensional Bigarray corresponding to the given generic Bigarray. RaiseInvalid_argumentif the generic Bigarray does not have exactly two dimensions.valarray3_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Array3.tReturn the three-dimensional Bigarray corresponding to the given generic Bigarray. RaiseInvalid_argumentif the generic Bigarray does not have exactly three dimensions.Re-shapingBigarraysvalreshape:('a,'b,'c)Genarray.t->intarray->('a,'b,'c)Genarray.treshapeb[|d1;...;dN|]converts the Bigarraybto aN-dimensional array of dimensionsd1...dN. The returned array and the original arraybshare their data and have the same layout. For instance, assuming thatbis a one-dimensional array of dimension 12,reshapeb[|3;4|]returns a two-dimensional arrayb'of dimensions 3 and 4. Ifbhas C layout, the element(x,y)ofb'corresponds to the elementx*3+yofb. Ifbhas Fortran layout, the element(x,y)ofb'corresponds to the elementx+(y-1)*4ofb. The returned Bigarray must have exactly the same number of elements as the original Bigarrayb. That is, the product of the dimensions ofbmust be equal toi1*...*iN. Otherwise,Invalid_argumentis raised.valreshape_0:('a,'b,'c)Genarray.t->('a,'b,'c)Array0.tSpecialized version ofBigarray.reshapefor reshaping to zero-dimensional arrays.Since4.05.0valreshape_1:('a,'b,'c)Genarray.t->int->('a,'b,'c)Array1.tSpecialized version ofBigarray.reshapefor reshaping to one-dimensional arrays.valreshape_2:('a,'b,'c)Genarray.t->int->int->('a,'b,'c)Array2.tSpecialized version ofBigarray.reshapefor reshaping to two-dimensional arrays.valreshape_3:('a,'b,'c)Genarray.t->int->int->int->('a,'b,'c)Array3.tSpecialized version ofBigarray.reshapefor reshaping to three-dimensional arrays.