transformseq

The transformseq module.

class nutils.transformseq.Transforms(todims, fromdims)

Bases: 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 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:
  • todims (int) – The dimension all transforms in this sequence map to.

  • fromdims (int) – The dimension all transforms in this sequence map from.

todims

The dimension all transforms in this sequence map to.

Type:

int

fromdims

The dimension all transforms in this sequence map from.

Type:

int

Notes

Subclasses must implement __getitem__(), __len__() and index_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 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 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 index 0 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),))
__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 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 index 0:

>>> 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 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

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: Transforms

An empty sequence.

class nutils.transformseq.PlainTransforms(transforms, todims, fromdims)

Bases: 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 of TransformItem objects) – The sequence of transforms in canonical order.

  • fromdims (int) – The number of dimensions all transforms map from.

class nutils.transformseq.IndexTransforms(ndims, length, offset=0)

Bases: 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 first nutils.transform.Index in this sequence.

class nutils.transformseq.Axis(i, j, mod)

Bases: Singleton

Base class for axes of StructuredTopology.

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

Bases: Transforms

Transforms sequence for StructuredTopology.

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

Bases: Transforms

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.ReorderedTransforms(parent, indices)

Bases: Transforms

A reordered Transforms object.

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: 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 a nutils.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: 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 a nutils.element.Reference that contains the derived references.

  • fromdims (int) – The number of dimensions all transforms in this sequence map from.

class nutils.transformseq.ChainedTransforms(items)

Bases: Transforms

A sequence of chained Transforms objects.

Parameters:

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

nutils.transformseq.chain(items, todims, fromdims)

Return the chained transforms sequence of items.

Parameters:
  • items (iterable of Transforms objects) – The Transforms objects to chain.

  • fromdims (int) – The number of dimensions all transforms in this sequence map from.

Returns:

The chained transforms.

Return type:

Transforms