# FreeBSD Manual Pages

Bigarray.Genarray(3) OCaml library Bigarray.Genarray(3)NAMEBigarray.Genarray - no descriptionModuleModule Bigarray.GenarrayDocumentationModuleGenarray:sigendtype('a,'b,'c)tThe typeGenarray.tis the type of big arrays with variable numbers of dimensions. Any number of dimensions between 1 and 16 is supported. The three type parameters toGenarray.tidentify the array element kind and layout, as follows: -the first parameter,'a, is the OCaml type for accessing array ele- ments (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 big arrays containing 32-bit floats in Fortran layout; reads and writes in this array use the OCaml typefloat.valcreate:('a,'b)Bigarray.kind->'cBigarray.layout->intarray->('a,'b,'c)tGenarray.createkindlayoutdimensionsreturns a new big array whose element kind is determined by the parameterkind(one offloat32,float64,int8_signed, etc) and whose layout is determined by the pa- rameterlayout(one ofc_layoutorfortran_layout). Thedimensionsparameter is an array of integers that indicate the size of the big ar- ray in each dimension. The length ofdimensionsdetermines the number of dimensions of the bigarray. For instance,Genarray.createint32c_layout[|4;6;8|]returns a fresh big array of 32-bit integers, in C layout, having three dimensions, the three dimensions being 4, 6 and 8 respectively. Big arrays returned byGenarray.createare not initialized: the initial values of array elements is unspecified.Genarray.createraisesInvalid_argumentif the number of dimensions is not in the range 1 to 16 inclusive, or if one of the dimensions is neg- ative.valnum_dims:('a,'b,'c)t->intReturn the number of dimensions of the given big array.valdims:('a,'b,'c)t->intarrayGenarray.dimsareturns all dimensions of the big arraya, as an array of integers of lengthGenarray.num_dimsa.valnth_dim:('a,'b,'c)t->int->intGenarray.nth_dimanreturns then-th dimension of the big arraya. The first dimension corresponds ton=0; the second dimension corre- sponds ton=1; the last dimension, ton=Genarray.num_dimsa-1. RaiseInvalid_argumentifnis less than 0 or greater or equal thanGenarray.num_dimsa.valkind:('a,'b,'c)t->('a,'b)Bigarray.kindReturn the kind of the given big array.vallayout:('a,'b,'c)t->'cBigarray.layoutReturn the layout of the given big array.valget:('a,'b,'c)t->intarray->'aRead an element of a generic big array.Genarray.geta[|i1;...;iN|]returns the element ofawhose coordinates arei1in the first dimen- sion,i2in the second dimension, ...,iNin theN-th dimension. Ifahas C layout, the coordinates must be greater or equal than 0 and strictly less than the corresponding dimensions ofa. Ifahas For- tran layout, the coordinates must be greater or equal than 1 and less or equal than the corresponding dimensions ofa. RaiseInvalid_argu-mentif the arrayadoes not have exactlyNdimensions, or if the coor- dinates are outside the array bounds. IfN>3, alternate syntax is provided: you can writea.{i1,i2,...,iN}instead ofGenarray.geta[|i1;...;iN|]. (The syntaxa.{...}with one, two or three coordinates is reserved for accessing one-, two- and three-dimensional arrays as described below.)valset:('a,'b,'c)t->intarray->'a->unitAssign an element of a generic big array.Genarray.seta[|i1;...;iN|]vstores the valuevin the element ofawhose coordinates arei1in the first dimension,i2in the second dimension, ...,iNin theN-th dimension. The arrayamust have exactlyNdimensions, and all coordinates must lie inside the array bounds, as described forGenarray.get; otherwise,Invalid_argumentis raised. IfN>3, alternate syntax is provided: you can writea.{i1,i2,...,iN}<-vinstead ofGenarray.seta[|i1;...;iN|]v. (The syntaxa.{...}<-vwith one, two or three coordinates is reserved for updat- ing one-, two- and three-dimensional arrays as described below.)valsub_left:('a,'b,Bigarray.c_layout)t->int->int->('a,'b,Bigarray.c_layout)tExtract a sub-array of the given big array by restricting the first (left-most) dimension.Genarray.sub_leftaofslenreturns a big array 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 ele- ments 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 big arrays in C layout. RaiseIn-valid_argumentifofsandlendo not designate a valid sub-array ofa, that is, ifofs<0, orlen<0, orofs+len>Genarray.nth_dima0.valsub_right:('a,'b,Bigarray.fortran_layout)t->int->int->('a,'b,Bigarray.fortran_layout)tExtract a sub-array of the given big array by restricting the last (right-most) dimension.Genarray.sub_rightaofslenreturns a big ar- ray 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 el- ements 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 big arrays in Fortran layout. RaiseInvalid_argumentifofsandlendo not designate a valid sub-array ofa, that is, ifofs<1, orlen<0, orofs+len>Genarray.nth_dima(Genarray.num_dimsa-1).valslice_left:('a,'b,Bigarray.c_layout)t->intarray->('a,'b,Bigarray.c_layout)tExtract a sub-array of lower dimension from the given big array by fix- ing one or several of the first (left-most) coordinates.Genar-ray.slice_lefta[|i1;...;iM|]returns the 'slice' ofaobtained by setting the firstMcoordinates toi1, ...,iM. IfahasNdimen- sions, the slice has dimensionN-M, and the element at coordinates[|j1;...;j(N-M)|]in the slice is identical to the element at coordi- nates[|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 big arrays in C layout. RaiseIn-valid_argumentifM>=N, or if[|i1;...;iM|]is outside the bounds ofa.valslice_right:('a,'b,Bigarray.fortran_layout)t->intarray->('a,'b,Bigarray.fortran_layout)tExtract a sub-array of lower dimension from the given big array by fix- ing one or several of the last (right-most) coordinates.Genar-ray.slice_righta[|i1;...;iM|]returns the 'slice' ofaobtained by setting the lastMcoordinates toi1, ...,iM. IfahasNdimen- sions, the slice has dimensionN-M, and the element at coordinates[|j1;...;j(N-M)|]in the slice is identical to the element at coordi- nates[|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 big arrays in Fortran layout. RaiseInvalid_argumentifM>=N, or if[|i1;...;iM|]is outside the bounds ofa.valblit:('a,'b,'c)t->('a,'b,'c)t->unitCopy all elements of a big array in another big array.Genarray.blitsrcdstcopies 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.valfill:('a,'b,'c)t->'a->unitSet all elements of a big array to a given value.Genarray.fillavstores the valuevin all elements of the big arraya. Setting only some elements ofatovcan be achieved by applyingGenarray.fillto a sub-array or a slice ofa.valmap_file:Unix.file_descr->?pos:int64->('a,'b)Bigarray.kind->'cBigarray.layout->bool->intarray->('a,'b,'c)tMemory mapping of a file as a big array.Genarray.map_filefdkindlayoutshareddimsreturns a big array of kindkind, layoutlayout, and dimensions as specified indims. The data contained in this big array are the contents of the file referred to by the file descriptorfd(as opened previously withUnix.openfile, for example). The op- tionalposparameter is the byte offset in the file of the data being mapped; it defaults to 0 (map from the beginning of the file). Ifsharedistrue, all modifications performed on the array are re- flected in the file. This requires thatfdbe opened with write per- missions. Ifsharedisfalse, modifications performed on the array are done in memory only, using copy-on-write of the modified pages; the underlying file is not affected.Genarray.map_fileis much more efficient than reading the whole file in a big array, modifying that big array, and writing it afterwards. To adjust automatically the dimensions of the big array to the actual size of the file, the major dimension (that is, the first dimension for an array with C layout, and the last dimension for an array with For- tran layout) can be given as-1.Genarray.map_filethen determines the major dimension from the size of the file. The file must contain an integral number of sub-arrays as determined by the non-major dimen- sions, otherwiseFailureis raised. If all dimensions of the big array are given, the file size is matched against the size of the big array. If the file is larger than the big array, only the initial portion of the file is mapped to the big array. If the file is smaller than the big array, the file is automatically grown to the size of the big array. This requires write permissions onfd. Array accesses are bounds-checked, but the bounds are determined by the initial call tomap_file. Therefore, you should make sure no other process modifies the mapped file while you're accessing it, or a SIGBUS signal may be raised. This happens, for instance, if the file is shrunk. This function raisesSys_errorin the case of any errors from the un- derlying system calls.Invalid_argumentorFailuremay be raised in cases where argument validation fails. OCamldoc 2017-04-30 Bigarray.Genarray(3)

NAME | Module | Documentation

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

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