transformseq¶
The transformseq module.
-
class
nutils.transformseq.
Transforms
(todims, 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: Notes
Subclasses must implement
__getitem__()
,__len__()
andindex_with_tail()
.-
__len__
(self)¶ Return
len(self)
.
-
__getitem__
(self, index)¶ Return
self[index]
.
-
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
– iftrans
is not found.Example
Consider the following plain sequence of two index transforms:
>>> from nutils.transform import Index, SimplexChild >>> transforms = PlainTransforms(((Index(1, 0),), (Index(1, 1),)), 1, 1)
Calling
index_with_tail()
with the first transform gives index0
and no tail:>>> transforms.index_with_tail((Index(1, 0),)) (0, ())
Calling with an additional scale gives:
>>> transforms.index_with_tail((Index(1, 0), SimplexChild(1, 0))) (0, (SimplexChild([0]+[.5]*x0),))
- index (
-
__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: int
Raises: ValueError
– iftrans
is not found.Example
Consider the following plain sequence of two index transforms:
>>> from nutils.transform import Index, SimplexChild >>> transforms = PlainTransforms(((Index(1, 0),), (Index(1, 1),)), 1, 1)
Calling
index()
with the first transform gives index0
:>>> transforms.index((Index(1, 0),)) 0
Calling with an additional scale raises an exception, because the transform is not present in
transforms
.>>> transforms.index((Index(1, 0), SimplexChild(1, 0))) Traceback (most recent call last): ... ValueError: (Index(1, 0), SimplexChild([0]+[.5]*x0)) 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: bool
-
__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: bool
-
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: bool
-
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: Transforms
-
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: Transforms
-
__add__
(self, other)¶ Return
self+other
.
-
unchain
(self)¶ Iterator of unchained
Transforms
items.Yields: Transforms
– Unchained items.
-
-
class
nutils.transformseq.
EmptyTransforms
(todims, fromdims)¶ Bases:
nutils.transformseq.Transforms
An empty sequence.
-
class
nutils.transformseq.
PlainTransforms
(transforms, todims, 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 in canonical order. - fromdims (
int
) – The number of dimensions alltransforms
map from.
- transforms (
-
class
nutils.transformseq.
IndexTransforms
(ndims, length, offset=0)¶ Bases:
nutils.transformseq.Transforms
A sequence of
nutils.transform.Index
singletons.Parameters: - ndims (
int
) – Dimension of the transformation. - length (
int
) – Length of the sequence. - offset (
int
) – The index of the firstnutils.transform.Index
in this sequence.
- ndims (
-
class
nutils.transformseq.
Axis
(i, j, mod)¶ Bases:
nutils.types.Singleton
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.
- root (
-
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 (one-dimensional array of
int
s) – The strict monotonic increasing indices ofparent
transforms to keep.
- parent (
-
class
nutils.transformseq.
ReorderedTransforms
(parent, indices)¶ Bases:
nutils.transformseq.Transforms
A reordered
Transforms
object.Parameters: - parent (
Transforms
) – The transforms to reorder. - indices (one-dimensional array of
int
s) – The new order of the transforms.
- parent (
-
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.
- parent (
-
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.
- parent (
-
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, todims, 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: - items (iterable of