Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions xobjects/context_cpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
23 changes: 21 additions & 2 deletions xobjects/general.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"):
Expand All @@ -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