Built-in functions#
46 functions. Zero vendor math.
.vis 0.1 has 46 built-in functions. All of them are Vision’s own, with the same result on every GPU and on the numpy reference; none calls the vendor’s math library.
Precision is the maximum error against the exact result computed in float64, in units in the last place (ULP), for results between 2⁻¹²⁵ and half the largest float. (sample): measured on 1 in every 101 inputs (42 million per function); the others on all 4 294 967 296 inputs.
Outside its domain a function returns the value at the edge of the domain, and an overflow gives ±MAX (±3.4028235e38): every value is finite. Every example below is computed by Vision in the tests.
Exponentials and logarithms#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
eˣ |
0.99 ULP |
|
|
2ˣ |
1.19 ULP (sample) |
|
|
eˣ − 1, accurate near 0 |
3.31 ULP (sample) |
|
|
natural logarithm |
0.83 ULP |
|
|
base-2 logarithm, exact on powers of 2 |
1.31 ULP (sample) |
|
|
base-10 logarithm |
1.68 ULP (sample) |
|
|
ln(1 + x), accurate near 0 |
2.79 ULP (sample) |
|
|
aᵇ (also written a ^ b) |
2.13–2.48 ULP (sample) |
|
log. log of 0 or of a negative number is −MAX.
pow. A negative base works with an integer-valued exponent; with any other exponent the result is 0. x ^ n with an integer literal n up to 16 is an exact product and keeps the type of x.
Roots#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
√x |
0.75 ULP |
|
|
∛x, defined for negative numbers |
0.92 ULP (sample) |
|
|
√(a² + b²) without premature overflow |
2.39 ULP (sample) |
|
Trigonometric#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
sine, accurate for every float32 argument |
1.59 ULP |
|
|
cosine |
1.58 ULP |
|
|
tangent |
3.24 ULP |
|
|
arcsine |
2.08 ULP (sample) |
|
|
arccosine |
1.33 ULP (sample) |
|
|
arctangent |
1.75 ULP |
|
|
the angle of the point (x, y) |
1.94 ULP |
|
Hyperbolic#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
hyperbolic sine |
1.66 ULP (sample) |
|
|
hyperbolic cosine |
1.66 ULP (sample) |
|
|
hyperbolic tangent |
1.62 ULP |
|
|
inverse hyperbolic sine |
4.14 ULP (sample) |
|
|
inverse hyperbolic cosine |
2.21 ULP (sample) |
|
|
inverse hyperbolic tangent |
1.58 ULP (sample) |
|
Probability and random numbers#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
error function |
2.40 ULP (sample) |
|
|
1 − erf(x), accurate in the tail |
4.62 ULP (sample) |
|
|
cumulative standard normal distribution |
4.60 ULP (sample) |
|
|
a uniform pseudo-random number in [0, 1) from three integers; the same arguments always give the same number |
exact |
|
rand. rand has no hidden state: for a new draw at every step, pass a step counter (an i32 channel) as an argument. Not rand(x, y, 7) in a kernel run 100 times but rand(x, y, clock) with clock += 1 in the kernel: the same arguments give the same number at every step.
Rounding#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
the largest integer ≤ x |
exact |
|
|
the smallest integer ≥ x |
exact |
|
|
the nearest integer, ties to even |
exact |
|
|
the integer part |
exact |
|
|
x − floor(x) |
exact |
|
Comparison and blending#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
absolute value; keeps int |
exact |
|
|
−1, 0 or 1; keeps int |
exact |
|
|
the smaller of two numbers; int when both are |
exact |
|
|
the larger of two numbers; int when both are |
exact |
|
|
min(max(v, lo), hi) |
exact |
|
|
a·(1 − t) + b·t |
exact |
|
|
1 if edge ≤ v, else 0 |
exact |
|
|
a smooth Hermite step from 0 to 1 |
exact |
|
|
a where cond is true, b elsewhere |
exact |
|
min. Inside a kernel min and max take two numbers; the minimum over a whole canvas is a measure. Not min(t) in a kernel but measure lowest = min(t) on c: the reduction over the canvas is a measure.
select. cond is a condition: to test a number, compare it. Not select(n, 1, 0) but select(n == 1, 1, 0): the first argument is true or false, not a number.
Conversion and integer transfers#
Function |
Meaning |
Precision |
Examples |
|---|---|---|---|
|
the value as a float; true is 1 and false is 0 |
exact |
|
|
the value as an int, truncating towards zero and saturating |
exact |
|
|
d / 2^s rounded half away from zero, s from 0 to 30; flux(-d, s) = -flux(d, s), so what a cell gives a neighbour is exactly what the neighbour receives and integer totals are conserved |
exact |
|
|
the integer r·65536 + g·256 + b: the value a colour pixel of a PNG loads as |
exact |
|
Reductions#
sum, mean, min, max and count reduce a whole canvas; they appear only in a measure (see Vocabulary). Inside a kernel, min and max are the two-argument functions above.