You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: book/src/functions.md
+28Lines changed: 28 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,6 +20,7 @@ The DiffSL supports the following mathematical functions that can be used in an
20
20
*`abs(x)` - absolute value of x
21
21
*`sigmoid(x)` - sigmoid function of x
22
22
*`heaviside(x)` - Heaviside step function of x
23
+
*`interp1d(x_i, y_i, q)` - 1D piecewise linear interpolation
23
24
24
25
You can use these functions as part of an expression in the DSL. For example, to define a variable `a` that is the sine of another variable `b`, you can write:
25
26
@@ -28,6 +29,33 @@ b { 1.0 }
28
29
a { sin(b) }
29
30
```
30
31
32
+
### `interp1d(x_i, y_i, q)`
33
+
34
+
The `interp1d` function performs 1D piecewise linear interpolation. `x_i` and `y_i`
35
+
must be compile-time constant 1D dense tensors of equal length. The query point
36
+
`q` can be a scalar or a tensor. Out-of-range queries are clamped to the
37
+
endpoints.
38
+
39
+
`x_i` must be **strictly increasing**; an error is reported at compile time if
40
+
it is not.
41
+
42
+
If `x_i` is uniformly spaced (constant increment `dx` between consecutive values),
43
+
the interpolation runs in **O(1)** per query point. For non-uniform `x_i`, a
44
+
binary search is used, giving **O(log n)** cost per query point.
# the first two arguments may be any constant 1D dense expression
56
+
r { interp1d(xs_i * 2.0, ys_i + 1.0, 5.0) }
57
+
```
58
+
31
59
## Pre-defined variables
32
60
33
61
There are two predefined variables in DiffSL. The first is the scalar `t` which is the current time, this allows the equations to be written as functions of time. For example
0 commit comments