FilterLiteral

Contents

FilterLiteral#

brainstate.typing.FilterLiteral#

Basic filter types that can be used to select parts of a PyTree.

Components#

type

Filter by type, e.g., float, jax.Array.

str

Filter by tag: matches objects whose tag attribute equals the string (converted to a WithTag filter), not by path-key matching.

Predicate

Custom function for complex filtering logic.

bool

Simple True/False filter.

Ellipsis

Wildcard filter that matches anything.

None

Filter that matches None values.

Examples

>>> # Filter by type
>>> float_filter: FilterLiteral = float
>>>
>>> # Filter by tag (matches objects whose ``tag`` attribute == "weight")
>>> weight_filter: FilterLiteral = "weight"
>>>
>>> # Custom predicate filter
>>> matrix_filter: FilterLiteral = lambda path, x: hasattr(x, 'ndim') and x.ndim == 2