Partial#
- class brainpy.math.Partial(fun, *args, child_objs=None, dyn_vars=None, **keywords)[source]#
A picklable, object-aware partial application of a function.
Partialbehaves likefunctools.partial(): it binds positional and keyword arguments tofunso that the remaining arguments can be supplied later when the instance is called. Unlikefunctools.partial(), it is aBrainPyObject, so anyVariableinstances and childBrainPyObjectobjects used byfunare registered and tracked.- Parameters:
fun (
Callable) – The function to be partially applied.*args (
Any) – Positional arguments bound ahead of the call-time positional arguments.child_objs (
Union[Callable,BrainPyObject,Sequence[BrainPyObject],Dict[str,BrainPyObject]]) – The children objects used infun.dyn_vars (
Union[Variable,Sequence[Variable],Dict[str,Variable]]) – TheVariableinstances used infun.**keywords (
Any) – Keyword arguments bound tofun. Keywords supplied at call time take precedence over those bound here.
See also
to_objectTransform a Python function into a
BrainPyObject.
Examples
>>> import brainpy.math as bm >>> add = bm.Partial(lambda x, y: x + y, 1) >>> add(2) 3