"""Two checks of the equivalence test itself. 1. Mutation: against a reference with ONE component removed the comparison must find differences - otherwise a passing equivalence test would prove nothing. 2. Speed: wall time of the compiled library against the Python reference over all problems. PYTHONPATH=;. python check_simbracket.py """ import time import simbracket from simroot.pure import pure_root from sweep_full import APRIME from tests.test_simbracket_equivalence import PROBS, reference, run def main(): for drop in ("close", "sub", "half", "contra", "exp"): pre = "+".join(p for p in APRIME.split("+") if p != drop) mut = lambda f, a, b, xt, mf, pre=pre: pure_root( # noqa: E731 f, a, b, xt, mf, similarity="ratio", scale="derived3", guard="project", prestep=pre, extrapolate="pattern") diff = sum(run(mut, f, a, b, 1e-12, 200) != run(simbracket.find_root, f, a, b, 1e-12, 200) for _p, f, a, b in PROBS) print(f"mutation -{drop:<7}: {diff} of {len(PROBS)} problems differ (must be > 0)") for name, m in (("reference (Python)", reference), ("simbracket (compiled)", simbracket.find_root)): t0 = time.perf_counter() for _ in range(3): for _p, f, a, b in PROBS: run(m, f, a, b, 1e-12, 200) print(f"{name:<22} {(time.perf_counter() - t0) / 3:.3f} s per pass over {len(PROBS)}") if __name__ == "__main__": main()