1Float.Array(3) OCaml library Float.Array(3)
2
3
4
6 Float.Array - no description
7
9 Module Float.Array
10
12 Module Array
13 : sig end
14
15
16
17
18
19
20
21 type t = floatarray
22
23
24 The type of float arrays with packed representation.
25
26
27 Since 4.08.0
28
29
30
31 val length : t -> int
32
33 Return the length (number of elements) of the given floatarray.
34
35
36
37 val get : t -> int -> float
38
39
40 get a n returns the element number n of floatarray a .
41
42
43 Raises Invalid_argument if n is outside the range 0 to (length a - 1) .
44
45
46
47 val set : t -> int -> float -> unit
48
49
50 set a n x modifies floatarray a in place, replacing element number n
51 with x .
52
53
54 Raises Invalid_argument if n is outside the range 0 to (length a - 1) .
55
56
57
58 val make : int -> float -> t
59
60
61 make n x returns a fresh floatarray of length n , initialized with x .
62
63
64 Raises Invalid_argument if n < 0 or n > Sys.max_floatarray_length .
65
66
67
68 val create : int -> t
69
70
71 create n returns a fresh floatarray of length n , with uninitialized
72 data.
73
74
75 Raises Invalid_argument if n < 0 or n > Sys.max_floatarray_length .
76
77
78
79 val init : int -> (int -> float) -> t
80
81
82 init n f returns a fresh floatarray of length n , with element number i
83 initialized to the result of f i . In other terms, init n f tabulates
84 the results of f applied to the integers 0 to n-1 .
85
86
87 Raises Invalid_argument if n < 0 or n > Sys.max_floatarray_length .
88
89
90
91 val append : t -> t -> t
92
93
94 append v1 v2 returns a fresh floatarray containing the concatenation of
95 the floatarrays v1 and v2 .
96
97
98 Raises Invalid_argument if length v1 + length v2 > Sys.max_floatar‐
99 ray_length .
100
101
102
103 val concat : t list -> t
104
105 Same as Float.Array.append , but concatenates a list of floatarrays.
106
107
108
109 val sub : t -> int -> int -> t
110
111
112 sub a start len returns a fresh floatarray of length len , containing
113 the elements number start to start + len - 1 of floatarray a .
114
115
116 Raises Invalid_argument if start and len do not designate a valid sub‐
117 array of a ; that is, if start < 0 , or len < 0 , or start + len >
118 length a .
119
120
121
122 val copy : t -> t
123
124
125 copy a returns a copy of a , that is, a fresh floatarray containing the
126 same elements as a .
127
128
129
130 val fill : t -> int -> int -> float -> unit
131
132
133 fill a ofs len x modifies the floatarray a in place, storing x in ele‐
134 ments number ofs to ofs + len - 1 .
135
136
137 Raises Invalid_argument if ofs and len do not designate a valid subar‐
138 ray of a .
139
140
141
142 val blit : t -> int -> t -> int -> int -> unit
143
144
145 blit v1 o1 v2 o2 len copies len elements from floatarray v1 , starting
146 at element number o1 , to floatarray v2 , starting at element number o2
147 . It works correctly even if v1 and v2 are the same floatarray, and the
148 source and destination chunks overlap.
149
150
151 Raises Invalid_argument if o1 and len do not designate a valid subarray
152 of v1 , or if o2 and len do not designate a valid subarray of v2 .
153
154
155
156 val to_list : t -> float list
157
158
159 to_list a returns the list of all the elements of a .
160
161
162
163 val of_list : float list -> t
164
165
166 of_list l returns a fresh floatarray containing the elements of l .
167
168
169 Raises Invalid_argument if the length of l is greater than
170 Sys.max_floatarray_length .
171
172
173
174
175 Iterators
176 val iter : (float -> unit) -> t -> unit
177
178
179 iter f a applies function f in turn to all the elements of a . It is
180 equivalent to f a.(0); f a.(1); ...; f a.(length a - 1); () .
181
182
183
184 val iteri : (int -> float -> unit) -> t -> unit
185
186 Same as Float.Array.iter , but the function is applied with the index
187 of the element as first argument, and the element itself as second
188 argument.
189
190
191
192 val map : (float -> float) -> t -> t
193
194
195 map f a applies function f to all the elements of a , and builds a
196 floatarray with the results returned by f .
197
198
199
200 val mapi : (int -> float -> float) -> t -> t
201
202 Same as Float.Array.map , but the function is applied to the index of
203 the element as first argument, and the element itself as second argu‐
204 ment.
205
206
207
208 val fold_left : ('a -> float -> 'a) -> 'a -> t -> 'a
209
210
211 fold_left f x a computes f (... (f (f x a.(0)) a.(1)) ...) a.(n-1) ,
212 where n is the length of the floatarray a .
213
214
215
216 val fold_right : (float -> 'a -> 'a) -> t -> 'a -> 'a
217
218
219 fold_right f a x computes f a.(0) (f a.(1) ( ... (f a.(n-1) x) ...)) ,
220 where n is the length of the floatarray a .
221
222
223
224
225 Iterators on two arrays
226 val iter2 : (float -> float -> unit) -> t -> t -> unit
227
228
229 Array.iter2 f a b applies function f to all the elements of a and b .
230
231
232 Raises Invalid_argument if the floatarrays are not the same size.
233
234
235
236 val map2 : (float -> float -> float) -> t -> t -> t
237
238
239 map2 f a b applies function f to all the elements of a and b , and
240 builds a floatarray with the results returned by f : [| f a.(0) b.(0);
241 ...; f a.(length a - 1) b.(length b - 1)|] .
242
243
244 Raises Invalid_argument if the floatarrays are not the same size.
245
246
247
248
249 Array scanning
250 val for_all : (float -> bool) -> t -> bool
251
252
253 for_all p [|a1; ...; an|] checks if all elements of the floatarray sat‐
254 isfy the predicate p . That is, it returns (p a1) && (p a2) && ... &&
255 (p an) .
256
257
258
259 val exists : (float -> bool) -> t -> bool
260
261
262 exists p [|a1; ...; an|] checks if at least one element of the floatar‐
263 ray satisfies the predicate p . That is, it returns (p a1) || (p a2) ||
264 ... || (p an) .
265
266
267
268 val mem : float -> t -> bool
269
270
271 mem a l is true if and only if there is an element of l that is struc‐
272 turally equal to a , i.e. there is an x in l such that compare a x = 0
273 .
274
275
276
277 val mem_ieee : float -> t -> bool
278
279 Same as Float.Array.mem , but uses IEEE equality instead of structural
280 equality.
281
282
283
284
285 Sorting
286 val sort : (float -> float -> int) -> t -> unit
287
288 Sort a floatarray in increasing order according to a comparison func‐
289 tion. The comparison function must return 0 if its arguments compare
290 as equal, a positive integer if the first is greater, and a negative
291 integer if the first is smaller (see below for a complete specifica‐
292 tion). For example, compare is a suitable comparison function. After
293 calling sort , the array is sorted in place in increasing order. sort
294 is guaranteed to run in constant heap space and (at most) logarithmic
295 stack space.
296
297 The current implementation uses Heap Sort. It runs in constant stack
298 space.
299
300 Specification of the comparison function: Let a be the floatarray and
301 cmp the comparison function. The following must be true for all x , y ,
302 z in a :
303
304 - cmp x y > 0 if and only if cmp y x < 0
305
306 - if cmp x y >= 0 and cmp y z >= 0 then cmp x z >= 0
307
308 When sort returns, a contains the same elements as before, reordered in
309 such a way that for all i and j valid indices of a :
310
311 - cmp a.(i) a.(j) >= 0 if and only if i >= j
312
313
314
315
316 val stable_sort : (float -> float -> int) -> t -> unit
317
318 Same as Float.Array.sort , but the sorting algorithm is stable (i.e.
319 elements that compare equal are kept in their original order) and not
320 guaranteed to run in constant heap space.
321
322 The current implementation uses Merge Sort. It uses a temporary
323 floatarray of length n/2 , where n is the length of the floatarray. It
324 is usually faster than the current implementation of Float.Array.sort .
325
326
327
328 val fast_sort : (float -> float -> int) -> t -> unit
329
330 Same as Float.Array.sort or Float.Array.stable_sort , whichever is
331 faster on typical input.
332
333
334
335
336 Iterators
337 val to_seq : t -> float Seq.t
338
339 Iterate on the floatarray, in increasing order. Modifications of the
340 floatarray during iteration will be reflected in the iterator.
341
342
343
344 val to_seqi : t -> (int * float) Seq.t
345
346 Iterate on the floatarray, in increasing order, yielding indices along
347 elements. Modifications of the floatarray during iteration will be
348 reflected in the iterator.
349
350
351
352 val of_seq : float Seq.t -> t
353
354 Create an array from the generator.
355
356
357
358 val map_to_array : (float -> 'a) -> t -> 'a array
359
360
361 map_to_array f a applies function f to all the elements of a , and
362 builds an array with the results returned by f : [| f a.(0); f a.(1);
363 ...; f a.(length a - 1) |] .
364
365
366
367 val map_from_array : ('a -> float) -> 'a array -> t
368
369
370 map_from_array f a applies function f to all the elements of a , and
371 builds a floatarray with the results returned by f .
372
373
374
375
376 Undocumented functions
377 val unsafe_get : t -> int -> float
378
379
380
381
382 val unsafe_set : t -> int -> float -> unit
383
384
385
386
387
388
389OCamldoc 2020-09-01 Float.Array(3)