from brian2 import Function)
Function(pyfunc, sympy_func=None, arg_units=None, return_unit=None, stateless=True)¶
An abstract specification of a function that can be used as part of model equations, etc.
pyfunc : function
A Python function that is represented by this
A corresponding sympy function (if any). Allows functions to be interpreted by sympy and potentially make simplifications. For example,
sqrt(x**2)could be replaced by
arg_units : list of
pyfuncdoes not provide unit information (which typically means that it was not annotated with a
check_units()decorator), the units of the arguments have to specified explicitly using this parameter.
Unitor callable, optional
Same as for
pyfuncdoes not provide unit information, this information has to be provided explictly here.
return_unitcan either be a specific
Unit, if the function always returns the same unit, or a function of the input units, e.g. a “square” function would return the square of its input units, i.e.
return_unitcould be specified as
lambda u: u**2.
stateless : bool, optional
Whether this function does not have an internal state, i.e. if it always returns the same output when called with the same arguments. This is true for mathematical functions but not true for
rand(), for example. Defaults to
If a function should be usable for code generation targets other than Python/numpy, implementations for these target languages have to be added using the
implementationdecorator or using the
Stores implementations for this function in a
Return whether this function (if interpreted as a function of time) should be considered constant over a timestep.
Return whether this function (if interpreted as a function of time) should be considered constant over a timestep. This is most importantly used by
TimedArrayso that linear integration can be used. In its standard implementation, always returns
dt : float
The length of a timestep (without units).
constant : bool
Whether the results of this function can be considered constant over one timestep of length