ufl.utils package

Submodules

ufl.utils.counted module

Mixin class for types with a global unique counter attached to each object.

class ufl.utils.counted.Counted(count=None, counted_class=None)[source]

Bases: object

Mixin class for globally counted objects.

count()[source]

Get count.

ufl.utils.formatting module

Various string formatting utilities.

ufl.utils.formatting.camel2underscore(name)[source]

Convert a CamelCaps string to underscore_syntax.

ufl.utils.formatting.estr(elements)[source]

Format list of elements for printing.

ufl.utils.formatting.istr(o)[source]

Format object as string, inserting ? for None.

ufl.utils.formatting.lstr(a)[source]

Pretty-print list or tuple, invoking str() on items instead of repr() like str() does.

ufl.utils.formatting.tree_format(expression, indentation=0, parentheses=True)[source]

Tree format.

ufl.utils.formatting.tstr(t, colsize=80)[source]

Pretty-print list of tuples of key-value pairs.

ufl.utils.indexflattening module

Collection of utilities for mapping between multiindices and a flattened index space.

ufl.utils.indexflattening.flatten_multiindex(ii, strides)[source]

Return the flat index corresponding to the given multiindex.

ufl.utils.indexflattening.shape_to_strides(sh)[source]

Return a tuple of strides given a shape tuple.

ufl.utils.indexflattening.unflatten_index(i, strides)[source]

Return the multiindex corresponding to the given flat index.

ufl.utils.sequences module

Various sequence manipulation utilities.

ufl.utils.sequences.max_degree(degrees)[source]

Maximum degree for mixture of scalar and tuple degrees.

ufl.utils.sequences.product(sequence)[source]

Return the product of all elements in a sequence.

ufl.utils.sorting module

Utilites for sorting.

ufl.utils.sorting.canonicalize_metadata(metadata)[source]

Assuming metadata to be a dict with string keys and builtin python types as values.

Transform dict to a tuple of (key, value) item tuples ordered by key, with dict, list and tuple values converted the same way recursively. Lists and tuples are converted to tuples. Other values are converted using str(). This is such that the end result can be hashed and sorted using regular <, because python 3 doesn’t allow e.g. (3 < “auto”) which occurs regularly in metadata.

ufl.utils.sorting.sorted_by_count(seq)[source]

Sort a sequence by the item.count().

ufl.utils.sorting.sorted_by_key(mapping)[source]

Sort dict items by key, allowing different key types.

ufl.utils.sorting.topological_sorting(nodes, edges)[source]

Return a topologically sorted list of the nodes.

Implemented algorithm from Wikipedia (http://en.wikipedia.org/wiki/Topological_sorting).

No error for cyclic edges…

ufl.utils.stacks module

Various utility data structures.

class ufl.utils.stacks.Stack(*args)[source]

Bases: list

A stack datastructure.

peek()[source]

Peek.

push(v)[source]

Push.

class ufl.utils.stacks.StackDict(*args, **kwargs)[source]

Bases: dict

A dictionary type.

A dict that can be changed incrementally with ‘d.push(k,v)’ and have changes rolled back with ‘k,v = d.pop()’.

pop()[source]

Restore previous state for this key.

push(k, v)[source]

Store previous state for this key.

Module contents

Utilities.