typed-ffmpeg-compatible 3.5.1__py3-none-any.whl → 3.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- typed_ffmpeg/__init__.py +4 -1
- typed_ffmpeg/_version.py +2 -2
- typed_ffmpeg/base.py +4 -1
- typed_ffmpeg/codecs/__init__.py +2 -0
- typed_ffmpeg/codecs/decoders.py +1852 -1853
- typed_ffmpeg/codecs/encoders.py +2001 -1782
- typed_ffmpeg/codecs/schema.py +6 -12
- typed_ffmpeg/common/__init__.py +1 -0
- typed_ffmpeg/common/cache.py +9 -6
- typed_ffmpeg/common/schema.py +11 -0
- typed_ffmpeg/common/serialize.py +13 -7
- typed_ffmpeg/compile/__init__.py +1 -0
- typed_ffmpeg/compile/compile_cli.py +55 -8
- typed_ffmpeg/compile/compile_json.py +4 -0
- typed_ffmpeg/compile/compile_python.py +15 -0
- typed_ffmpeg/compile/context.py +15 -4
- typed_ffmpeg/compile/validate.py +9 -8
- typed_ffmpeg/dag/factory.py +2 -0
- typed_ffmpeg/dag/global_runnable/__init__.py +1 -0
- typed_ffmpeg/dag/global_runnable/global_args.py +2 -2
- typed_ffmpeg/dag/global_runnable/runnable.py +51 -11
- typed_ffmpeg/dag/io/__init__.py +1 -0
- typed_ffmpeg/dag/io/_input.py +20 -5
- typed_ffmpeg/dag/io/_output.py +24 -9
- typed_ffmpeg/dag/io/output_args.py +21 -7
- typed_ffmpeg/dag/nodes.py +20 -0
- typed_ffmpeg/dag/schema.py +19 -6
- typed_ffmpeg/dag/utils.py +2 -2
- typed_ffmpeg/exceptions.py +2 -1
- typed_ffmpeg/expressions.py +884 -0
- typed_ffmpeg/ffprobe/__init__.py +1 -0
- typed_ffmpeg/ffprobe/parse.py +7 -1
- typed_ffmpeg/ffprobe/probe.py +3 -1
- typed_ffmpeg/ffprobe/schema.py +83 -1
- typed_ffmpeg/ffprobe/xml2json.py +8 -2
- typed_ffmpeg/filters.py +540 -631
- typed_ffmpeg/formats/__init__.py +2 -0
- typed_ffmpeg/formats/demuxers.py +1869 -1921
- typed_ffmpeg/formats/muxers.py +1382 -1107
- typed_ffmpeg/formats/schema.py +6 -12
- typed_ffmpeg/info.py +8 -0
- typed_ffmpeg/options/__init__.py +15 -0
- typed_ffmpeg/options/codec.py +711 -0
- typed_ffmpeg/options/format.py +196 -0
- typed_ffmpeg/options/framesync.py +43 -0
- typed_ffmpeg/options/timeline.py +22 -0
- typed_ffmpeg/schema.py +15 -0
- typed_ffmpeg/sources.py +392 -381
- typed_ffmpeg/streams/__init__.py +2 -0
- typed_ffmpeg/streams/audio.py +1071 -882
- typed_ffmpeg/streams/av.py +9 -3
- typed_ffmpeg/streams/subtitle.py +3 -3
- typed_ffmpeg/streams/video.py +1873 -1725
- typed_ffmpeg/types.py +3 -2
- typed_ffmpeg/utils/__init__.py +1 -0
- typed_ffmpeg/utils/escaping.py +8 -4
- typed_ffmpeg/utils/frozendict.py +31 -1
- typed_ffmpeg/utils/lazy_eval/__init__.py +1 -0
- typed_ffmpeg/utils/lazy_eval/operator.py +75 -27
- typed_ffmpeg/utils/lazy_eval/schema.py +176 -4
- typed_ffmpeg/utils/run.py +2 -0
- typed_ffmpeg/utils/snapshot.py +3 -2
- typed_ffmpeg/utils/typing.py +2 -1
- typed_ffmpeg/utils/view.py +2 -1
- {typed_ffmpeg_compatible-3.5.1.dist-info → typed_ffmpeg_compatible-3.6.dist-info}/METADATA +1 -1
- typed_ffmpeg_compatible-3.6.dist-info/RECORD +73 -0
- typed_ffmpeg_compatible-3.5.1.dist-info/RECORD +0 -67
- {typed_ffmpeg_compatible-3.5.1.dist-info → typed_ffmpeg_compatible-3.6.dist-info}/WHEEL +0 -0
- {typed_ffmpeg_compatible-3.5.1.dist-info → typed_ffmpeg_compatible-3.6.dist-info}/entry_points.txt +0 -0
- {typed_ffmpeg_compatible-3.5.1.dist-info → typed_ffmpeg_compatible-3.6.dist-info}/licenses/LICENSE +0 -0
- {typed_ffmpeg_compatible-3.5.1.dist-info → typed_ffmpeg_compatible-3.6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,884 @@
|
|
1
|
+
"""FFmpeg expression functions and utilities."""
|
2
|
+
|
3
|
+
from typing import Any
|
4
|
+
|
5
|
+
|
6
|
+
class Expression(str):
|
7
|
+
"""A string-based expression class for FFmpeg expressions."""
|
8
|
+
|
9
|
+
def __init__(self, expression: str):
|
10
|
+
"""
|
11
|
+
Initialize an Expression with a string expression.
|
12
|
+
|
13
|
+
Args:
|
14
|
+
expression: The FFmpeg expression string.
|
15
|
+
|
16
|
+
"""
|
17
|
+
self.expression = expression
|
18
|
+
|
19
|
+
def __str__(self) -> str:
|
20
|
+
"""
|
21
|
+
Return the expression string.
|
22
|
+
|
23
|
+
Returns:
|
24
|
+
The expression string.
|
25
|
+
|
26
|
+
"""
|
27
|
+
return self.expression
|
28
|
+
|
29
|
+
def __repr__(self) -> str:
|
30
|
+
"""
|
31
|
+
Return a string representation of the Expression.
|
32
|
+
|
33
|
+
Returns:
|
34
|
+
A string representation of the Expression.
|
35
|
+
|
36
|
+
"""
|
37
|
+
return f"Expression({self.expression})"
|
38
|
+
|
39
|
+
# The following binary operators are available: +, -, *, /, ^.
|
40
|
+
def __add__(self, other: Any) -> "Expression":
|
41
|
+
"""
|
42
|
+
Add another value to this expression.
|
43
|
+
|
44
|
+
Returns:
|
45
|
+
A new Expression with the addition operation.
|
46
|
+
|
47
|
+
"""
|
48
|
+
return Expression(f"{self.expression}+{other}")
|
49
|
+
|
50
|
+
def __sub__(self, other: Any) -> "Expression":
|
51
|
+
"""
|
52
|
+
Subtract another value from this expression.
|
53
|
+
|
54
|
+
Returns:
|
55
|
+
A new Expression with the subtraction operation.
|
56
|
+
|
57
|
+
"""
|
58
|
+
return Expression(f"{self.expression}-{other}")
|
59
|
+
|
60
|
+
def __mul__(self, other: Any) -> "Expression":
|
61
|
+
"""
|
62
|
+
Multiply this expression by another value.
|
63
|
+
|
64
|
+
Returns:
|
65
|
+
A new Expression with the multiplication operation.
|
66
|
+
|
67
|
+
"""
|
68
|
+
return Expression(f"{self.expression}*{other}")
|
69
|
+
|
70
|
+
def __truediv__(self, other: Any) -> "Expression":
|
71
|
+
"""
|
72
|
+
Divide this expression by another value.
|
73
|
+
|
74
|
+
Returns:
|
75
|
+
A new Expression with the division operation.
|
76
|
+
|
77
|
+
"""
|
78
|
+
return Expression(f"{self.expression}/{other}")
|
79
|
+
|
80
|
+
def __mod__(self, other: Any) -> "Expression":
|
81
|
+
"""
|
82
|
+
Compute the modulo of this expression with another value.
|
83
|
+
|
84
|
+
Returns:
|
85
|
+
A new Expression with the modulo operation.
|
86
|
+
|
87
|
+
"""
|
88
|
+
return Expression(f"{self.expression}%{other}")
|
89
|
+
|
90
|
+
def __pow__(self, other: Any) -> "Expression":
|
91
|
+
"""
|
92
|
+
Raise this expression to the power of another value.
|
93
|
+
|
94
|
+
Returns:
|
95
|
+
A new Expression with the power operation.
|
96
|
+
|
97
|
+
"""
|
98
|
+
return Expression(f"{self.expression}^{other}")
|
99
|
+
|
100
|
+
# The following unary operators are available: +, -.
|
101
|
+
def __neg__(self) -> "Expression":
|
102
|
+
"""
|
103
|
+
Return the negative of this expression.
|
104
|
+
|
105
|
+
Returns:
|
106
|
+
A new Expression with the negation operation.
|
107
|
+
|
108
|
+
"""
|
109
|
+
return Expression(f"-{self.expression}")
|
110
|
+
|
111
|
+
def __pos__(self) -> "Expression":
|
112
|
+
"""
|
113
|
+
Return the positive of this expression.
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
A new Expression with the positive operation.
|
117
|
+
|
118
|
+
"""
|
119
|
+
return Expression(f"+{self.expression}")
|
120
|
+
|
121
|
+
|
122
|
+
def abs(x: Any) -> Expression:
|
123
|
+
"""
|
124
|
+
Compute absolute value of x.
|
125
|
+
|
126
|
+
Args:
|
127
|
+
x: The value to compute absolute value for.
|
128
|
+
|
129
|
+
Returns:
|
130
|
+
Expression representing the absolute value.
|
131
|
+
|
132
|
+
"""
|
133
|
+
return Expression(f"abs({x})")
|
134
|
+
|
135
|
+
|
136
|
+
def acos(x: Any) -> Expression:
|
137
|
+
"""
|
138
|
+
Compute arccosine of x.
|
139
|
+
|
140
|
+
Args:
|
141
|
+
x: The value to compute arccosine for.
|
142
|
+
|
143
|
+
Returns:
|
144
|
+
Expression representing the arccosine.
|
145
|
+
|
146
|
+
"""
|
147
|
+
return Expression(f"acos({x})")
|
148
|
+
|
149
|
+
|
150
|
+
def asin(x: Any) -> Expression:
|
151
|
+
"""
|
152
|
+
Compute arcsine of x.
|
153
|
+
|
154
|
+
Args:
|
155
|
+
x: The value to compute arcsine for.
|
156
|
+
|
157
|
+
Returns:
|
158
|
+
Expression representing the arcsine.
|
159
|
+
|
160
|
+
"""
|
161
|
+
return Expression(f"asin({x})")
|
162
|
+
|
163
|
+
|
164
|
+
def atan(x: Any) -> Expression:
|
165
|
+
"""
|
166
|
+
Compute arctangent of x.
|
167
|
+
|
168
|
+
Args:
|
169
|
+
x: The value to compute arctangent for.
|
170
|
+
|
171
|
+
Returns:
|
172
|
+
Expression representing the arctangent.
|
173
|
+
|
174
|
+
"""
|
175
|
+
return Expression(f"atan({x})")
|
176
|
+
|
177
|
+
|
178
|
+
def atan2(x: Any) -> Expression:
|
179
|
+
"""
|
180
|
+
Compute principal value of the arc tangent of y/x.
|
181
|
+
|
182
|
+
Args:
|
183
|
+
x: The value to compute arctangent for.
|
184
|
+
|
185
|
+
Returns:
|
186
|
+
Expression representing the arctangent.
|
187
|
+
|
188
|
+
"""
|
189
|
+
return Expression(f"atan2({x})")
|
190
|
+
|
191
|
+
|
192
|
+
def between(x: Any, min: Any, max: Any) -> Expression:
|
193
|
+
"""
|
194
|
+
Return 1 if x is greater than or equal to min and lesser than or equal to max, 0 otherwise.
|
195
|
+
|
196
|
+
Args:
|
197
|
+
x: The value to check.
|
198
|
+
min: The minimum value.
|
199
|
+
max: The maximum value.
|
200
|
+
|
201
|
+
Returns:
|
202
|
+
Expression representing the comparison result.
|
203
|
+
|
204
|
+
"""
|
205
|
+
return Expression(f"between({x},{min},{max})")
|
206
|
+
|
207
|
+
|
208
|
+
def bitand(x: Any, y: Any) -> Expression:
|
209
|
+
"""
|
210
|
+
Compute bitwise and/or operation on x and y.
|
211
|
+
|
212
|
+
Args:
|
213
|
+
x: The first value.
|
214
|
+
y: The second value.
|
215
|
+
|
216
|
+
Returns:
|
217
|
+
Expression representing the bitwise AND result.
|
218
|
+
|
219
|
+
"""
|
220
|
+
return Expression(f"bitand({x},{y})")
|
221
|
+
|
222
|
+
|
223
|
+
def bitor(x: Any, y: Any) -> Expression:
|
224
|
+
"""
|
225
|
+
Compute bitwise and/or operation on x and y.
|
226
|
+
|
227
|
+
Args:
|
228
|
+
x: The first value.
|
229
|
+
y: The second value.
|
230
|
+
|
231
|
+
Returns:
|
232
|
+
Expression representing the bitwise OR result.
|
233
|
+
|
234
|
+
"""
|
235
|
+
return Expression(f"bitor({x},{y})")
|
236
|
+
|
237
|
+
|
238
|
+
def ceil(expr: Any) -> Expression:
|
239
|
+
"""
|
240
|
+
Round the value of expression expr upwards to the nearest integer. For example, "ceil(1.5)" is "2.0".
|
241
|
+
|
242
|
+
Args:
|
243
|
+
expr: The expression to round up.
|
244
|
+
|
245
|
+
Returns:
|
246
|
+
Expression representing the ceiling value.
|
247
|
+
|
248
|
+
"""
|
249
|
+
return Expression(f"ceil({expr})")
|
250
|
+
|
251
|
+
|
252
|
+
def clip(x: Any, min: Any, max: Any) -> Expression:
|
253
|
+
"""
|
254
|
+
Return the value of x clipped between min and max.
|
255
|
+
|
256
|
+
Args:
|
257
|
+
x: The value to clip.
|
258
|
+
min: The minimum value.
|
259
|
+
max: The maximum value.
|
260
|
+
|
261
|
+
Returns:
|
262
|
+
Expression representing the clipped value.
|
263
|
+
|
264
|
+
"""
|
265
|
+
return Expression(f"clip({x},{min},{max})")
|
266
|
+
|
267
|
+
|
268
|
+
def cos(x: Any) -> Expression:
|
269
|
+
"""
|
270
|
+
Compute cosine of x.
|
271
|
+
|
272
|
+
Args:
|
273
|
+
x: The value to compute cosine for.
|
274
|
+
|
275
|
+
Returns:
|
276
|
+
Expression representing the cosine.
|
277
|
+
|
278
|
+
"""
|
279
|
+
return Expression(f"cos({x})")
|
280
|
+
|
281
|
+
|
282
|
+
def cosh(x: Any) -> Expression:
|
283
|
+
"""
|
284
|
+
Compute hyperbolic cosine of x.
|
285
|
+
|
286
|
+
Args:
|
287
|
+
x: The value to compute hyperbolic cosine for.
|
288
|
+
|
289
|
+
Returns:
|
290
|
+
Expression representing the hyperbolic cosine.
|
291
|
+
|
292
|
+
"""
|
293
|
+
return Expression(f"cosh({x})")
|
294
|
+
|
295
|
+
|
296
|
+
def eq(x: Any, y: Any) -> Expression:
|
297
|
+
"""
|
298
|
+
Return 1 if x and y are equivalent, 0 otherwise.
|
299
|
+
|
300
|
+
Args:
|
301
|
+
x: The first value to compare.
|
302
|
+
y: The second value to compare.
|
303
|
+
|
304
|
+
Returns:
|
305
|
+
Expression representing the equality comparison.
|
306
|
+
|
307
|
+
"""
|
308
|
+
return Expression(f"eq({x},{y})")
|
309
|
+
|
310
|
+
|
311
|
+
def exp(x: Any) -> Expression:
|
312
|
+
"""
|
313
|
+
Compute exponential of x (with base e, the Euler's number).
|
314
|
+
|
315
|
+
Args:
|
316
|
+
x: The value to compute exponential for.
|
317
|
+
|
318
|
+
Returns:
|
319
|
+
Expression representing the exponential.
|
320
|
+
|
321
|
+
"""
|
322
|
+
return Expression(f"exp({x})")
|
323
|
+
|
324
|
+
|
325
|
+
def floor(expr: Any) -> Expression:
|
326
|
+
"""
|
327
|
+
Round the value of expression expr downwards to the nearest integer. For example, "floor(-1.5)" is "-2.0".
|
328
|
+
|
329
|
+
Args:
|
330
|
+
expr: The expression to round down.
|
331
|
+
|
332
|
+
Returns:
|
333
|
+
Expression representing the floor value.
|
334
|
+
|
335
|
+
"""
|
336
|
+
return Expression(f"floor({expr})")
|
337
|
+
|
338
|
+
|
339
|
+
def gauss(x: Any) -> Expression:
|
340
|
+
"""
|
341
|
+
Compute Gauss function of x, corresponding to exp(-x*x/2) / sqrt(2*PI).
|
342
|
+
|
343
|
+
Args:
|
344
|
+
x: The value to compute Gauss function for.
|
345
|
+
|
346
|
+
Returns:
|
347
|
+
Expression representing the Gauss function.
|
348
|
+
|
349
|
+
"""
|
350
|
+
return Expression(f"gauss({x})")
|
351
|
+
|
352
|
+
|
353
|
+
def gcd(x: Any, y: Any) -> Expression:
|
354
|
+
"""
|
355
|
+
Return the greatest common divisor of x and y. If both x and y are 0 or either or both are less than zero then behavior is undefined.
|
356
|
+
|
357
|
+
Args:
|
358
|
+
x: The first value.
|
359
|
+
y: The second value.
|
360
|
+
|
361
|
+
Returns:
|
362
|
+
Expression representing the greatest common divisor.
|
363
|
+
|
364
|
+
"""
|
365
|
+
return Expression(f"gcd({x},{y})")
|
366
|
+
|
367
|
+
|
368
|
+
def gt(x: Any, y: Any) -> Expression:
|
369
|
+
"""
|
370
|
+
Return 1 if x is greater than y, 0 otherwise.
|
371
|
+
|
372
|
+
Args:
|
373
|
+
x: The first value to compare.
|
374
|
+
y: The second value to compare.
|
375
|
+
|
376
|
+
Returns:
|
377
|
+
Expression representing the greater than comparison.
|
378
|
+
|
379
|
+
"""
|
380
|
+
return Expression(f"gt({x},{y})")
|
381
|
+
|
382
|
+
|
383
|
+
def gte(x: Any, y: Any) -> Expression:
|
384
|
+
"""
|
385
|
+
Return 1 if x is greater than or equal to y, 0 otherwise.
|
386
|
+
|
387
|
+
Args:
|
388
|
+
x: The first value to compare.
|
389
|
+
y: The second value to compare.
|
390
|
+
|
391
|
+
Returns:
|
392
|
+
Expression representing the greater than or equal comparison.
|
393
|
+
|
394
|
+
"""
|
395
|
+
return Expression(f"gte({x},{y})")
|
396
|
+
|
397
|
+
|
398
|
+
def hypot(x: Any, y: Any) -> Expression:
|
399
|
+
"""
|
400
|
+
Return sqrt(x*x + y*y), the length of the hypotenuse of a right triangle with sides of length x and y, or the distance of the point (x, y) from the origin.
|
401
|
+
|
402
|
+
Args:
|
403
|
+
x: The first value.
|
404
|
+
y: The second value.
|
405
|
+
|
406
|
+
Returns:
|
407
|
+
Expression representing the hypotenuse length.
|
408
|
+
|
409
|
+
"""
|
410
|
+
return Expression(f"hypot({x},{y})")
|
411
|
+
|
412
|
+
|
413
|
+
def if_(x: Any, y: Any, z: Any | None = None) -> Expression:
|
414
|
+
"""
|
415
|
+
Evaluate x, and if the result is non-zero return the result of the evaluation of y, return 0 otherwise.
|
416
|
+
|
417
|
+
Args:
|
418
|
+
x: The condition to evaluate.
|
419
|
+
y: The value to return if condition is true.
|
420
|
+
z: Optional value to return if condition is false.
|
421
|
+
|
422
|
+
Returns:
|
423
|
+
Expression representing the conditional result.
|
424
|
+
|
425
|
+
"""
|
426
|
+
if z is None:
|
427
|
+
return Expression(f"if({x},{y})")
|
428
|
+
else:
|
429
|
+
return Expression(f"if({x},{y},{z})")
|
430
|
+
|
431
|
+
|
432
|
+
def ifnot(x: Any, y: Any, z: Any | None = None) -> Expression:
|
433
|
+
"""
|
434
|
+
Evaluate x, and if the result is zero return the result of the evaluation of y, return 0 otherwise.
|
435
|
+
|
436
|
+
Args:
|
437
|
+
x: The condition to evaluate.
|
438
|
+
y: The value to return if condition is false.
|
439
|
+
z: Optional value to return if condition is true.
|
440
|
+
|
441
|
+
Returns:
|
442
|
+
Expression representing the conditional result.
|
443
|
+
|
444
|
+
"""
|
445
|
+
if z is None:
|
446
|
+
return Expression(f"ifnot({x},{y})")
|
447
|
+
else:
|
448
|
+
return Expression(f"ifnot({x},{y},{z})")
|
449
|
+
|
450
|
+
|
451
|
+
def isinf(x: Any) -> Expression:
|
452
|
+
"""
|
453
|
+
Return 1.0 if x is +/-INFINITY, 0.0 otherwise.
|
454
|
+
|
455
|
+
Args:
|
456
|
+
x: The value to check for infinity.
|
457
|
+
|
458
|
+
Returns:
|
459
|
+
Expression representing the infinity check.
|
460
|
+
|
461
|
+
"""
|
462
|
+
return Expression(f"isinf({x})")
|
463
|
+
|
464
|
+
|
465
|
+
def isnan(x: Any) -> Expression:
|
466
|
+
"""
|
467
|
+
Return 1.0 if x is NAN, 0.0 otherwise.
|
468
|
+
|
469
|
+
Args:
|
470
|
+
x: The value to check for NaN.
|
471
|
+
|
472
|
+
Returns:
|
473
|
+
Expression representing the NaN check.
|
474
|
+
|
475
|
+
"""
|
476
|
+
return Expression(f"isnan({x})")
|
477
|
+
|
478
|
+
|
479
|
+
def ld(idx: Any) -> Expression:
|
480
|
+
"""
|
481
|
+
Load the value of the internal variable with index idx, which was previously stored with st(idx, expr). The function returns the loaded value.
|
482
|
+
|
483
|
+
Args:
|
484
|
+
idx: The index of the internal variable to load.
|
485
|
+
|
486
|
+
Returns:
|
487
|
+
Expression representing the loaded value.
|
488
|
+
|
489
|
+
"""
|
490
|
+
return Expression(f"ld({idx})")
|
491
|
+
|
492
|
+
|
493
|
+
def lerp(x: Any, y: Any, z: Any) -> Expression:
|
494
|
+
"""
|
495
|
+
Return linear interpolation between x and y by amount of z.
|
496
|
+
|
497
|
+
Args:
|
498
|
+
x: The first value.
|
499
|
+
y: The second value.
|
500
|
+
z: The interpolation amount.
|
501
|
+
|
502
|
+
Returns:
|
503
|
+
Expression representing the interpolated value.
|
504
|
+
|
505
|
+
"""
|
506
|
+
return Expression(f"lerp({x},{y},{z})")
|
507
|
+
|
508
|
+
|
509
|
+
def log(x: Any) -> Expression:
|
510
|
+
"""
|
511
|
+
Compute natural logarithm of x.
|
512
|
+
|
513
|
+
Args:
|
514
|
+
x: The value to compute natural logarithm for.
|
515
|
+
|
516
|
+
Returns:
|
517
|
+
Expression representing the natural logarithm.
|
518
|
+
|
519
|
+
"""
|
520
|
+
return Expression(f"log({x})")
|
521
|
+
|
522
|
+
|
523
|
+
def lt(x: Any, y: Any) -> Expression:
|
524
|
+
"""
|
525
|
+
Return 1 if x is lesser than y, 0 otherwise.
|
526
|
+
|
527
|
+
Args:
|
528
|
+
x: The first value to compare.
|
529
|
+
y: The second value to compare.
|
530
|
+
|
531
|
+
Returns:
|
532
|
+
Expression representing the less than comparison.
|
533
|
+
|
534
|
+
"""
|
535
|
+
return Expression(f"lt({x},{y})")
|
536
|
+
|
537
|
+
|
538
|
+
def lte(x: Any, y: Any) -> Expression:
|
539
|
+
"""
|
540
|
+
Return 1 if x is lesser than or equal to y, 0 otherwise.
|
541
|
+
|
542
|
+
Args:
|
543
|
+
x: The first value to compare.
|
544
|
+
y: The second value to compare.
|
545
|
+
|
546
|
+
Returns:
|
547
|
+
Expression representing the less than or equal comparison.
|
548
|
+
|
549
|
+
"""
|
550
|
+
return Expression(f"lte({x},{y})")
|
551
|
+
|
552
|
+
|
553
|
+
def max(x: Any, y: Any) -> Expression:
|
554
|
+
"""
|
555
|
+
Return the maximum between x and y.
|
556
|
+
|
557
|
+
Args:
|
558
|
+
x: The first value.
|
559
|
+
y: The second value.
|
560
|
+
|
561
|
+
Returns:
|
562
|
+
Expression representing the maximum value.
|
563
|
+
|
564
|
+
"""
|
565
|
+
return Expression(f"max({x},{y})")
|
566
|
+
|
567
|
+
|
568
|
+
def min(x: Any, y: Any) -> Expression:
|
569
|
+
"""
|
570
|
+
Return the minimum between x and y.
|
571
|
+
|
572
|
+
Args:
|
573
|
+
x: The first value.
|
574
|
+
y: The second value.
|
575
|
+
|
576
|
+
Returns:
|
577
|
+
Expression representing the minimum value.
|
578
|
+
|
579
|
+
"""
|
580
|
+
return Expression(f"min({x},{y})")
|
581
|
+
|
582
|
+
|
583
|
+
def mod(x: Any, y: Any) -> Expression:
|
584
|
+
"""
|
585
|
+
Compute the remainder of division of x by y.
|
586
|
+
|
587
|
+
Args:
|
588
|
+
x: The dividend.
|
589
|
+
y: The divisor.
|
590
|
+
|
591
|
+
Returns:
|
592
|
+
Expression representing the remainder.
|
593
|
+
|
594
|
+
"""
|
595
|
+
return Expression(f"mod({x},{y})")
|
596
|
+
|
597
|
+
|
598
|
+
def not_(expr: Any) -> Expression:
|
599
|
+
"""
|
600
|
+
Return 1.0 if expr is zero, 0.0 otherwise.
|
601
|
+
|
602
|
+
Args:
|
603
|
+
expr: The expression to negate.
|
604
|
+
|
605
|
+
Returns:
|
606
|
+
Expression representing the logical NOT.
|
607
|
+
|
608
|
+
"""
|
609
|
+
return Expression(f"not({expr})")
|
610
|
+
|
611
|
+
|
612
|
+
def pow(x: Any, y: Any) -> Expression:
|
613
|
+
"""
|
614
|
+
Compute the power of x elevated y, it is equivalent to "(x)^(y)".
|
615
|
+
|
616
|
+
Args:
|
617
|
+
x: The base value.
|
618
|
+
y: The exponent.
|
619
|
+
|
620
|
+
Returns:
|
621
|
+
Expression representing the power.
|
622
|
+
|
623
|
+
"""
|
624
|
+
return Expression(f"pow({x},{y})")
|
625
|
+
|
626
|
+
|
627
|
+
def print(t: Any, l: Any | None = None) -> Expression:
|
628
|
+
"""
|
629
|
+
Print the value of expression t with loglevel l. If l is not specified then a default log level is used. Return the value of the expression printed.
|
630
|
+
|
631
|
+
Args:
|
632
|
+
t: The expression to print.
|
633
|
+
l: Optional log level.
|
634
|
+
|
635
|
+
Returns:
|
636
|
+
Expression representing the printed value.
|
637
|
+
|
638
|
+
"""
|
639
|
+
if l is None:
|
640
|
+
return Expression(f"print({t})")
|
641
|
+
else:
|
642
|
+
return Expression(f"print({t},{l})")
|
643
|
+
|
644
|
+
|
645
|
+
def random(idx: Any) -> Expression:
|
646
|
+
"""
|
647
|
+
Return a pseudo random value between 0.0 and 1.0. idx is the index of the internal variable used to save the seed/state, which can be previously stored with st(idx).
|
648
|
+
|
649
|
+
Args:
|
650
|
+
idx: The index of the internal variable for seed/state.
|
651
|
+
|
652
|
+
Returns:
|
653
|
+
Expression representing the random value.
|
654
|
+
|
655
|
+
"""
|
656
|
+
return Expression(f"random({idx})")
|
657
|
+
|
658
|
+
|
659
|
+
def randomi(idx: Any, min: Any, max: Any) -> Expression:
|
660
|
+
"""
|
661
|
+
Return a pseudo random value in the interval between min and max. idx is the index of the internal variable which will be used to save the seed/state, which can be previously stored with st(idx).
|
662
|
+
|
663
|
+
Args:
|
664
|
+
idx: The index of the internal variable for seed/state.
|
665
|
+
min: The minimum value.
|
666
|
+
max: The maximum value.
|
667
|
+
|
668
|
+
Returns:
|
669
|
+
Expression representing the random integer value.
|
670
|
+
|
671
|
+
"""
|
672
|
+
return Expression(f"randomi({idx},{min},{max})")
|
673
|
+
|
674
|
+
|
675
|
+
def root(expr: Any, max: Any) -> Expression:
|
676
|
+
"""
|
677
|
+
Find an input value for which the function represented by expr with argument ld(0) is 0 in the interval 0..max.
|
678
|
+
|
679
|
+
Args:
|
680
|
+
expr: The expression representing the function.
|
681
|
+
max: The maximum value for the interval.
|
682
|
+
|
683
|
+
Returns:
|
684
|
+
Expression representing the root value.
|
685
|
+
|
686
|
+
"""
|
687
|
+
return Expression(f"root({expr},{max})")
|
688
|
+
|
689
|
+
|
690
|
+
def round(expr: Any) -> Expression:
|
691
|
+
"""
|
692
|
+
Round the value of expression expr to the nearest integer. For example, "round(1.5)" is "2.0".
|
693
|
+
|
694
|
+
Args:
|
695
|
+
expr: The expression to round.
|
696
|
+
|
697
|
+
Returns:
|
698
|
+
Expression representing the rounded value.
|
699
|
+
|
700
|
+
"""
|
701
|
+
return Expression(f"round({expr})")
|
702
|
+
|
703
|
+
|
704
|
+
def sgn(x: Any) -> Expression:
|
705
|
+
"""
|
706
|
+
Compute sign of x.
|
707
|
+
|
708
|
+
Args:
|
709
|
+
x: The value to compute sign for.
|
710
|
+
|
711
|
+
Returns:
|
712
|
+
Expression representing the sign.
|
713
|
+
|
714
|
+
"""
|
715
|
+
return Expression(f"sgn({x})")
|
716
|
+
|
717
|
+
|
718
|
+
def sin(x: Any) -> Expression:
|
719
|
+
"""
|
720
|
+
Compute sine of x.
|
721
|
+
|
722
|
+
Args:
|
723
|
+
x: The value to compute sine for.
|
724
|
+
|
725
|
+
Returns:
|
726
|
+
Expression representing the sine.
|
727
|
+
|
728
|
+
"""
|
729
|
+
return Expression(f"sin({x})")
|
730
|
+
|
731
|
+
|
732
|
+
def sinh(x: Any) -> Expression:
|
733
|
+
"""
|
734
|
+
Compute hyperbolic sine of x.
|
735
|
+
|
736
|
+
Args:
|
737
|
+
x: The value to compute hyperbolic sine for.
|
738
|
+
|
739
|
+
Returns:
|
740
|
+
Expression representing the hyperbolic sine.
|
741
|
+
|
742
|
+
"""
|
743
|
+
return Expression(f"sinh({x})")
|
744
|
+
|
745
|
+
|
746
|
+
def sqrt(expr: Any) -> Expression:
|
747
|
+
"""
|
748
|
+
Compute the square root of expr. This is equivalent to "(expr)^.5".
|
749
|
+
|
750
|
+
Args:
|
751
|
+
expr: The expression to compute square root for.
|
752
|
+
|
753
|
+
Returns:
|
754
|
+
Expression representing the square root.
|
755
|
+
|
756
|
+
"""
|
757
|
+
return Expression(f"sqrt({expr})")
|
758
|
+
|
759
|
+
|
760
|
+
def squish(x: Any) -> Expression:
|
761
|
+
"""
|
762
|
+
Compute expression 1/(1 + exp(4*x)).
|
763
|
+
|
764
|
+
Args:
|
765
|
+
x: The value to compute squish function for.
|
766
|
+
|
767
|
+
Returns:
|
768
|
+
Expression representing the squish function.
|
769
|
+
|
770
|
+
"""
|
771
|
+
return Expression(f"squish({x})")
|
772
|
+
|
773
|
+
|
774
|
+
def st(idx: Any, expr: Any) -> Expression:
|
775
|
+
"""
|
776
|
+
Store the value of the expression expr in an internal variable. idx specifies the index of the variable where to store the value, and it is a value ranging from 0 to 9. The function returns the value stored in the internal variable.
|
777
|
+
|
778
|
+
Args:
|
779
|
+
idx: The index of the internal variable (0-9).
|
780
|
+
expr: The expression to store.
|
781
|
+
|
782
|
+
Returns:
|
783
|
+
Expression representing the stored value.
|
784
|
+
|
785
|
+
"""
|
786
|
+
return Expression(f"st({idx},{expr})")
|
787
|
+
|
788
|
+
|
789
|
+
def tan(x: Any) -> Expression:
|
790
|
+
"""
|
791
|
+
Compute tangent of x.
|
792
|
+
|
793
|
+
Args:
|
794
|
+
x: The value to compute tangent for.
|
795
|
+
|
796
|
+
Returns:
|
797
|
+
Expression representing the tangent.
|
798
|
+
|
799
|
+
"""
|
800
|
+
return Expression(f"tan({x})")
|
801
|
+
|
802
|
+
|
803
|
+
def tanh(x: Any) -> Expression:
|
804
|
+
"""
|
805
|
+
Compute hyperbolic tangent of x.
|
806
|
+
|
807
|
+
Args:
|
808
|
+
x: The value to compute hyperbolic tangent for.
|
809
|
+
|
810
|
+
Returns:
|
811
|
+
Expression representing the hyperbolic tangent.
|
812
|
+
|
813
|
+
"""
|
814
|
+
return Expression(f"tanh({x})")
|
815
|
+
|
816
|
+
|
817
|
+
def taylor(expr: Any, x: Any, idx: Any | None = None) -> Expression:
|
818
|
+
"""
|
819
|
+
Evaluate a Taylor series at x, given an expression representing the ld(idx)-th derivative of a function at 0.
|
820
|
+
|
821
|
+
Args:
|
822
|
+
expr: The expression representing the derivative.
|
823
|
+
x: The value to evaluate at.
|
824
|
+
idx: Optional index for the derivative.
|
825
|
+
|
826
|
+
Returns:
|
827
|
+
Expression representing the Taylor series evaluation.
|
828
|
+
|
829
|
+
"""
|
830
|
+
if idx is None:
|
831
|
+
return Expression(f"taylor({expr},{x})")
|
832
|
+
else:
|
833
|
+
return Expression(f"taylor({expr},{x},{idx})")
|
834
|
+
|
835
|
+
|
836
|
+
def time(x: Any) -> Expression:
|
837
|
+
"""
|
838
|
+
Return the current (wallclock) time in seconds.
|
839
|
+
|
840
|
+
Args:
|
841
|
+
x: Unused parameter.
|
842
|
+
|
843
|
+
Returns:
|
844
|
+
Expression representing the current time.
|
845
|
+
|
846
|
+
"""
|
847
|
+
return Expression(f"time({x})")
|
848
|
+
|
849
|
+
|
850
|
+
def trunc(expr: Any) -> Expression:
|
851
|
+
"""
|
852
|
+
Round the value of expression expr towards zero to the nearest integer. For example, "trunc(-1.5)" is "-1.0".
|
853
|
+
|
854
|
+
Args:
|
855
|
+
expr: The expression to truncate.
|
856
|
+
|
857
|
+
Returns:
|
858
|
+
Expression representing the truncated value.
|
859
|
+
|
860
|
+
"""
|
861
|
+
return Expression(f"trunc({expr})")
|
862
|
+
|
863
|
+
|
864
|
+
def while_(cond: Any, expr: Any) -> Expression:
|
865
|
+
"""
|
866
|
+
Evaluate expression expr while the expression cond is non-zero, and returns the value of the last expr evaluation, or NAN if cond was always false.
|
867
|
+
|
868
|
+
Args:
|
869
|
+
cond: The condition to evaluate.
|
870
|
+
expr: The expression to evaluate while condition is true.
|
871
|
+
|
872
|
+
Returns:
|
873
|
+
Expression representing the while loop result.
|
874
|
+
|
875
|
+
"""
|
876
|
+
return Expression(f"while({cond},{expr})")
|
877
|
+
|
878
|
+
|
879
|
+
PI = Expression("PI")
|
880
|
+
"""area of the unit disc, approximately 3.14"""
|
881
|
+
E = Expression("E")
|
882
|
+
"""exp(1) (Euler's number), approximately 2.718"""
|
883
|
+
PHI = Expression("PHI")
|
884
|
+
"""golden ratio (1+sqrt(5))/2, approximately 1.618"""
|