package owl

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file owl_maths.ml

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# 1 "src/owl/maths/owl_maths.ml"
(*
 * OWL - OCaml Scientific and Engineering Computing
 * Copyright (c) 2016-2019 Liang Wang <liang.wang@cl.cam.ac.uk>
 *)

module CI = Cstubs_internals


(** Basic and advanced math functions *)

let add = ( +. )

let sub = ( -. )

let mul = ( *. )

let div = ( /. )

let fmod = Stdlib.mod_float

let atan2 = Stdlib.atan2

let abs x = abs_float x

let neg x = 0. -. x

let reci x = 1. /. x

let signum x =
  if FP_nan = classify_float x then nan
  else (
    if x > 0. then 1.
    else (
      if x < 0. then (~-. 1.) else 0.
    )
  )

let softsign x = x /. (1. +. abs x)

let softplus x = log (1. +. exp x)

let relu x = max 0. x

let floor x = floor x

let ceil x = ceil x

let round_lb = -.(2. ** 52.)
let round_ub = 2. ** 52.
let round t =
  if t >= round_lb && t <= round_ub then
    floor (t +. 0.49999999999999994)
  else t

let trunc x = modf x |> snd

let sqr x = x *. x

let sqrt x = sqrt x

let pow x y = x ** y

let exp x = exp x

let exp2 x = Owl_maths_special.exp2 x

let exp10 x = Owl_maths_special.exp10 x

let expm1 x = expm1 x

let log x = log x

let log1p x = log1p x

let log2 x = (log x) /. Owl_const.loge2

let log10 x = (log x) /. Owl_const.loge10

let logn base x = (log x) /. (log base)

let logabs x = Owl_maths_special.logabs x

let sigmoid x = 1. /. ((exp (-.x)) +. 1.)

let sin x = sin x

let cos x = cos x

let tan x = tan x

let cot x = 1. /. (tan x)

let sec x = 1. /. (cos x)

let csc x = 1. /. (sin x)

let asin x = asin x

let acos x = acos x

let atan x = atan x

let acot x = (Owl_const.pi /. 2.) -. (atan x)

let asec x = acos (1. /. x)

let acsc x = asin (1. /. x)

let sinc x = Owl_maths_special.sinc x

let sinh x = sinh x

let cosh x = cosh x

let tanh x = tanh x

let coth x = let a = exp (-2. *. x) in (1. +. a) /. (1. -. a)

let sech x = 1. /. cosh x

let csch x = 1. /. sinh x

let asinh x = Owl_maths_special.asinh x

let acosh x = Owl_maths_special.acosh x

let atanh x = Owl_maths_special.atanh x

let acoth x = atanh (1. /. x)

let asech x = acosh (1. /. x)

let acsch x = asinh (1. /. x)

let logsinh x = log (sinh x)

let logcosh x = log (cosh x)

let sindg x = Owl_maths_special.sindg x

let cosdg x = Owl_maths_special.cosdg x

let tandg x = Owl_maths_special.tandg x

let cotdg x = Owl_maths_special.cotdg x

let hypot x y = Owl_maths_special.hypot x y

let xlogy x y = Owl_maths_special.xlogy x y

let xlog1py x y = Owl_maths_special.xlog1py x y

let logit x = Owl_maths_special.logit x

let expit x = Owl_maths_special.expit x

let log1mexp x = Owl_maths_special.log1mexp x

let log1pexp x = Owl_maths_special.log1pexp x

let airy x =
  let ai = Ctypes.(allocate double 0.) in
  let aip = Ctypes.(allocate double 0.) in
  let bi = Ctypes.(allocate double 0.) in
  let bip = Ctypes.(allocate double 0.) in
  (* TODO: unify exception handling ... *)
  Owl_maths_special.airy x ai aip bi bip |> ignore;
  Ctypes.(!@ai, !@aip, !@bi, !@bip)

let ellipj u m =
  let sn = Ctypes.(allocate double 0.) in
  let cn = Ctypes.(allocate double 0.) in
  let dn = Ctypes.(allocate double 0.) in
  let ph = Ctypes.(allocate double 0.) in
  Owl_maths_special.ellipj u m sn cn dn ph |> ignore;
  Ctypes.(!@sn, !@cn, !@dn, !@ph)

let ellipk m = Owl_maths_special.ellipk m

let ellipkm1 m = Owl_maths_special.ellipkm1 m

let ellipkinc phi m = Owl_maths_special.ellipkinc phi m

let ellipe m = Owl_maths_special.ellipe m

let ellipeinc phi m = Owl_maths_special.ellipeinc phi m

let j0 x = Owl_maths_special.j0 x

let j1 x = Owl_maths_special.j1 x

let jv v x = Owl_maths_special.jv v x

let y0 x = Owl_maths_special.y0 x

let y1 x = Owl_maths_special.y1 x

