ComposableTransform

class menpo.transform.base.composable.ComposableTransform[source]

Bases: Transform

Transform subclass that enables native composition, such that the behavior of multiple Transform s is composed together in a natural way.

_compose_after_inplace(transform)[source]

Specialised inplace composition. This should be overridden to provide specific cases of composition as defined in composes_inplace_with.

Parameters:

transform : composes_inplace_with

Transform to be applied before self

_compose_before_inplace(transform)[source]

Specialised inplace composition. This should be overridden to provide specific cases of composition as defined in composes_inplace_with.

Parameters:

transform : composes_inplace_with

Transform to be applied after self

apply(x, **kwargs)

Applies this transform to x.

If x is Transformable, x will be handed this transform object to transform itself non-destructively (a transformed copy of the object will be returned).

If not, x is assumed to be an ndarray. The transformation will be non-destructive, returning the transformed version.

Any kwargs will be passed to the specific transform _apply() method.

Parameters:

x : Transformable or (n_points, n_dims) ndarray

The array or object to be transformed.

kwargs : dict

Passed through to _apply().

Returns:

transformed : type(x)

The transformed object or array

apply_inplace(x, **kwargs)

Applies this transform to a Transformable x destructively.

Any kwargs will be passed to the specific transform _apply() method.

Parameters:

x : Transformable

The Transformable object to be transformed.

kwargs : dict

Passed through to _apply().

Returns:

transformed : type(x)

The transformed object

compose_after(transform)[source]

A Transform that represents this transform composed after the given transform:

c = a.compose_after(b)
c.apply(p) == a.apply(b.apply(p))

a and b are left unchanged.

This corresponds to the usual mathematical formalism for the compose operator, o.

An attempt is made to perform native composition, but will fall back to a TransformChain as a last resort. See composes_with for a description of how the mode of composition is decided.

Parameters:

transform : Transform

Transform to be applied before self

Returns:

transform : Transform or TransformChain

If the composition was native, a single new Transform will be returned. If not, a TransformChain is returned instead.

compose_after_inplace(transform)[source]

Update self so that it represents this transform composed after the given transform:

a_orig = deepcopy(a)
a.compose_after_inplace(b)
a.apply(p) == a_orig.apply(b.apply(p))

a is permanently altered to be the result of the composition. b is left unchanged.

Parameters:

transform : composes_inplace_with

Transform to be applied before self

Raises:

ValueError :

If transform isn’t an instance of composes_inplace_with

compose_before(transform)[source]

A Transform that represents this transform composed before the given transform:

c = a.compose_before(b)
c.apply(p) == b.apply(a.apply(p))

a and b are left unchanged.

An attempt is made to perform native composition, but will fall back to a TransformChain as a last resort. See composes_with for a description of how the mode of composition is decided.

Parameters:

transform : Transform

Transform to be applied after self

Returns:

transform : Transform or TransformChain

If the composition was native, a single new Transform will be returned. If not, a TransformChain is returned instead.

compose_before_inplace(transform)[source]

Update self so that it represents this transform composed before the given transform:

a_orig = deepcopy(a)
a.compose_before_inplace(b)
a.apply(p) == b.apply(a_orig.apply(p))

a is permanently altered to be the result of the composition. b is left unchanged.

Parameters:

transform : composes_inplace_with

Transform to be applied after self

Raises:

ValueError :

If transform isn’t an instance of composes_inplace_with

composes_inplace_with[source]

The Transform s that this transform composes inplace with natively (i.e. no TransformChain will be produced).

An attempt to compose inplace against any type that is not an instance of this property on this class will result in an Exception.

Type:Transform or tuple of Transform s
composes_with[source]

The Transform s that this transform composes with natively (i.e. no TransformChain will be produced).

If native composition is not possible, falls back to producing a TransformChain.

By default, this is the same list as composes_inplace_with.

Type:Transform or tuple of Transform s
n_dims

The dimensionality of the data the transform operates on.

None if the transform is not dimension specific.

Type:int or None
n_dims_output

The output of the data from the transform.

None if the output of the transform is not dimension specific.

Type:int or None