Commit 8f3cad4d authored by Pierre Paleo's avatar Pierre Paleo
Browse files

sino normalization: update cuda test

parent 12d96b7d
......@@ -14,8 +14,8 @@ def bootstrap(request):
cls = request.cls
cls.sino = get_data("sino_refill.npy")
cls.tol = 1e-7
cls.norm_array_1D = np.arange(cls.sino.shape[-1])
cls.norm_array_2D = np.arange(cls.sino.size).reshape(cls.sino.shape)
cls.norm_array_1D = np.arange(cls.sino.shape[-1]) + 1
cls.norm_array_2D = np.arange(cls.sino.size).reshape(cls.sino.shape) + 1
@pytest.mark.usefixtures("bootstrap")
......@@ -47,6 +47,16 @@ class TestSinoNormalization:
assert np.max(np.abs(res - ref)) < self.tol
def get_normalization_reference_result(self, op, normalization_arr):
# Perform explicit operations to compare with numpy.divide, numpy.subtract, etc
if op == "subtraction":
ref = self.sino - normalization_arr
elif op == "division":
ref = self.sino / normalization_arr
return ref
def test_sino_array_subtraction_and_division(self):
with pytest.raises(ValueError):
SinoNormalization(kind="subtraction", sinos_shape=self.sino.shape)
......@@ -58,12 +68,7 @@ class TestSinoNormalization:
)
sino = self.sino.copy()
sino_normalization.normalize(sino)
# Perform explicit operations to compare with numpy.divide, numpy.subtract, etc
if op == "subtraction":
ref = self.sino - normalization_arr
elif op == "division":
ref = self.sino / normalization_arr
#
ref = self.get_normalization_reference_result(op, normalization_arr)
assert np.allclose(sino, ref), "operation=%s, normalization_array dims=%d" % (op, normalization_arr.ndim)
compare_normalizations(self.norm_array_1D, "subtraction")
......@@ -73,22 +78,22 @@ class TestSinoNormalization:
@pytest.mark.skipif(not(__has_pycuda__), reason="Need pycuda for sinogram normalization with cuda backend")
def xtest_sino_array_subtraction_cuda(self):
def test_sino_array_subtraction_cuda(self):
with pytest.raises(ValueError):
CudaSinoNormalization(kind="subtraction", sinos_shape=self.sino.shape)
array_1D = np.arange(self.sino.shape[-1])
array_2D = np.arange(self.sino.size).reshape(self.sino.shape)
def compare_normalizations(normalization_arr):
def compare_normalizations(normalization_arr, op):
sino_normalization = CudaSinoNormalization(
kind="subtraction", sinos_shape=self.sino.shape,
kind=op, sinos_shape=self.sino.shape,
normalization_array=normalization_arr
)
sino = garray.to_gpu(self.sino)
sino_normalization.normalize(sino)
ref = self.sino - normalization_arr
ref = self.get_normalization_reference_result(op, normalization_arr)
assert np.allclose(sino.get(), ref)
compare_normalizations(array_1D)
compare_normalizations(array_2D)
compare_normalizations(self.norm_array_1D, "subtraction")
compare_normalizations(self.norm_array_2D, "subtraction")
compare_normalizations(self.norm_array_1D, "division")
compare_normalizations(self.norm_array_2D, "division")
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment