pymor.tools.floatcmp

Module Contents

pymor.tools.floatcmp.almost_less(x, y, rtol=1e-14, atol=1e-14)[source]

Component-wise check if x <= y up to a given tolerance.

For scalars the check is given by

almost_less(x, y) <=> (x - y  <= atol + |y| * rtol)
Parameters:
  • xNumPy arrays to be compared. Have to be broadcastable to the same shape.

  • yNumPy arrays to be compared. Have to be broadcastable to the same shape.

  • rtol – The relative tolerance.

  • atol – The absolute tolerance.

pymor.tools.floatcmp.bounded(lower, upper, x, rtol=None, atol=None)[source]

Check if x is strictly in bounds (lower, upper) or float_compares equal to lower or upper.

Parameters:
  • lower – Lower bound

  • upper – Upper bound

  • x – value to check

  • rtol – relative tolerance for float_cmp

  • atol – absolute tolerance for float_cmp

pymor.tools.floatcmp.float_cmp(x, y, rtol=1e-14, atol=1e-14)[source]

Compare x and y component-wise for almost equality.

For scalars we define almost equality as

float_cmp(x,y) <=> |x - y| <= atol + |y|*rtol

Note

Numpy’s allclose method uses the same definition but treats arrays containing infinities as close if the infinities are at the same places and all other entries are close. In our definition, arrays containing infinities can never be close which seems more appropriate in most cases.

Parameters:
  • xNumPy arrays to be compared. Have to be broadcastable to the same shape.

  • yNumPy arrays to be compared. Have to be broadcastable to the same shape.

  • rtol – The relative tolerance.

  • atol – The absolute tolerance.

pymor.tools.floatcmp.float_cmp_all(x, y, rtol=None, atol=None)[source]

Compare x and y for almost equality.

Returns True if all components of x are almost equal to the corresponding components of y.

See float_cmp.