ops-mel 0.7.1

Mélodium core operations library
Documentation
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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
use melodium_core::*;
use melodium_macro::{check, mel_function, mel_treatment};

/// Elevates `base` from `exponent`
#[mel_function]
pub fn pow(base: f64, exponent: f64) -> f64 {
    base.powf(exponent)
}

/// Computes cube root of `value`
#[mel_function]
pub fn cbrt(value: f64) -> f64 {
    value.cbrt()
}

/// Computes natural logarithm of `value`
#[mel_function]
pub fn ln(value: f64) -> f64 {
    value.ln()
}

/// Computes logarithm of `value` with `base`
#[mel_function]
pub fn log(value: f64, base: f64) -> f64 {
    value.log(base)
}

/// Computes quare root of `value`
#[mel_function]
pub fn sqrt(value: f64) -> f64 {
    value.sqrt()
}

/// Computes arccosine of `value` (in radians)
#[mel_function]
pub fn acos(value: f64) -> f64 {
    value.acos()
}

/// Computes inverse hyperbolic cosine of `value`
#[mel_function]
pub fn acosh(value: f64) -> f64 {
    value.acosh()
}

/// Computes arcsine of `value` (in radians)
#[mel_function]
pub fn asin(value: f64) -> f64 {
    value.asin()
}

/// Computes inverse hyperbolic sine of `value`
#[mel_function]
pub fn asinh(value: f64) -> f64 {
    value.asinh()
}

/// Computes arctangent of `value` (in radians)
#[mel_function]
pub fn atan(value: f64) -> f64 {
    value.atan()
}

/// Computes inverse hyperbolic tangent of `value`
#[mel_function]
pub fn atanh(value: f64) -> f64 {
    value.atanh()
}

/// Computes cosine of `value` (in radians)
#[mel_function]
pub fn cos(value: f64) -> f64 {
    value.cos()
}

/// Computes hyperbolic cosine of `value`
#[mel_function]
pub fn cosh(value: f64) -> f64 {
    value.cosh()
}

/// Computes sine of `value` (in radians)
#[mel_function]
pub fn sin(value: f64) -> f64 {
    value.sin()
}

/// Computes hyperbolic sine of `value`
#[mel_function]
pub fn sinh(value: f64) -> f64 {
    value.sinh()
}

/// Computes tangent of `value` (in radians)
#[mel_function]
pub fn tan(value: f64) -> f64 {
    value.tan()
}

/// Computes hyperbolic tangent of `value`
#[mel_function]
pub fn tanh(value: f64) -> f64 {
    value.tanh()
}

/// Elevates values from a stream of `f64` to the power of another one.
///
/// Values passed through `base` are elevated to the power of `exponent`.
#[mel_treatment(
    input base Stream<f64>
    input exponent Stream<f64>
    output power Stream<f64>
)]
pub async fn pow() {
    while let (Ok(base), Ok(exp)) = (base.recv_one_f64().await, exponent.recv_one_f64().await) {
        check!(power.send_one_f64(base.powf(exp)).await)
    }
}

/// Computes the cube roots from a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output root Stream<f64>
)]
pub async fn cbrt() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            root.send_f64(values.into_iter().map(|v| v.cbrt()).collect())
                .await
        )
    }
}

/// Computes the natural logarithms of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output log Stream<f64>
)]
pub async fn ln() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            log.send_f64(values.into_iter().map(|v| v.ln()).collect())
                .await
        )
    }
}

/// Computes logarithms from a stream of `f64` with the base of another one.
#[mel_treatment(
    input base Stream<f64>
    input value Stream<f64>
    output log Stream<f64>
)]
pub async fn log() {
    while let (Ok(base), Ok(value)) = (base.recv_one_f64().await, value.recv_one_f64().await) {
        check!(log.send_one_f64(value.log(base)).await)
    }
}

/// Computes the square roots from a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output root Stream<f64>
)]
pub async fn sqrt() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            root.send_f64(values.into_iter().map(|v| v.sqrt()).collect())
                .await
        )
    }
}

/// Computes arccosine (in radians) of a stream of `f64`.
///
/// Gives values in the range [0, pi] or not-a-number if outside range [-1, 1].
#[mel_treatment(
    input value Stream<f64>
    output acos Stream<f64>
)]
pub async fn acos() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            acos.send_f64(values.into_iter().map(|v| v.acos()).collect())
                .await
        )
    }
}

/// Computes inverse hyperbolic cosine of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output acosh Stream<f64>
)]
pub async fn acosh() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            acosh
                .send_f64(values.into_iter().map(|v| v.acosh()).collect())
                .await
        )
    }
}

/// Computes arcsine (in radians) of a stream of `f64`.
///
/// Gives values in the range [0, pi] or not-a-number if outside range [-1, 1].
#[mel_treatment(
    input value Stream<f64>
    output asin Stream<f64>
)]
pub async fn asin() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            asin.send_f64(values.into_iter().map(|v| v.asin()).collect())
                .await
        )
    }
}

/// Computes inverse hyperbolic sine of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output asinh Stream<f64>
)]
pub async fn asinh() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            asinh
                .send_f64(values.into_iter().map(|v| v.asinh()).collect())
                .await
        )
    }
}

/// Computes arctangent (in radians) of a stream of `f64`.
///
/// Gives values in the range [-pi/2, pi/2].
#[mel_treatment(
    input value Stream<f64>
    output atan Stream<f64>
)]
pub async fn atan() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            atan.send_f64(values.into_iter().map(|v| v.atan()).collect())
                .await
        )
    }
}

