Skip to content

chacana.checker

Static type checker for tensor expressions.

chacana.checker

Static type checker for Chacana AST.

Rules 1 (contraction), 2 (free index invariance), 3 (symmetry validity).

check(token: ValidationToken, ctx: GlobalContext | None = None) -> ValidationToken

Run all type checks on a ValidationToken. Returns the token if valid.

Source code in src/chacana/checker.py
def check(token: ValidationToken, ctx: GlobalContext | None = None) -> ValidationToken:
    """Run all type checks on a ValidationToken. Returns the token if valid."""
    _check_contraction(token, ctx)
    _check_free_index_invariance(token, ctx)
    _check_symmetry(token, ctx)
    if ctx is not None:
        _check_rank(token, ctx)
        _check_operators(token, ctx)
    return token