# transformseq¶

The transformseq module.

class nutils.transformseq.Transforms(fromdims)

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 an index() method. In addition the class supports the index_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.

fromdims

The number of dimensions all transforms in this sequence map from.

Type

int

Notes

Subclasses must implement __getitem__(), __len__() and index_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 tail trans[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 that self[index] == trans[:n] for some n. Note that there is either exactly one index satisfying this condition, or none, due to the restrictions of the transforms in a Transforms object.

Parameters

trans (tuple of nutils.transform.TransformItem objects) – The transform to find up to a possibly empty tail.

Returns

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 index 0 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 of nutils.transform.TransformItem objects) –

Returns

index – The index of trans in this sequence.

Return type

int

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 index 0:

>>> 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 in self.

Parameters

trans (tuple of nutils.transform.TransformItem objects) –

Returns

True if trans is contained in this sequence of transforms, i.e. if index() returns without ValueError, otherwise False.

Return type

bool

__contains__(self, trans)

Return trans in self.

Parameters

trans (tuple of nutils.transform.TransformItem objects) –

Returns

True if trans is contained in this sequence of transforms, i.e. if index() returns without ValueError, otherwise False.

Return type

bool

contains_with_tail(self, trans)

Return trans[:n] in self for some n.

Parameters

trans (tuple of nutils.transform.TransformItem objects) –

Returns

True if a head of trans is contained in this sequence of transforms, i.e. if index_with_tail() returns without ValueError, otherwise False.

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

__add__(self, other)

Return self+other.

unchain(self)

Iterator of unchained Transforms items.

Yields

Transforms – Unchained items.

class nutils.transformseq.PlainTransforms(transforms, fromdims)

A general purpose implementation of Transforms.

Use this class only if there exists no specific implementation of Transforms for the transforms at hand.

Parameters
class nutils.transformseq.Axis(*args, **kwargs)

Abstract base class for axes of StructuredTopology.

class nutils.transformseq.StructuredTransforms(root, axes, nrefine)

Transforms sequence for StructuredTopology.

Parameters
class nutils.transformseq.MaskedTransforms(parent, indices)

An order preserving subset of another Transforms object.

Parameters
• parent (Transforms) – The transforms to subset.

• indices (one-dimensional array of ints) – The strict monotonic increasing indices of parent transforms to keep.

class nutils.transformseq.RefinedTransforms(parent, parent_references)

A sequence of refined transforms.

The refined transforms are ordered first by parent transforms, then by child transforms, as returned by the reference:

(trans+(ctrans,) for trans, ref in zip(parent, parent_references) for ctrans in ref.child_transforms)

Parameters
class nutils.transformseq.UniformRefinedTransforms(parent, parent_reference)

A sequence of refined transforms from a uniform sequence of references.

The refined transforms are ordered first by parent transforms, then by child transforms, as returned by the reference:

(trans+(ctrans,) for trans in parent for ctrans in parent_reference.child_transforms)

Parameters
class nutils.transformseq.ProductTransforms(transforms1, transforms2)

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
class nutils.transformseq.ChainedTransforms(items)

A sequence of chained Transforms objects.

Parameters

items (tuple of Transforms objects) – The Transforms objects to chain.

nutils.transformseq.chain(items, fromdims)

Return the chained transforms sequence of items.

Parameters
Returns

The chained transforms.

Return type

Transforms