Module Bigarray.Genarray
type ('a, 'b, 'c) tThe type
Genarray.tis the type of Bigarrays with variable numbers of dimensions. Any number of dimensions between 0 and 16 is supported.The three type parameters to
Genarray.tidentify the array element kind and layout, as follows:- the first parameter,
'a, is the OCaml type for accessing array elements (float,int,int32,int64,nativeint); - the second parameter,
'b, is the actual kind of array elements (float32_elt,float64_elt,int8_signed_elt,int8_unsigned_elt, etc); - the third parameter,
'c, identifies the array layout (c_layoutorfortran_layout).
For instance,
(float, float32_elt, fortran_layout) Genarray.tis the type of generic Bigarrays containing 32-bit floats in Fortran layout; reads and writes in this array use the OCaml typefloat.- the first parameter,
val create : ('a, 'b) kind -> 'c layout -> int array -> ('a, 'b, 'c) tGenarray.create kind layout dimensionsreturns a new Bigarray whose element kind is determined by the parameterkind(one offloat32,float64,int8_signed, etc) and whose layout is determined by the parameterlayout(one ofc_layoutorfortran_layout). Thedimensionsparameter is an array of integers that indicate the size of the Bigarray in each dimension. The length ofdimensionsdetermines the number of dimensions of the Bigarray.For instance,
Genarray.create int32 c_layout [|4;6;8|]returns a fresh Bigarray of 32-bit integers, in C layout, having three dimensions, the three dimensions being 4, 6 and 8 respectively.Bigarrays returned by
Genarray.createare not initialized: the initial values of array elements is unspecified.Genarray.createraisesInvalid_argumentif the number of dimensions is not in the range 0 to 16 inclusive, or if one of the dimensions is negative.
val num_dims : ('a, 'b, 'c) t -> intReturn the number of dimensions of the given Bigarray.
val dims : ('a, 'b, 'c) t -> int arrayGenarray.dims areturns all dimensions of the Bigarraya, as an array of integers of lengthGenarray.num_dims a.
val nth_dim : ('a, 'b, 'c) t -> int -> intGenarray.nth_dim a nreturns then-th dimension of the Bigarraya. The first dimension corresponds ton = 0; the second dimension corresponds ton = 1; the last dimension, ton = Genarray.num_dims a - 1. RaiseInvalid_argumentifnis less than 0 or greater or equal thanGenarray.num_dims a.
val change_layout : ('a, 'b, 'c) t -> 'd layout -> ('a, 'b, 'd) tGenarray.change_layout a layoutreturns a Bigarray with the specifiedlayout, sharing the data witha(and hence having the same dimensions asa). No copying of elements is involved: the new array and the original array share the same storage space. The dimensions are reversed, such thatget v [| a; b |]in C layout becomesget v [| b+1; a+1 |]in Fortran layout.- since
- 4.04.0
val size_in_bytes : ('a, 'b, 'c) t -> intsize_in_bytes ais the number of elements inamultiplied bya'skind_size_in_bytes.- since
- 4.03.0
val get : ('a, 'b, 'c) t -> int array -> 'aRead an element of a generic Bigarray.
Genarray.get a [|i1; ...; iN|]returns the element ofawhose coordinates arei1in the first dimension,i2in the second dimension, ...,iNin theN-th dimension.If
ahas C layout, the coordinates must be greater or equal than 0 and strictly less than the corresponding dimensions ofa. Ifahas Fortran layout, the coordinates must be greater or equal than 1 and less or equal than the corresponding dimensions ofa. RaiseInvalid_argumentif the arrayadoes not have exactlyNdimensions, or if the coordinates are outside the array bounds.If
N > 3, alternate syntax is provided: you can writea.{i1, i2, ..., iN}instead ofGenarray.get a [|i1; ...; iN|]. (The syntaxa.{...}with one, two or three coordinates is reserved for accessing one-, two- and three-dimensional arrays as described below.)
val set : ('a, 'b, 'c) t -> int array -> 'a -> unitAssign an element of a generic Bigarray.
Genarray.set a [|i1; ...; iN|] vstores the valuevin the element ofawhose coordinates arei1in the first dimension,i2in the second dimension, ...,iNin theN-th dimension.The array
amust have exactlyNdimensions, and all coordinates must lie inside the array bounds, as described forGenarray.get; otherwise,Invalid_argumentis raised.If
N > 3, alternate syntax is provided: you can writea.{i1, i2, ..., iN} <- vinstead ofGenarray.set a [|i1; ...; iN|] v. (The syntaxa.{...} <- vwith one, two or three coordinates is reserved for updating one-, two- and three-dimensional arrays as described below.)
val sub_left : ('a, 'b, c_layout) t -> int -> int -> ('a, 'b, c_layout) tExtract a sub-array of the given Bigarray by restricting the first (left-most) dimension.
Genarray.sub_left a ofs lenreturns a Bigarray with the same number of dimensions asa, and the same dimensions asa, except the first dimension, which corresponds to the interval[ofs ... ofs + len - 1]of the first dimension ofa. 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[|i1; ...; iN|]of the sub-array is identical to the element at coordinates[|i1+ofs; ...; iN|]of the original arraya.Genarray.sub_leftapplies only to Bigarrays in C layout. RaiseInvalid_argumentifofsandlendo not designate a valid sub-array ofa, that is, ifofs < 0, orlen < 0, orofs + len > Genarray.nth_dim a 0.
val sub_right : ('a, 'b, fortran_layout) t -> int -> int -> ('a, 'b, fortran_layout) tExtract a sub-array of the given Bigarray by restricting the last (right-most) dimension.
Genarray.sub_right a ofs lenreturns a Bigarray with the same number of dimensions asa, and the same dimensions asa, except the last dimension, which corresponds to the interval[ofs ... ofs + len - 1]of the last dimension ofa. 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[|i1; ...; iN|]of the sub-array is identical to the element at coordinates[|i1; ...; iN+ofs|]of the original arraya.Genarray.sub_rightapplies only to Bigarrays in Fortran layout. RaiseInvalid_argumentifofsandlendo not designate a valid sub-array ofa, that is, ifofs < 1, orlen < 0, orofs + len > Genarray.nth_dim a (Genarray.num_dims a - 1).
val slice_left : ('a, 'b, c_layout) t -> int array -> ('a, 'b, c_layout) tExtract a sub-array of lower dimension from the given Bigarray by fixing one or several of the first (left-most) coordinates.
Genarray.slice_left a [|i1; ... ; iM|]returns the 'slice' ofaobtained by setting the firstMcoordinates toi1, ...,iM. IfahasNdimensions, the slice has dimensionN - M, and the element at coordinates[|j1; ...; j(N-M)|]in the slice is identical to the element at coordinates[|i1; ...; iM; j1; ...; j(N-M)|]in the original arraya. No copying of elements is involved: the slice and the original array share the same storage space.Genarray.slice_leftapplies only to Bigarrays in C layout. RaiseInvalid_argumentifM >= N, or if[|i1; ... ; iM|]is outside the bounds ofa.
val slice_right : ('a, 'b, fortran_layout) t -> int array -> ('a, 'b, fortran_layout) tExtract a sub-array of lower dimension from the given Bigarray by fixing one or several of the last (right-most) coordinates.
Genarray.slice_right a [|i1; ... ; iM|]returns the 'slice' ofaobtained by setting the lastMcoordinates toi1, ...,iM. IfahasNdimensions, the slice has dimensionN - M, and the element at coordinates[|j1; ...; j(N-M)|]in the slice is identical to the element at coordinates[|j1; ...; j(N-M); i1; ...; iM|]in the original arraya. No copying of elements is involved: the slice and the original array share the same storage space.Genarray.slice_rightapplies only to Bigarrays in Fortran layout. RaiseInvalid_argumentifM >= N, or if[|i1; ... ; iM|]is outside the bounds ofa.
val blit : ('a, 'b, 'c) t -> ('a, 'b, 'c) t -> unitCopy all elements of a Bigarray in another Bigarray.
Genarray.blit src dstcopies all elements ofsrcintodst. Both arrayssrcanddstmust have the same number of dimensions and equal dimensions. Copying a sub-array ofsrcto a sub-array ofdstcan be achieved by applyingGenarray.blitto sub-array or slices ofsrcanddst.
val fill : ('a, 'b, 'c) t -> 'a -> unitSet all elements of a Bigarray to a given value.
Genarray.fill a vstores the valuevin all elements of the Bigarraya. Setting only some elements ofatovcan be achieved by applyingGenarray.fillto a sub-array or a slice ofa.