TransformChain¶

class
menpo.transform.
TransformChain
(transforms)[source]¶ Bases:
ComposableTransform
A chain of transforms that can be efficiently applied one after the other.
This class is the natural product of composition. Note that objects may know how to compose themselves more efficiently  such objects implement the
ComposableTransform
orVComposable
interfaces.Parameters: transforms (list of Transform
) – The list of transforms to be applied. Note that the first transform will be applied first  the result of which is fed into the second transform and so on until the chain is exhausted.
apply
(x, batch_size=None, **kwargs)¶ Applies this transform to
x
.If
x
isTransformable
,x
will be handed this transform object to transform itself nondestructively (a transformed copy of the object will be returned).If not,
x
is assumed to be an ndarray. The transformation will be nondestructive, 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.  batch_size (int, optional) – If not
None
, this determines how many items from the numpy array will be passed through the transform at a time. This is useful for operations that require large intermediate matrices to be computed.  kwargs (dict) – Passed through to
_apply()
.
Returns: transformed (
type(x)
) – The transformed object or array x (

apply_inplace
(*args, **kwargs)¶ Deprecated as public supported API, use the nonmutating apply() instead.
For internal performancespecific uses, see _apply_inplace().

compose_after
(transform)¶ 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
andb
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. Seecomposes_with
for a description of how the mode of composition is decided.Parameters: transform ( Transform
) – Transform to be applied beforeself
Returns: transform ( Transform
orTransformChain
) – If the composition was native, a single newTransform
will be returned. If not, aTransformChain
is returned instead.

compose_after_inplace
(transform)¶ Update
self
so that it represents this transform composed after the given transform:a_orig = a.copy() 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 beforeself
Raises: ValueError
– Iftransform
isn’t an instance ofcomposes_inplace_with

compose_before
(transform)¶ 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
andb
are left unchanged.An attempt is made to perform native composition, but will fall back to a
TransformChain
as a last resort. Seecomposes_with
for a description of how the mode of composition is decided.Parameters: transform ( Transform
) – Transform to be applied afterself
Returns: transform ( Transform
orTransformChain
) – If the composition was native, a single newTransform
will be returned. If not, aTransformChain
is returned instead.

compose_before_inplace
(transform)¶ Update
self
so that it represents this transform composed before the given transform:a_orig = a.copy() 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 afterself
Raises: ValueError
– Iftransform
isn’t an instance ofcomposes_inplace_with

copy
()¶ Generate an efficient copy of this object.
Note that Numpy arrays and other
Copyable
objects onself
will be deeply copied. Dictionaries and sets will be shallow copied, and everything else will be assigned (no copy will be made).Classes that store state other than numpy arrays and immutable types should overwrite this method to ensure all state is copied.
Returns: type(self)
– A copy of this object

composes_inplace_with
¶ The
Transform
s that this transform composes inplace with natively (i.e. noTransformChain
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 ofTransform
s

composes_with
¶ The
Transform
s that this transform composes with natively (i.e. noTransformChain
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 ofTransform
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
