shapecheck#
Utilities for runtime shape-checking.
Penzai is highly dynamic by nature, and is heavily based on having nested tree structured objects, which is difficult to capture with Python’s type annotations. This module provides a shape-and-structure checking utility that can be used to check the shapes and dtypes of nested structures while also simultaneously extracting parts that the program may need to use (e.g. lengths for axes).
Classes
A non-leaf marker for a (named) array structure. |
|
A dimension variable, which will be matched with the shapes in a structure. |
|
A substitution for all of the dimension variables in a structure. |
|
A dimension with a known value, used to bind a name to a value directly. |
|
The result of a successful shape check. |
|
A variable standing in for a sequence or dictionary axis names. |
|
Sentinel marker for the remainder of axes. |
|
Wildcard marker that matches any value or subtree of a PyTree. |
Functions
|
Abstracts a concrete tree of values into a tree of |
|
Checks that a structure of values matches a pattern. |
Substitutes all dimension variables for their known values. |
|
|
Returns a collection of all dimension variables in a structure. |
|
Creates a variable for an axis shape. |
|
Creates variables for a known collection of named axes. |
Exceptions
Raised when a |