comnum.Tolerance#

class comnum.Tolerance(*, atol=None, rtol=None, factor=None)#

The acceptance rule of a measured value v against an expected value e, as comnum verify and the validation cards apply it: |v - e| <= atol + rtol |e| (with atol or rtol), or e/factor <= v <= factor e for a positive e (with factor); a value passes when one of the given rules accepts it.

Parameters:
  • atol (float | None) – the absolute tolerance.

  • rtol (float | None) – the tolerance relative to the expected value.

  • factor (float | None) – the factor, at least 1.

Examples

>>> import comnum
>>> t = comnum.Tolerance(factor=1.6)
>>> t.accepts(0.30, 0.26), t.accepts(0.5, 0.26)
(True, False)
>>> comnum.Tolerance(rtol=0.05).accepts([1.0, 2.05], [1.0, 2.0])
True
accepts(value, expected)#

Whether every measured value is accepted for its expected value.

Parameters:
  • value (float | array_like) – the measured values.

  • expected (float | array_like) – the expected values, one for all or one per measured value.

Returns:

whether all are accepted.

Return type:

bool

Raises:

ValueError – for arrays of different sizes, or values that are not real numbers.

atol#

The absolute tolerance.

Type:

float | None

factor#

The factor.

Type:

float | None

is_set#

Whether a rule is given (an empty tolerance accepts nothing).

Type:

bool

rtol#

The relative tolerance.

Type:

float | None