diff --git a/xobjects/context_cpu.py b/xobjects/context_cpu.py index 7e6f60f..6234a9a 100644 --- a/xobjects/context_cpu.py +++ b/xobjects/context_cpu.py @@ -422,12 +422,6 @@ def compile_kernel( xtr_link_args.append("-fopenmp") xtr_compile_args.append("-DXO_CONTEXT_CPU_OPENMP") xtr_link_args.append("-DXO_CONTEXT_CPU_OPENMP") - - # https://mac.r-project.org/openmp/ - # on macos comment the above and uncomment the below flags to compile OpenMP with Xcode clang: - # xtr_compile_args.append("-Xclang") - # xtr_compile_args.append("-fopenmp") - # xtr_link_args.append("-lomp") else: xtr_compile_args.append("-DXO_CONTEXT_CPU_SERIAL") xtr_link_args.append("-DXO_CONTEXT_CPU_SERIAL") diff --git a/xobjects/general.py b/xobjects/general.py index 9720c0e..6324936 100644 --- a/xobjects/general.py +++ b/xobjects/general.py @@ -17,7 +17,7 @@ def __call__(self, *args, **kwargs): _print = Print() -def assert_allclose(a, b, rtol=1e-7, atol=1e-7): +def assert_allclose(a, b, rtol=0, atol=0, max_outliers=0): if hasattr(a, "get"): a = a.get() if hasattr(b, "get"): @@ -30,4 +30,23 @@ def assert_allclose(a, b, rtol=1e-7, atol=1e-7): b = np.squeeze(b) except: pass - np_assert_allclose(a, b, rtol=rtol, atol=atol) + + try: + np_assert_allclose(a, b, rtol=rtol, atol=atol) + except AssertionError as e: + if max_outliers == 0: + raise e + if not allclose_with_outliers(a, b, rtol, atol, max_outliers): + raise AssertionError( + "Arrays are not close enough, even with outliers allowed." + ) from e + + +def allclose_with_outliers(a, b, rtol=1e-7, atol=0, max_outliers=0): + a = np.asanyarray(a) + b = np.asanyarray(b) + diff = np.abs(a - b) + allowed = atol + rtol * np.abs(b) + mask = diff > allowed + num_outliers = np.count_nonzero(mask) + return num_outliers <= max_outliers