math_spec.dimensions
Static dim-set checking — a type system whose type is a set of dim names.
Parameter dims are declared, variable foreach is declared, and operator
dimension arguments are name-checked, so every node's dim set is computable
before any data is bound. That is the whole basis of this pass: it runs at
load time, on the resolved core AST, so both lanes get the same answer by
construction rather than by differential test.
The rules::
number -> no dims
parameter p -> its declared dims
variable v -> its foreach
-x, +x -> same dims as x
a + b, a * b, a / b -> every dim either side carries (set union)
sum(x, over=d) -> x's dims without d; error if x has no d
sum(x, by=l) -> x's dims without the dim l is over, plus the
dim l maps into; error if x has no such dim
sum(x, by=[l, m]) -> the same, with every target at once; l and m
must be over one dim and target different ones
at(x, by=l) -> the reverse: x's dims without l's target(s),
plus the dim l is over
shift(x, over=d, offset=n) -> same dims as x; error if x has no d
sum_back(x, over=d, within=n) -> same dims as x; error if x has no d
and at the declaration level::
constraint -> the dims of both sides together must *equal* foreach
where -> the predicate's dims must not exceed the frame
bounds -> the bound parameter's dims must not exceed foreach
The direction that matters most is the stray dim: one the frame does not declare broadcasts silently in the eager lane and adds coordinate columns in the relational one, so the same YAML quietly builds a bigger model than it reads as. The missing direction is checked too, a foreach dim the equation never uses just repeating one row across it — nearly always a typo.
check_schema(schema)
#
Check every declaration's dim rules.
| RAISES | DESCRIPTION |
|---|---|
DimensionError
|
On the first declaration that breaks one. |
Source code in src/math_spec/dimensions.py
dims_of(node, schema, context)
#
The dim set of a resolved expression, checking every rule on the way.
| RAISES | DESCRIPTION |
|---|---|
DimensionError
|
On the first rule broken. |