# FreeBSD Manual Pages

Bigarray(3) OCaml library Bigarray(3)NAMEBigarray - Large, multi-dimensional, numerical arrays.ModuleModule BigarrayDocumentationModuleBigarray:sigendLarge, multi-dimensional, numerical arrays. This module implements multi-dimensional arrays of integers and float- ing-point numbers, thereafter referred to as 'big arrays'. The imple- mentation allows efficient sharing of large numerical arrays between OCaml code and C or Fortran numerical libraries. Concerning the naming conventions, users of this module are encouraged to doopenBigarrayin their source, then refer to array types and op- erations via short dot notation, e.g.Array1.torArray2.sub. Big arrays support all the OCaml ad-hoc polymorphic operations: -comparisons (=, <> , <=, etc, as well asPervasives.compare); -hashing (moduleHash); -and structured input-output (the functions from theMarshalmodule, as well asPervasives.output_valueandPervasives.input_value).===Elementkinds======Elementkinds======Bigarrayscancontainelementsofthefollowingkinds:-IEEEsin-gleprecision(32bits)floating-pointnumbers(Bigarray.float32_elt),-IEEEdoubleprecision(64bits)floating-pointnumbers(Bigar-ray.float64_elt),-IEEEsingleprecision(2*32bits)floating-pointcomplexnumbers(Bigarray.complex32_elt),-IEEEdoubleprecision(2*64bits)floating-pointcomplexnumbers(Bigarray.complex64_elt),-8-bitintegers(signedorunsigned)(Bigarray.int8_signed_eltorBigar-ray.int8_unsigned_elt),-16-bitintegers(signedorunsigned)(Bigar-ray.int16_signed_eltorBigarray.int16_unsigned_elt),-OCamlintegers(signed,31bitson32-bitarchitectures,63bitson64-bitarchitec-tures)(Bigarray.int_elt),-32-bitsignedinteger(Bigar-ray.int32_elt),-64-bitsignedintegers(Bigarray.int64_elt),-plat-form-nativesignedintegers(32bitson32-bitarchitectures,64bitson64-bitarchitectures)(Bigarray.nativeint_elt).Eachelementkindisrepresentedatthetypelevelbyoneofthe*_elttypesdefinedbe-low(definedwithasingleconstructorinsteadofabstracttypesfortechnicalinjectivityreasons).===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)kind(* To each element kind is associated an OCaml type, which is the type of OCaml values that can be stored in the big array or read back from it. This type is not necessarily the same as the type of the ar- ray elements proper: for instance, a big array 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 big array, and of an element kind'bwhich represents the actual contents of the big array. Its construc- tors 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 to write well-typed polymorphic functions whose return type depend on the argu- ment 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_un-signed->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, big arrays of kindfloat32_eltandfloat64_eltare accessed using the OCaml typefloat. Big arrays of complex kindscomplex32_elt,complex64_eltare accessed with the OCaml typeComplex.t. Big arrays of integer kinds are ac- cessed 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 bi- garrays. Finally, big arrays of kindint8_unsigned_eltcan also be ac- cessed as arrays of characters instead of arrays of small integers, by using the kind valuecharinstead ofint8_unsigned.===Arraylayouts===typec_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 big arrays, one compatible with the C conventions, the other com- patible 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-dimen- sional 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-dimen- sional arrays are laid out in column-major format. That is, for a two-dimensional array, all elements of column 0 are contiguous in mem- ory, 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. *)===SupportedlayoutsTheGADTtype'alayoutrepresentsoneofthetwosupportedmemorylayouts:C-styleorFortran-style.Itsconstructorsarere-exportedasvaluesbelowforbackward-compatibilityreasons.===type'alayout= | C_layout:c_layoutlayout| Fortran_layout:fortran_layoutlayoutvalc_layout:c_layoutlayoutvalfortran_layout:fortran_layoutlayout===Genericarrays(ofarbitrarilymanydimensions)===moduleGenarray:sigend===One-dimensionalarrays===moduleArray1:sigendOne-dimensional arrays. TheArray1structure provides operations simi- lar to those ofBigarray.Genarray, but specialized to the case of one-dimensional arrays. (TheArray2andArray3structures below pro- vide 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-dimensionalarrays===moduleArray2:sigendTwo-dimensional arrays. TheArray2structure provides operations simi- lar to those ofBigarray.Genarray, but specialized to the case of two-dimensional arrays.===Three-dimensionalarrays===moduleArray3:sigendThree-dimensional arrays. TheArray3structure provides operations sim- ilar to those ofBigarray.Genarray, but specialized to the case of three-dimensional arrays.===Coercionsbetweengenericbigarraysandfixed-dimensionbigarrays===valgenarray_of_array1:('a,'b,'c)Array1.t->('a,'b,'c)Genar-ray.tReturn the generic big array corresponding to the given one-dimensional big array.valgenarray_of_array2:('a,'b,'c)Array2.t->('a,'b,'c)Genar-ray.tReturn the generic big array corresponding to the given two-dimensional big array.valgenarray_of_array3:('a,'b,'c)Array3.t->('a,'b,'c)Genar-ray.tReturn the generic big array corresponding to the given three-dimen- sional big array.valarray1_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Ar-ray1.tReturn the one-dimensional big array corresponding to the given generic big array. RaiseInvalid_argumentif the generic big array does not have exactly one dimension.valarray2_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Ar-ray2.tReturn the two-dimensional big array corresponding to the given generic big array. RaiseInvalid_argumentif the generic big array does not have exactly two dimensions.valarray3_of_genarray:('a,'b,'c)Genarray.t->('a,'b,'c)Ar-ray3.tReturn the three-dimensional big array corresponding to the given generic big array. RaiseInvalid_argumentif the generic big array does not have exactly three dimensions.===Re-shapingbigarrays===valreshape:('a,'b,'c)Genarray.t->intarray->('a,'b,'c)Genarray.treshapeb[|d1;...;dN|]converts the big arraybto aN-dimensional array of dimensionsd1...dN. The returned array and the original arraybshare their data and have the same layout. For instance, as- suming 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'corre- sponds to the elementx+(y-1)*4ofb. The returned big array must have exactly the same number of elements as the original big arrayb. That is, the product of the dimensions ofbmust be equal toi1*...*iN. Otherwise,Invalid_argumentis raised.valreshape_1:('a,'b,'c)Genarray.t->int->('a,'b,'c)Array1.tSpecialized version ofBigarray.reshapefor reshaping to one-dimen- sional arrays.valreshape_2:('a,'b,'c)Genarray.t->int->int->('a,'b,'c)Array2.tSpecialized version ofBigarray.reshapefor reshaping to two-dimen- sional arrays.valreshape_3:('a,'b,'c)Genarray.t->int->int->int->('a,'b,'c)Array3.tSpecialized version ofBigarray.reshapefor reshaping to three-dimen- sional arrays. OCamldoc 2017-04-30 Bigarray(3)

NAME | Module | Documentation

Want to link to this manual page? Use this URL:

<https://www.freebsd.org/cgi/man.cgi?query=Bigarray&sektion=3o&manpath=FreeBSD+12.1-RELEASE+and+Ports>