spekk.transformations.apply.Apply#

class spekk.transformations.apply.Apply(f: Callable, *args, **kwargs)[source]#

Bases: Transformation

Transform a function such that f is applied to the output of it.

f#

The function to apply to the result of the wrapped function.

args#

Optional extra positional arguments to pass to f.

kwargs#

Optional extra keyword arguments to pass to f.

__init__(f: Callable, *args, **kwargs)[source]#

Methods

__init__(f, *args, **kwargs)

transform_function(to_be_transformed, ...)

Transform the wrapped function given the spec of the input arguments and the spec of the returned value of the wrapped function.

transform_input_spec(spec)

Return a new spec that represent the input arguments that are passed down to the wrapped function after the transformation has been applied.

transform_output_spec(spec)

Return a new spec that represent the returned value of the final transformed function.

with_extra_output_spec_transform(t)

transform_function(to_be_transformed: callable, input_spec: Spec, output_spec: Spec) callable[source]#

Transform the wrapped function given the spec of the input arguments and the spec of the returned value of the wrapped function.

transform_input_spec(spec: Spec) Spec[source]#

Return a new spec that represent the input arguments that are passed down to the wrapped function after the transformation has been applied.

For example, if the transformation vectorizes the wrapped function over a dimension, the wrapped function would only see single items of the dimension at a time. Therefore, the input spec will have one less dimension when passed down to the wrapped function.

transform_output_spec(spec: Spec) Spec[source]#

Return a new spec that represent the returned value of the final transformed function.

For example, if the transformation sums over a dimension of the result of calling the wrapped function, the output spec will have one less dimension.