assertFloatsAlmostEqual¶
-
lsst.utils.tests.
assertFloatsAlmostEqual
(testCase, lhs, rhs, rtol=2.220446049250313e-16, atol=2.220446049250313e-16, relTo=None, printFailures=True, plotOnFailure=False, plotFileName=None, invert=False, msg=None)[source]¶ Highly-configurable floating point comparisons for scalars and arrays.
The test assertion will fail if all elements
lhs
andrhs
are not equal to within the tolerances specified byrtol
andatol
. More precisely, the comparison is:abs(lhs - rhs) <= relTo*rtol OR abs(lhs - rhs) <= atol
If
rtol
oratol
isNone
, that term in the comparison is not performed at all.When not specified,
relTo
is the elementwise maximum of the absolute values oflhs
andrhs
. If set manually, it should usually be set to eitherlhs
orrhs
, or a scalar value typical of what is expected.Parameters: testCase :
unittest.TestCase
Instance the test is part of.
lhs : scalar or array-like
LHS value(s) to compare; may be a scalar or array-like of any dimension.
rhs : scalar or array-like
RHS value(s) to compare; may be a scalar or array-like of any dimension.
rtol :
float
, optionalRelative tolerance for comparison; defaults to double-precision epsilon.
atol :
float
, optionalAbsolute tolerance for comparison; defaults to double-precision epsilon.
relTo :
float
, optionalValue to which comparison with rtol is relative.
printFailures :
bool
, optionalUpon failure, print all inequal elements as part of the message.
plotOnFailure :
bool
, optionalUpon failure, plot the originals and their residual with matplotlib. Only 2-d arrays are supported.
plotFileName :
str
, optionalFilename to save the plot to. If
None
, the plot will be displayed in a window.invert :
bool
, optionalIf
True
, invert the comparison and fail only if any elements are equal. Used to implementassertFloatsNotEqual
, which should generally be used instead for clarity.msg :
str
, optionalString to append to the error message when assert fails.
Raises: AssertionError
The values are not almost equal.