>>> # the first two arguments are required and the last two are
outputs = x + y + z)
>>> # optional and initialized to 42 and 0, respectively.
# the first two arguments are required and the last two are
>>> # The last argument, w, is updated with w + x each time the
# optional and initialized to 42 and 0, respectively.
>>> # function is called.
# The last argument, w, is updated with w + x each time the
# function is called.
>>> fn(1) # illegal because there are two required arguments # doctest: +ELLIPSIS
Traceback (most recent call last):
fn(1) # illegal because there are two required arguments
...
fn(1, 2) # legal, z is 42, w goes 0 -> 1 (because w <- w + x), returns array(45.0)
TypeError: Missing required input: y
fn(1, y = 2) # legal, z is 42, w goes 1 -> 2, returns array(45.0)
>>> fn(1, 2) # legal, z is 42, w goes 0 -> 1 (because w <- w + x)
fn(x = 1, y = 2) # illegal because x was not named
array(45.0)
fn(1, 2, 3) # legal, z is 3, w goes 2 -> 3, returns array(6.0)
>>> fn(1, y=2) # legal, z is 42, w goes 1 -> 2
fn(1, z = 3, y = 2) # legal, z is 3, w goes 3 -> 4, returns array(6.0)
array(45.0)
fn(1, 2, w = 400) # legal, z is 42 again, w goes 400 -> 401, returns array(45.0)
>>> fn(x=1, y=2) # illegal because x was not named # doctest: +ELLIPSIS
fn(1, 2) # legal, z is 42, w goes 401 -> 402, returns array(45.0)
Traceback (most recent call last):
...
TypeError: Unknown input or state: x. The function has 3 named inputs (y, z, w), and 1 unnamed input which thus cannot be accessed through keyword argument (use 'name=...' in a variable's constructor to give it a name).
>>> fn(1, 2, 3) # legal, z is 3, w goes 2 -> 3
array(6.0)
>>> fn(1, z=3, y=2) # legal, z is 3, w goes 3 -> 4
array(6.0)
>>> fn(1, 2, w=400) # legal, z is 42 again, w goes 400 -> 401
array(45.0)
>>> fn(1, 2) # legal, z is 42, w goes 401 -> 402
array(45.0)
In the example above, ``z`` has value 42 when no value is explicitly given.
In the example above, ``z`` has value 42 when no value is explicitly given.
This default value is potentially used at every function invocation, because
This default value is potentially used at every function invocation, because
...
@@ -285,20 +306,25 @@ If a single ``Variable`` or ``Out`` instance is given as argument, then the comp
...
@@ -285,20 +306,25 @@ If a single ``Variable`` or ``Out`` instance is given as argument, then the comp
If a list of ``Variable`` or ``Out`` instances is given as argument, then the compiled function will return a list of their values.
If a list of ``Variable`` or ``Out`` instances is given as argument, then the compiled function will return a list of their values.