Skip to content

Commit 6169a12

Browse files
committed
minor tweaks in test_offloading to allow Py(CUDA|OpenCL) arrays
1 parent ff02e3c commit 6169a12

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

tests/test_offloading.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
TrialFunction, Function, UnitSquareMesh,
55
SpatialCoordinate, inner, grad, dx, norm, pi, cos,
66
assemble)
7-
import numpy as np
87
import firedrake_configuration
98
from pyop2.backends.cpu import cpu_backend
109

@@ -16,6 +15,13 @@
1615
AVAILABLE_BACKENDS.append(cuda_backend)
1716

1817

18+
def allclose(a, b, rtol=1e-05, atol=1e-08):
19+
"""
20+
Prefer this routine over np.allclose(...) to allow pycuda/pyopencl arrays
21+
"""
22+
return bool(abs(a - b) < (atol + rtol * abs(b)))
23+
24+
1925
@pytest.mark.parametrize("offloading_backend", AVAILABLE_BACKENDS)
2026
def test_nonlinear_variational_solver(offloading_backend):
2127
set_offloading_backend(offloading_backend)
@@ -106,4 +112,4 @@ def test_data_manipulation_on_host(offloading_backend):
106112
with offloading():
107113
new_norm = norm(fem_soln)
108114

109-
np.testing.assert_allclose(kappa*old_norm, new_norm)
115+
allclose(kappa*old_norm, new_norm)

0 commit comments

Comments
 (0)