transformseq¶
The transformseq module.

class
nutils.transformseq.
Transforms
(fromdims)¶ Bases:
nutils.types.Singleton
Abstract base class for a sequence of
TransformItem
tuples.This class resembles to some extent a plain
tuple
: the class supports indexing, iterating and has anindex()
method. In addition the class supports theindex_with_tail()
method which can be used to find the index of a transform given the transform plus any number of child transformations.The transforms in this sequence must satisfy the following condition: any transform must not start with any other transform in the same sequence.
 Parameters
fromdims (
int
) – The number of dimensions all transforms in this sequence map from.
Notes
Subclasses must implement
__getitem__()
,__len__()
andindex_with_tail()
.
abstract
__len__
(self)¶ Return
len(self)
.

__getitem__
(self, index)¶ Return
self[index]
.

abstract
index_with_tail
(self, trans)¶ Return the index of
trans[:n]
and the tailtrans[n:]
.Find the index of a transform in this sequence given the transform plus any number of child transforms. In other words: find
index
such thatself[index] == trans[:n]
for somen
. Note that there is either exactly oneindex
satisfying this condition, or none, due to the restrictions of the transforms in aTransforms
object. Parameters
trans (
tuple
ofnutils.transform.TransformItem
objects) – The transform to find up to a possibly empty tail. Returns
index (
int
) – The index oftrans
without tail in this sequence.tail (
tuple
ofnutils.transform.TransformItem
objects) – The tail:trans[len(self[index]):]
.
 Raises
ValueError – if
trans
is not found.
Example
Consider the following plain sequence of two shift transforms:
>>> from nutils.transform import Shift, Scale >>> transforms = PlainTransforms([(Shift([0.]),), (Shift([1.]),)], fromdims=1)
Calling
index_with_tail()
with the first transform gives index0
and no tail:>>> transforms.index_with_tail((Shift([0.]),)) (0, ())
Calling with an additional scale gives:
>>> transforms.index_with_tail((Shift([0.]), Scale(0.5, [0.]))) (0, (Scale([0]+0.5*x),))

__iter__
(self)¶ Implement
iter(self)
.

index
(self, trans)¶ Return the index of
trans
. Parameters
trans (
tuple
ofnutils.transform.TransformItem
objects) – Returns
index – The index of
trans
in this sequence. Return type
 Raises
ValueError – if
trans
is not found.
Example
Consider the following plain sequence of two shift transforms:
>>> from nutils.transform import Shift, Scale >>> transforms = PlainTransforms([(Shift([0.]),), (Shift([1.]),)], fromdims=1)
Calling
index()
with the first transform gives index0
:>>> transforms.index((Shift([0.]),)) 0
Calling with an additional scale raises an exception, because the transform is not present in
transforms
.>>> transforms.index((Shift([0.]), Scale(0.5, [0.]))) Traceback (most recent call last): ... ValueError: (Shift([0]+x), Scale([0]+0.5*x)) not in sequence of transforms

contains
(self, trans)¶ Return
trans
inself
. Parameters
trans (
tuple
ofnutils.transform.TransformItem
objects) – Returns
True
iftrans
is contained in this sequence of transforms, i.e. ifindex()
returns withoutValueError
, otherwiseFalse
. Return type

__contains__
(self, trans)¶ Return
trans
inself
. Parameters
trans (
tuple
ofnutils.transform.TransformItem
objects) – Returns
True
iftrans
is contained in this sequence of transforms, i.e. ifindex()
returns withoutValueError
, otherwiseFalse
. Return type

contains_with_tail
(self, trans)¶ Return
trans[:n]
inself
for somen
. Parameters
trans (
tuple
ofnutils.transform.TransformItem
objects) – Returns
True
if a head oftrans
is contained in this sequence of transforms, i.e. ifindex_with_tail()
returns withoutValueError
, otherwiseFalse
. Return type

refined
(self, references)¶ Return the sequence of refined transforms given
references
. Parameters
references (
References
) – A sequence of references matching this sequence of transforms. Returns
The sequence of refined transforms:
(trans+(ctrans,) for trans, ref in zip(self, references) for ctrans in ref.child_transforms)
 Return type

edges
(self, references)¶ Return the sequence of edge transforms given
references
. Parameters
references (
References
) – A sequence of references matching this sequence of transforms. Returns
The sequence of edge transforms:
(trans+(etrans,) for trans, ref in zip(self, references) for etrans in ref.edge_transforms)
 Return type

__add__
(self, other)¶ Return
self+other
.

