Module Float.Array
val length : t -> intReturn the length (number of elements) of the given floatarray.
val get : t -> int -> floatget a nreturns the element numbernof floatarraya.Raise
Invalid_argumentifnis outside the range 0 to(length a - 1).
val set : t -> int -> float -> unitset a n xmodifies floatarrayain place, replacing element numbernwithx.Raise
Invalid_argumentifnis outside the range 0 to(length a - 1).
val make : int -> float -> tmake n xreturns a fresh floatarray of lengthn, initialized withx.Raise
Invalid_argumentifn < 0orn > Sys.max_floatarray_length.
val create : int -> tcreate nreturns a fresh floatarray of lengthn, with uninitialized data.Raise
Invalid_argumentifn < 0orn > Sys.max_floatarray_length.
val init : int -> (int -> float) -> tinit n freturns a fresh floatarray of lengthn, with element numberiinitialized to the result off i. In other terms,init n ftabulates the results offapplied to the integers0ton-1.Raise
Invalid_argumentifn < 0orn > Sys.max_floatarray_length.
val append : t -> t -> tappend v1 v2returns a fresh floatarray containing the concatenation of the floatarraysv1andv2.Raise
Invalid_argumentiflength v1 + length v2 > Sys.max_floatarray_length.
val sub : t -> int -> int -> tsub a start lenreturns a fresh floatarray of lengthlen, containing the elements numberstarttostart + len - 1of floatarraya.Raise
Invalid_argumentifstartandlendo not designate a valid subarray ofa; that is, ifstart < 0, orlen < 0, orstart + len > length a.
val copy : t -> tcopy areturns a copy ofa, that is, a fresh floatarray containing the same elements asa.
val fill : t -> int -> int -> float -> unitfill a ofs len xmodifies the floatarrayain place, storingxin elements numberofstoofs + len - 1.Raise
Invalid_argumentifofsandlendo not designate a valid subarray ofa.
val blit : t -> int -> t -> int -> int -> unitblit v1 o1 v2 o2 lencopieslenelements from floatarrayv1, starting at element numbero1, to floatarrayv2, starting at element numbero2. It works correctly even ifv1andv2are the same floatarray, and the source and destination chunks overlap.Raise
Invalid_argumentifo1andlendo not designate a valid subarray ofv1, or ifo2andlendo not designate a valid subarray ofv2.
val to_list : t -> float listto_list areturns the list of all the elements ofa.
val of_list : float list -> tof_list lreturns a fresh floatarray containing the elements ofl.Raise
Invalid_argumentif the length oflis greater thanSys.max_floatarray_length.
Iterators
val iter : (float -> unit) -> t -> unititer f aapplies functionfin turn to all the elements ofa. It is equivalent tof a.(0); f a.(1); ...; f a.(length a - 1); ().
val iteri : (int -> float -> unit) -> t -> unitSame as
iter, but the function is applied with the index of the element as first argument, and the element itself as second argument.
val map : (float -> float) -> t -> tmap f aapplies functionfto all the elements ofa, and builds a floatarray with the results returned byf.
val mapi : (int -> float -> float) -> t -> tSame as
map, but the function is applied to the index of the element as first argument, and the element itself as second argument.
val fold_left : ('a -> float -> 'a) -> 'a -> t -> 'afold_left f x acomputesf (... (f (f x a.(0)) a.(1)) ...) a.(n-1), wherenis the length of the floatarraya.
val fold_right : (float -> 'a -> 'a) -> t -> 'a -> 'afold_right f a xcomputesf a.(0) (f a.(1) ( ... (f a.(n-1) x) ...)), wherenis the length of the floatarraya.
Iterators on two arrays
Array scanning
val for_all : (float -> bool) -> t -> boolfor_all p [|a1; ...; an|]checks if all elements of the floatarray satisfy the predicatep. That is, it returns(p a1) && (p a2) && ... && (p an).
val exists : (float -> bool) -> t -> boolexists p [|a1; ...; an|]checks if at least one element of the floatarray satisfies the predicatep. That is, it returns(p a1) || (p a2) || ... || (p an).
val mem : float -> t -> boolmem a lis true if and only if there is an element oflthat is structurally equal toa, i.e. there is anxinlsuch thatcompare a x = 0.
Sorting
val sort : (float -> float -> int) -> t -> unitSort a floatarray in increasing order according to a comparison function. The comparison function must return 0 if its arguments compare as equal, a positive integer if the first is greater, and a negative integer if the first is smaller (see below for a complete specification). For example,
Stdlib.compareis a suitable comparison function. After callingsort, the array is sorted in place in increasing order.sortis guaranteed to run in constant heap space and (at most) logarithmic stack space.The current implementation uses Heap Sort. It runs in constant stack space.
Specification of the comparison function: Let
abe the floatarray andcmpthe comparison function. The following must be true for allx,y,zina:cmp x y> 0 if and only ifcmp y x< 0- if
cmp x y>= 0 andcmp y z>= 0 thencmp x z>= 0
When
sortreturns,acontains the same elements as before, reordered in such a way that for all i and j valid indices ofa:cmp a.(i) a.(j)>= 0 if and only if i >= j
val stable_sort : (float -> float -> int) -> t -> unitSame as
sort, but the sorting algorithm is stable (i.e. elements that compare equal are kept in their original order) and not guaranteed to run in constant heap space.The current implementation uses Merge Sort. It uses a temporary floatarray of length
n/2, wherenis the length of the floatarray. It is usually faster than the current implementation ofsort.
val fast_sort : (float -> float -> int) -> t -> unitSame as
sortorstable_sort, whichever is faster on typical input.
Iterators
val to_seq : t -> float Seq.tIterate on the floatarray, in increasing order. Modifications of the floatarray during iteration will be reflected in the iterator.
val to_seqi : t -> (int * float) Seq.tIterate on the floatarray, in increasing order, yielding indices along elements. Modifications of the floatarray during iteration will be reflected in the iterator.
val map_to_array : (float -> 'a) -> t -> 'a arraymap_to_array f aapplies functionfto all the elements ofa, and builds an array with the results returned byf:[| f a.(0); f a.(1); ...; f a.(length a - 1) |].
val map_from_array : ('a -> float) -> 'a array -> tmap_from_array f aapplies functionfto all the elements ofa, and builds a floatarray with the results returned byf.