spekk.transformations.base.PartialTransformation#

class spekk.transformations.base.PartialTransformation(partial_transformations: Sequence[Transformation])[source]#

Bases: Transformation

A partially applied transformation.

PartialTransformation lets us compose transformations such that they can be re-used as building blocks. For example, in the below code, tf_partial and tf_full are equivalent:

>>> import numpy as np
>>> from spekk.transformations import ForAll, compose

Let’s create an example kernel function along with some data and a spec:

>>> kernel = lambda x: x**2
>>> data = {"x": np.ones((2, 3)) * 2}
>>> spec = Spec({"x": ["a", "b"]})

Create a partial transformation by composing two transformations:

>>> forall_xy = compose(ForAll("a"), ForAll("b"))

Create and build two equivalent transformed functions:

>>> tf_partial = compose(kernel, forall_xy).build(spec)
>>> tf_full = compose(kernel, ForAll("a"), ForAll("b")).build(spec)

The two transformed functions are equivalent:

>>> np.array_equal(tf_partial(**data), tf_full(**data))
True
__init__(partial_transformations: Sequence[Transformation]) None#

Methods

__init__(partial_transformations)

transform_function(wrapped_fn, input_spec, ...)

Transform the wrapped function by applying each partial transformation in turn.

transform_input_spec(spec)

Transform the input spec using each partial transformation in turn.

transform_output_spec(spec)

Transform the output spec using each partial transformation in turn.

Attributes

partial_transformations

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

Transform the wrapped function by applying each partial transformation in turn.

transform_input_spec(spec: Spec) Spec[source]#

Transform the input spec using each partial transformation in turn.

transform_output_spec(spec: Spec) Spec[source]#

Transform the output spec using each partial transformation in turn.