transformseq¶
The transformseq module.
- class nutils.transformseq.Transforms(todims, fromdims)¶
Bases:
SingletonAbstract base class for a sequence of
TransformItemtuples.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().- 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
indexsuch thatself[index] == trans[:n]for somen. Note that there is either exactly oneindexsatisfying this condition, or none, due to the restrictions of the transforms in aTransformsobject.- Parameters:
trans (
tupleofnutils.transform.TransformItemobjects) – The transform to find up to a possibly empty tail.- Returns:
index (
int) – The index oftranswithout tail in this sequence.tail (
tupleofnutils.transform.TransformItemobjects) – The tail:trans[len(self[index]):].
- Raises:
ValueError – if
transis 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 index0and 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),))
- __iter__(self)¶
Implement
iter(self).
- index(self, trans)¶
Return the index of
trans.- Parameters:
trans (
tupleofnutils.transform.TransformItemobjects) –- Returns:
index – The index of
transin this sequence.- Return type:
- Raises:
ValueError – if
transis 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
transinself.- Parameters:
trans (
tupleofnutils.transform.TransformItemobjects) –- Returns:
Trueiftransis contained in this sequence of transforms, i.e. ifindex()returns withoutValueError, otherwiseFalse.- Return type:
- __contains__(self, trans)¶
Return
transinself.- Parameters:
trans (
tupleofnutils.transform.TransformItemobjects) –- Returns:
Trueiftransis contained in this sequence of transforms, i.e. ifindex()returns withoutValueError, otherwiseFalse.- Return type:
- contains_with_tail(self, trans)¶
Return
trans[:n]inselffor somen.- Parameters:
trans (
tupleofnutils.transform.TransformItemobjects) –- Returns:
Trueif a head oftransis 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
Transformsitems.- Yields:
Transforms– Unchained items.
- get_evaluable(self, index)¶
Return the evaluable transform chain at the given index.
- Parameters:
index (a scalar, integer
nutils.evaluable.Array) – The index of the transform chain to return.- Returns:
The evaluable transform chain at the given
index.- Return type:
- class nutils.transformseq.EmptyTransforms(todims, fromdims)¶
Bases:
TransformsAn empty sequence.
- class nutils.transformseq.PlainTransforms(transforms, todims, fromdims)¶
Bases:
TransformsA general purpose implementation of
Transforms.Use this class only if there exists no specific implementation of
Transformsfor the transforms at hand.- Parameters:
transforms (
tupleofTransformItemobjects) – The sequence of transforms.fromdims (
int) – The number of dimensions alltransformsmap from.
- class nutils.transformseq.IndexTransforms(ndims, length, offset=0)¶
Bases:
TransformsA sequence of
nutils.transform.Indexsingletons.- Parameters:
ndims (
int) – Dimension of the transformation.length (
int) – Length of the sequence.offset (
int) – The index of the firstnutils.transform.Indexin this sequence.
- class nutils.transformseq.Axis(i, j, mod)¶
Bases:
SingletonBase class for axes of
StructuredTopology.
- class nutils.transformseq.StructuredTransforms(root, axes, nrefine)¶
Bases:
TransformsTransforms sequence for
StructuredTopology.- Parameters:
root (
TransformItem) – Root transform of theStructuredTopology.axes (
tupleofAxisobjects) – The axes defining theStructuredTopology.nrefine (
int) – Number of structured refinements.
- class nutils.transformseq.MaskedTransforms(parent, indices)¶
Bases:
TransformsAn order preserving subset of another
Transformsobject.- Parameters:
parent (
Transforms) – The transforms to subset.indices (one-dimensional array of
ints) – The strict monotonic increasing indices ofparenttransforms to keep.
- class nutils.transformseq.ReorderedTransforms(parent, indices)¶
Bases:
TransformsA reordered
Transformsobject.- Parameters:
parent (
Transforms) – The transforms to reorder.indices (one-dimensional array of
ints) – The new order of the transforms.
- class nutils.transformseq.DerivedTransforms(parent, parent_references, derived_attribute, fromdims)¶
Bases:
TransformsA 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.Referencethat 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:
TransformsA 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.Referencethat contains the derived references.fromdims (
int) – The number of dimensions all transforms in this sequence map from.
- class nutils.transformseq.ChainedTransforms(items)¶
Bases:
TransformsA sequence of chained
Transformsobjects.- Parameters:
items (
tupleofTransformsobjects) – TheTransformsobjects to chain.
- nutils.transformseq.chain(items, todims, fromdims)¶
Return the chained transforms sequence of
items.- Parameters:
items (iterable of
Transformsobjects) – TheTransformsobjects to chain.fromdims (
int) – The number of dimensions all transforms in this sequence map from.
- Returns:
The chained transforms.
- Return type: