Any#
- class brainstate.util.Any(*filters)[source]#
Combine multiple filters using logical OR operation.
This filter returns True if any of its constituent filters return True. It’s useful for creating flexible filtering criteria where multiple conditions can be satisfied.
- Parameters:
*filters (
type|str|Callable[[Tuple[Key,...],Any],bool] |bool|EllipsisType|None|Tuple[type|str|Callable[[Tuple[Key,...],Any],bool] |bool|EllipsisType|None|Tuple[Filter,...] |List[Filter],...] |List[type|str|Callable[[Tuple[Key,...],Any],bool] |bool|EllipsisType|None|Tuple[Filter,...] |List[Filter]]) – Variable number of filters to be combined with OR logic.
Examples
>>> from brainstate.util.filter import Any, WithTag, OfType >>> import numpy as np >>> >>> # Create a filter that matches either tag >>> trainable_or_frozen = Any('trainable', 'frozen') >>> >>> # Test with objects >>> class Param: ... def __init__(self, tag): ... self.tag = tag >>> >>> trainable = Param('trainable') >>> frozen = Param('frozen') >>> other = Param('other') >>> >>> trainable_or_frozen([], trainable) True >>> trainable_or_frozen([], frozen) True >>> trainable_or_frozen([], other) False >>> >>> # Combine different filter types >>> array_or_list = Any( ... OfType(np.ndarray), ... OfType(list) ... ) >>> >>> array_or_list([], np.array([1, 2, 3])) True >>> array_or_list([], [1, 2, 3]) True >>> array_or_list([], (1, 2, 3)) False
See also
AllLogical AND combination of filters
NotLogical negation of a filter
to_predicateConvert various inputs to predicates
Notes
The Any filter short-circuits evaluation, returning True as soon as one of its constituent filters returns True.