checks¶
Shared numeric utilities — the check record, float comparison, and tolerance resolution.
checks
¶
Shared numeric utilities: the check record, float comparison, tolerances.
CheckResult(phase, name, description, passed, detail='')
dataclass
¶
Represent one line in the verification log.
passed is True/False for a real check, or None for an informational
entry (e.g. a data-intake summary line that reports a fact but does not pass/fail).
Attributes:
| Name | Type | Description |
|---|---|---|
phase |
str
|
Identifier of the verification phase that produced this record (e.g. |
name |
str
|
Short machine-readable check name (e.g. |
description |
str
|
Human-readable description of what the check verifies. |
passed |
bool | None
|
|
detail |
str
|
Optional free-text detail line shown alongside the result. |
status
property
¶
Render the check outcome as a log label.
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
and |
is_close(a, b, atol=1e-08, rtol=1e-06, use_abs=False)
¶
Test whether two numbers agree within atol + rtol * max(|a|, |b|).
NaN never counts as agreement: a NaN almost always signals a broken
computation, not consensus, so two NaNs do not "match" and are not
"reproducible". Infinities compare by exact equality. use_abs compares
magnitudes only, for quantities whose sign is implementation-defined (PCA
loadings, eigenvectors, discriminant-function coefficients), where Python and
R may legitimately return the same result with opposite signs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
a
|
First value; coerced to |
required | |
b
|
Second value; coerced to |
required | |
atol
|
float
|
Absolute tolerance component. |
1e-08
|
rtol
|
float
|
Relative tolerance component, anchored to |
1e-06
|
use_abs
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
bool
|
|
bool
|
when either value is NaN or cannot be coerced to |
Source code in crossverify/checks.py
tol_for(tolerance, key)
¶
Resolve (atol, rtol, use_abs) for a statistic, applying per-key overrides.
Starts from default_atol/default_rtol and a use_abs of False, then
applies any overrides declared under per_key[key] (atol, rtol, abs).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
dict
|
Tolerance configuration mapping, typically |
required |
key
|
str
|
Statistic name whose per-key overrides should be applied. |
required |
Returns:
| Type | Description |
|---|---|
|
A |
|
|
tolerance, and magnitude-only comparison flag for |
Source code in crossverify/checks.py
severity_for(tolerance, key)
¶
Resolve a statistic's cross-tool severity: 'fail' (default) or 'info'.
A cross-tool mismatch is a hard failure by default — agreement across an
independent implementation is the whole point of Phase 5. But correct
analyses legitimately differ past a tight tolerance for defensible reasons
(robust-SE variants, ddof/denominator choices, contrast coding, tie
handling). Declaring severity: info in a statistic's per-key tolerance
reports such a divergence as INFO rather than failing the build, so a
researcher is not pushed to degrade correct code just to turn the run green.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tolerance
|
dict
|
Tolerance configuration mapping, typically |
required |
key
|
str
|
Statistic name whose per-key |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
str
|
(also the fallback for any unrecognized severity value). |
Source code in crossverify/checks.py
fmt(x)
¶
Format a number for the log without lying about precision.
Renders None as an em dash, NaN as "NaN", and integral values without a
decimal point. Other finite values use enough significant digits (%.10g) that
two values differing only at the 7th-8th digit (a row that therefore FAILED) do not
print as identical. Values that cannot be coerced to float fall back to str.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Value to format; typically a number, |
required |
Returns:
| Type | Description |
|---|---|
str
|
The formatted string representation of |