let yv v x = Owl_maths_special.yv v x

let yn n x = Owl_maths_special.yn n x

let i0 x = Owl_maths_special.i0 x

let i0e x = Owl_maths_special.i0e x

let i1 x = Owl_maths_special.i1 x

let i1e x = Owl_maths_special.i1e x

let iv v x = Owl_maths_special.iv v x

let k0 x = Owl_maths_special.k0 x

let k0e x = Owl_maths_special.k0e x

let k1 x = Owl_maths_special.k1 x

let k1e x = Owl_maths_special.k1e x

let expn n x = Owl_maths_special.expn n x

let shichi x =
  let si = Ctypes.(allocate double 0.) in
  let ci = Ctypes.(allocate double 0.) in
  Owl_maths_special.shichi x si ci |> ignore;
  Ctypes.(!@si, !@ci)

let shi x = shichi x |> fst

let chi x = shichi x |> snd

let sici x =
  let si = Ctypes.(allocate double 0.) in
  let ci = Ctypes.(allocate double 0.) in
  Owl_maths_special.sici x si ci |> ignore;
  Ctypes.(!@si, !@ci)

let si x = sici x |> fst

let ci x = sici x |> snd

let gamma x = Owl_maths_special.gamma x

let rgamma x = Owl_maths_special.rgamma x

let loggamma x = Owl_maths_special.loggamma x

let gammainc a x = Owl_maths_special.gammainc a x

let gammaincinv a x = Owl_maths_special.gammaincinv a x

let gammaincc a x = Owl_maths_special.gammaincc a x

let gammainccinv a x = Owl_maths_special.gammainccinv a x

let psi x = Owl_maths_special.psi x

let fact x =
  Owl_exception.(check (x >= 0) (NON_NEGATIVE_INT x));
  Owl_maths_special.fact x

let log_fact x =
  Owl_exception.(check (x >= 0) (NON_NEGATIVE_INT x));
  Owl_maths_special.log_fact x

let doublefact x =
  Owl_exception.(check (x >= 0) (NON_NEGATIVE_INT x));
  Owl_maths_special.doublefact x

let log_doublefact x =
  Owl_exception.(check (x >= 0) (NON_NEGATIVE_INT x));
  Owl_maths_special.log_doublefact x

let beta a b = Owl_maths_special.beta a b

let betainc a b x = Owl_maths_special.betainc a b x

let betaincinv a b y = Owl_maths_special.betaincinv a b y

let zeta x q = Owl_maths_special.zeta x q

let zetac x = Owl_maths_special.zetac x

let combination_float n k = Owl_maths_special.combination n k |> trunc

let combination n k = combination_float n k |> int_of_float

let log_combination n k = Owl_maths_special.log_combination n k

let permutation_float n k =
  let r = ref 1. in
  for i = 0 to k - 1 do
    r := !r *. float_of_int (n - i)
  done;
  !r |> trunc

let permutation n k = permutation_float n k |> int_of_float

let erf x = Owl_maths_special.erf x

let erfc x = Owl_maths_special.erfc x

let erfcx x = Owl_maths_special.erfcx x

let erfinv x = Owl_maths_special.erfinv x

let erfcinv x = Owl_maths_special.erfcinv x

let dawsn x = Owl_maths_special.dawsn x

let fresnel x =
  let ssa = Ctypes.(allocate double 0.) in
  let csa = Ctypes.(allocate double 0.) in
  Owl_maths_special.fresnel x ssa csa |> ignore;
  Ctypes.(!@ssa, !@csa)

let struve v x = Owl_maths_special.struve v x

let same_sign = Owl_base_maths.same_sign

let is_simplex = Owl_base_maths.is_simplex

let is_nan = Owl_base_maths.is_nan

let is_inf = Owl_base_maths.is_inf

let is_normal = Owl_base_maths.is_normal

let is_subnormal = Owl_base_maths.is_subnormal

let is_odd = Owl_base_maths.is_odd

let is_even = Owl_base_maths.is_even

let is_pow2 = Owl_base_maths.is_pow2

let is_int = Owl_base_maths.is_int

let is_sqr = Owl_base_maths.is_sqr

let mulmod a b m = Owl_maths_special.mulmod a b m

let powmod a b m = Owl_maths_special.powmod a b m

let is_prime = Owl_base_maths.is_prime

let fermat_fact = Owl_base_maths.fermat_fact

let nextafter = Owl_maths_special.nextafter

let nextafterf = Owl_maths_special.nextafterf

let bdtr k n p = Owl_maths_special.bdtr k n p

let bdtrc k n p = Owl_maths_special.bdtrc k n p

let bdtri k n y = Owl_maths_special.bdtri k n y

let btdtr a b x = Owl_maths_special.btdtr a b x

let btdtri a b p = Owl_maths_special.btdtri a b p



(* ends here *)
OCaml

Innovation. Community. Security.