unchain
(self)¶ Iterator of unchained
Transforms
items. Yields
Transforms
– Unchained items.

class
nutils.transformseq.
EmptyTransforms
(fromdims)¶ Bases:
nutils.transformseq.Transforms
An empty sequence.

class
nutils.transformseq.
PlainTransforms
(transforms, fromdims)¶ Bases:
nutils.transformseq.Transforms
A general purpose implementation of
Transforms
.Use this class only if there exists no specific implementation of
Transforms
for the transforms at hand. Parameters
transforms (
tuple
ofTransformItem
objects) – The sequence of transforms.fromdims (
int
) – The number of dimensions alltransforms
map from.

class
nutils.transformseq.
IdentifierTransforms
(ndims, name, length)¶ Bases:
nutils.transformseq.Transforms
A sequence of
nutils.transform.Identifier
singletons.Every identifier is instantiated with three arguments: the dimension, the name string, and an integer index matching its position in the sequence.

class
nutils.transformseq.
Axis
(*args, **kwargs)¶ Bases:
nutils.types.Singleton
Abstract base class for axes of
StructuredTopology
.

class
nutils.transformseq.
StructuredTransforms
(root, axes, nrefine)¶ Bases:
nutils.transformseq.Transforms
Transforms sequence for
StructuredTopology
. Parameters
root (
TransformItem
) – Root transform of theStructuredTopology
.axes (
tuple
ofAxis
objects) – The axes defining theStructuredTopology
.nrefine (
int
) – Number of structured refinements.

class
nutils.transformseq.
MaskedTransforms
(parent, indices)¶ Bases:
nutils.transformseq.Transforms
An order preserving subset of another
Transforms
object. Parameters
parent (
Transforms
) – The transforms to subset.indices (onedimensional array of
int
s) – The strict monotonic increasing indices ofparent
transforms to keep.

class
nutils.transformseq.
ReorderedTransforms
(parent, indices)¶ Bases:
nutils.transformseq.Transforms
A reordered
Transforms
object. Parameters
parent (
Transforms
) – The transforms to reorder.indices (onedimensional array of
int
s) – The new order of the transforms.

class
nutils.transformseq.
DerivedTransforms
(parent, parent_references, derived_attribute, fromdims)¶ Bases:
nutils.transformseq.Transforms
A sequence of derived transforms.
The derived transforms are ordered first by parent transforms, then by derived transforms, as returned by the reference:
(trans+(ctrans,) for trans, ref in zip(parent, parent_references) for ctrans in getattr(ref, derived_attribute))
 Parameters
parent (
Transforms
) – The transforms to refine.parent_references (
References
) – The references to use for the refinement.derived_attribute (
str
) – The name of the attribute of anutils.element.Reference
that contains the derived references.fromdims (
int
) – The number of dimensions all transforms in this sequence map from.

class
nutils.transformseq.
UniformDerivedTransforms
(parent, parent_reference, derived_attribute, fromdims)¶ Bases:
nutils.transformseq.Transforms
A sequence of refined transforms from a uniform sequence of references.
The refined transforms are ordered first by parent transforms, then by derived transforms, as returned by the reference:
(trans+(ctrans,) for trans in parent for ctrans in getattr(parent_reference, derived_attribute))
 Parameters
parent (
Transforms
) – The transforms to refine.parent_reference (
Reference
) – The reference to use for the refinement.derived_attribute (
str
) – The name of the attribute of anutils.element.Reference
that contains the derived references.fromdims (
int
) – The number of dimensions all transforms in this sequence map from.

class
nutils.transformseq.
ProductTransforms
(transforms1, transforms2)¶ Bases:
nutils.transformseq.Transforms
The product of two
Transforms
objects.The order of the resulting transforms is:
transforms1[0]*transforms2[0], transforms1[0]*transforms2[1], ..., transforms1[1]*transforms2[0], transforms1[1]*transforms2[1], ...
. Parameters
transforms1 (
Transforms
) – The first sequence of transforms.transforms2 (
Transforms
) – The second sequence of transforms.

class
nutils.transformseq.
ChainedTransforms
(items)¶ Bases:
nutils.transformseq.Transforms
A sequence of chained
Transforms
objects. Parameters
items (
tuple
ofTransforms
objects) – TheTransforms
objects to chain.

nutils.transformseq.
chain
(items, fromdims)¶ Return the chained transforms sequence of
items
. Parameters
items (iterable of
Transforms
objects) – TheTransforms
objects to chain.fromdims (
int
) – The number of dimensions all transforms in this sequence map from.
 Returns
The chained transforms.
 Return type