Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

05: Value domains and dtypes

E0501

Value isn’t in the expected domain. A value doesn’t fit where it’s used: a range not contained in the expected one, a Prob where logits are expected, a Mask where numbers are expected or the other way round, and so on. The help suggests to T when a conversion exists and as T otherwise.

fn f(x: [n]) -> [n] Unit = x * 2

See Widening, Semantic domains and Discrete domains.

E0502

Wrong dtype. An argument or returned value is stored in a different dtype than expected, or the operands of @, matmul, einsum or scatter have different dtypes. Convert with to, as in to f32.

fn f(x: [n D] bf16, w: [D D]) = x @ w

See Dtypes.

E0503

Invalid domain. Logit, Prob or LogProb without over, or over an axis the type doesn’t have, or in a type without a shape where none can be found; over or a size on a domain that doesn’t take one; Index without a size; a domain and dtype that don’t go together, such as Mask f32; a domain declaration with a reserved name, ends that aren’t numbers, or no values.

fn f(x: [b C] Prob) = x

See Built-in domains and User domains.

E0504

to conversion that doesn’t exist. to only makes the conversions in its table, and the note lists them. Converting to the domain a value already has, converting semantic or discrete domains by their values’ range, and converting to bool are errors too.

fn f(x: [n]) = softmax(x, over=n) to Signed

See The to table and Converting dtypes.

E0505

Arithmetic on a mask. + - * / @ and unary - take numbers, and a Mask holds booleans. Convert it: to Additive to add it to scores, to Binary for 0 and 1; use ! to negate it and and or or to combine masks.

fn f(x: [n m], keep: [n m] Mask) = x + keep

See Discrete domains.

E0506

Function applied outside its domain. log, log1p, sqrt, rsqrt or a division gets values that are past where the function is defined, or a divisor that is exactly 0.

fn f(s: [n] Signed) = log(s)

See Function edges.

E0507

Indices for an axis of a different size. Index[V] values index an axis whose size isn’t V: in emb[ids], a call, gather, cross_entropy targets, or a return type.

dim V = 100
dim V2 = 50

fn f(emb: [V 8], ids: [t] Index[V2]) = emb[ids]

See Discrete domains and Indexing.

W0501

Value can be exactly where a function is undefined. The range of the argument of log, log1p or rsqrt, or of a divisor, reaches the function’s edge: log of values that can be 0, or a division by values that can be 0. The help suggests a stable alternative where there is one, such as log_sigmoid(x) for log(sigmoid(x)), or as Pos if the value is never 0.

fn f(x: [n]) = log(sigmoid(x))

See Function edges.