1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module L = BatList
let stddev (l: float list) =
let n, sx, sx2 =
List.fold_left (fun (n, sx, sx2) x ->
(n +. 1., sx +. x, sx2 +. (x *.x))
) (0., 0., 0.) l
in
sqrt ((sx2 -. (sx *. sx) /. n) /. n)
let enforce (condition: bool) (err_msg_fun: unit -> string): unit =
if not condition then
failwith (err_msg_fun ())
let prepend2 a (b, c) =
(a, b, c)
let prepend3 a (b, c, d) =
(a, b, c, d)
let fst4 (a, _b, _c, _d) =
a
let trd4 (_a, _b, c, _d) =
c
let frt4 (_a, _b, _c, d) =
d
let combine3 l1 l2 l3 =
let rec loop acc = function
| ([], [], []) -> L.rev acc
| (x :: xs, y :: ys, z :: zs) -> loop ((x, y, z) :: acc) (xs, ys, zs)
| _ -> failwith "Utls.combine3: incompatible list lengths" in
loop [] (l1, l2, l3)
let with_temp_file tmp_dir prfx sfx f =
let tmp_fn = Filename.temp_file ~temp_dir:tmp_dir prfx sfx in
let res = f tmp_fn in
Sys.remove tmp_fn;
res