boundlab.utils#

Shared utilities: shape metadata, einsum plumbing, polynomials, formatting.

Module Attributes

Dim

A tensor dimension: a plain int or a symbolic size.

Functions

all_same

Whether every element equals the first (vacuously true when empty).

all_unique

Whether no element repeats.

cast

Runtime-checked cast: dies (via beartype) if value is not a ty.

einsum_formatter

Format input tuples followed by one output tuple as an einsum string.

einsum_parser

Parse an einsum string into input tuples followed by one output tuple.

format_bytes

Format a byte count as a human-readable string (e.g. 1.5MiB).

is_statically_zero

Return whether a concrete scalar/tensor contains only zeros.

same_shape

Whether two shapes agree, comparing symbolic dimensions by string.

sum

Sum with + and no zero start, so expression types keep their own __add__ semantics; raises on an empty iterable.

unwarp

Assert an Optional is present and return it.

unzip

Transpose an iterable of equal-length tuples into per-slot lists.

Classes

Dim

A tensor dimension: a plain int or a symbolic size.

Polynomial

Dense univariate polynomial \(P(x) = \sum_k c_k x^k\).

ShapeDtype

Allocation-free shape and dtype metadata for an abstract expression.

TensorFormat

A format string plus the traced arrays that fill its placeholders.

TyDict

Dictionary whose values are indexed by their concrete types.