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