ComposableTransform¶
-
class
menpo.transform.base.composable.
ComposableTransform
[source]¶ Bases:
Transform
Transform
subclass that enables native composition, such that the behavior of multipleTransform
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 beforeself
-
_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 afterself
-
apply
(x, **kwargs)¶ Applies this transform to
x
.If
x
isTransformable
,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- x (
-
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
) – TheTransformable
object to be transformed. - kwargs (dict) – Passed through to
_apply()
.
Returns: transformed (
type(x)
) – The transformed object- x (
-
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
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
orTransformChain
) – Transform to be applied beforeself
- Returns –
- -------- –
- transform – If the composition was native, a single new
Transform
will be returned. If not, aTransformChain
is returned instead.
- transform (
-
compose_after_inplace
(transform)[source]¶ 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)[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
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
orTransformChain
) – Transform to be applied afterself
- Returns –
- -------- –
- transform – If the composition was native, a single new
Transform
will be returned. If not, aTransformChain
is returned instead.
- transform (
-
compose_before_inplace
(transform)[source]¶ 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
-