Abstract Helpers

autoform.extend.avalof(x, /)[source]

Return the abstract value for a traceable leaf.

avalof applies the registered aval rule for type(x). It is the concrete-to-abstract direction used by autoform.trace(), zeros, and extension code that needs to inspect a value domain.

Parameters:

x – Concrete value, symbolic zero, or IR value with a registered aval rule.

Returns:

The abstract value for x.

Raises:

TypeError – If no aval rule is registered for type(x).

Return type:

AVal

autoform.extend.zeroof(v, /)[source]

Return a symbolic zero with the same aval as v.

If v is already a symbolic zero, it is returned unchanged.

Parameters:

v – Concrete value, IR value, or symbolic zero.

Returns:

A Zero carrying avalof(v).

Return type:

Zero

autoform.extend.materialize(x, /)[source]

Replace each Zero leaf in a pytree with its concrete zero value.

materialize is useful inside transform rules before calling primitives that expect real runtime values instead of symbolic zeros.

Parameters:

x (Tree) – Pytree that may contain Zero leaves.

Returns:

A pytree with the same structure as x where each symbolic zero has been replaced by its registered concrete zero value.

Raises:

TypeError – If a Zero has a type with no registered concrete zero (e.g. Zero(BoolAVal())). This indicates an invalid gradient path through a non-differentiable type.

Return type:

Tree

autoform.extend.is_zero(x, /)[source]

Return whether the input is a symbolic zero cotangent.

This is intended for rule implementations that need to preserve symbolic zeros instead of treating them as ordinary values.

Return type:

TypeGuard[Zero]