/// Computes inverse hyperbolic tangent of a stream of  `f64`.
#[mel_treatment(
    input value Stream<f64>
    output atanh Stream<f64>
)]
pub async fn atanh() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            atanh
                .send_f64(values.into_iter().map(|v| v.atanh()).collect())
                .await
        )
    }
}

/// Computes cosine (in radians) of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output cos Stream<f64>
)]
pub async fn cos() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            cos.send_f64(values.into_iter().map(|v| v.cos()).collect())
                .await
        )
    }
}

/// Computes hyberbolic cosine of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output cosh Stream<f64>
)]
pub async fn cosh() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            cosh.send_f64(values.into_iter().map(|v| v.cosh()).collect())
                .await
        )
    }
}

/// Computes sine (in radians) of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output sin Stream<f64>
)]
pub async fn sin() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            sin.send_f64(values.into_iter().map(|v| v.sin()).collect())
                .await
        )
    }
}

/// Computes hyberbolic sine of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output sinh Stream<f64>
)]
pub async fn sinh() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            sinh.send_f64(values.into_iter().map(|v| v.sinh()).collect())
                .await
        )
    }
}

/// Computes tangent (in radians) of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output tan Stream<f64>
)]
pub async fn tan() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            tan.send_f64(values.into_iter().map(|v| v.tan()).collect())
                .await
        )
    }
}

/// Computes hyberbolic tangent of a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output tanh Stream<f64>
)]
pub async fn tanh() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            tanh.send_f64(values.into_iter().map(|v| v.tanh()).collect())
                .await
        )
    }
}

/// Add `a` and `b`
#[mel_function]
pub fn add(a: f64, b: f64) -> f64 {
    a + b
}

/// Divide `dividend` by `divisor`
#[mel_function]
pub fn div(dividend: f64, divisor: f64) -> f64 {
    dividend / divisor
}

/// Multiply `a` by `b`
#[mel_function]
pub fn mult(a: f64, b: f64) -> f64 {
    a * b
}

/// Get the remainder of `dividend` by `divisor`
#[mel_function]
pub fn rem(dividend: f64, divisor: f64) -> f64 {
    dividend % divisor
}

/// Substract `b` from `a`
#[mel_function]
pub fn sub(a: f64, b: f64) -> f64 {
    a - b
}

/// Tells whether `a` is strictly greater than `b`.
#[mel_function]
pub fn gt(a: f64, b: f64) -> bool {
    a > b
}

/// Tells whether `a` is strictly lower than `b`.
#[mel_function]
pub fn lt(a: f64, b: f64) -> bool {
    a < b
}

/// Compares and gives the minimum of two values.
#[mel_function]
pub fn min(a: f64, b: f64) -> f64 {
    a.min(b)
}

/// Compares and gives the maximum of two values.
#[mel_function]
pub fn max(a: f64, b: f64) -> f64 {
    a.max(b)
}

/// Add values from two streams of `f64`.
///
/// Values passed through `a` & `b` are added and send in sum.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output sum Stream<f64>
)]
pub async fn add() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(sum.send_one_f64(a + b).await)
    }
}

/// Divide values from two streams of `f64`.
///
/// Every `a` number passed through the stream is divided by `b` counterpart.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output quotient Stream<f64>
)]
pub async fn div() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(quotient.send_one_f64(a / b).await)
    }
}

/// Multiply values from two streams of `f64`.
///
/// Every `a` number passed through the stream is multiplied by `b` counterpart.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output product Stream<f64>
)]
pub async fn mult() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(product.send_one_f64(a * b).await)
    }
}

/// Give the remainder of the division from two streams of `f64`.
///
/// Every `a` number passed through the stream is divided by `b` and the remainder is outputted.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output remainder Stream<f64>
)]
pub async fn rem() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(remainder.send_one_f64(a % b).await)
    }
}

/// Substract values from two streams of `f64`.
///
/// Every `a` number passed through the stream get `b` substracted.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output diff Stream<f64>
)]
pub async fn sub() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(diff.send_one_f64(a - b).await)
    }
}

/// Compares and gives the minimum of two values.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output min Stream<f64>
)]
pub async fn min() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(min.send_one_f64(a.min(b)).await)
    }
}

/// Compares and gives the maximum of two values.
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output max Stream<f64>
)]
pub async fn max() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(max.send_one_f64(a.max(b)).await)
    }
}

/// Determine whether `a` is strictly lower than `b`
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output is Stream<bool>
)]
pub async fn lower_than() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(is.send_one_bool(a < b).await)
    }
}

/// Determine whether `a` is strictly greater than `b`
#[mel_treatment(
    input a Stream<f64>
    input b Stream<f64>
    output is Stream<bool>
)]
pub async fn greater_than() {
    while let (Ok(a), Ok(b)) = (a.recv_one_f64().await, b.recv_one_f64().await) {
        check!(is.send_one_bool(a > b).await)
    }
}

/// Get absolute value
#[mel_function]
pub fn abs(value: f64) -> f64 {
    value.abs()
}

/// Get the absolute values from a stream of `f64`.
#[mel_treatment(
    input value Stream<f64>
    output abs Stream<f64>
)]
pub async fn abs() {
    while let Ok(values) = value.recv_f64().await {
        check!(
            abs.send_f64(values.into_iter().map(|v| v.abs()).collect())
                .await
        )
    }
}