utilities

General purpose utilities.

affine_by_parts(values, arr)[source]

Computes affine functions

compute_relative_error(current, target)[source]

Computes the absolute relative error between two values

docstring_parameters(*args, **kwargs)[source]

Decorator that allows the use of variables in docstrings. See: https://stackoverflow.com/questions/10307696/

This decorator modifies the docstring such that it ignores curly braces outside the “Parameters” section.

isiter(obj)[source]

Returns True if the passed argument is an iterable, False otherwise. Note that strings are iterable and will therefore return True.

safe_divide(num, denom, div0=0.0)[source]
Divides two numbers or iterables while handling the following cases:
  • If the numerator is 0, return 0

  • If the denominator is 0, return 0

  • If both numerator and denominator are 0, return 0

safe_slice(obj, mask)[source]

Slices an object if this is an iterable, otherwise returns the object.