diff options
author | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2019-12-23 13:45:09 +0100 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@synchrotron-soleil.fr> | 2019-12-23 13:45:09 +0100 |
commit | 5d647cf9a6159afd2933da594b9c79ad93d3cd9b (patch) | |
tree | 2571025a602f68fc8933b01104dc712d41f84034 /silx/opencl/test | |
parent | 654a6ac93513c3cc1ef97cacd782ff674c6f4559 (diff) |
New upstream version 0.12.0~b0+dfsg
Diffstat (limited to 'silx/opencl/test')
-rw-r--r-- | silx/opencl/test/test_addition.py | 5 | ||||
-rw-r--r-- | silx/opencl/test/test_convolution.py | 8 | ||||
-rw-r--r-- | silx/opencl/test/test_kahan.py | 8 | ||||
-rw-r--r-- | silx/opencl/test/test_linalg.py | 5 | ||||
-rw-r--r-- | silx/opencl/test/test_sparse.py | 85 |
5 files changed, 64 insertions, 47 deletions
diff --git a/silx/opencl/test/test_addition.py b/silx/opencl/test/test_addition.py index 3283a4d..49cc0b4 100644 --- a/silx/opencl/test/test_addition.py +++ b/silx/opencl/test/test_addition.py @@ -35,7 +35,7 @@ __authors__ = ["Henri Payno, Jérôme Kieffer"] __contact__ = "jerome.kieffer@esrf.eu" __license__ = "MIT" __copyright__ = "2013 European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "05/07/2018" +__date__ = "01/08/2019" import logging import numpy @@ -80,7 +80,8 @@ class TestAddition(unittest.TestCase): self.shape = 4096 self.data = numpy.random.random(self.shape).astype(numpy.float32) self.d_array_img = pyopencl.array.to_device(self.queue, self.data) - self.d_array_5 = pyopencl.array.zeros_like(self.d_array_img) - 5 + self.d_array_5 = pyopencl.array.empty_like(self.d_array_img) + self.d_array_5.fill(-5) self.program = pyopencl.Program(self.ctx, get_opencl_code("addition")).build() def tearDown(self): diff --git a/silx/opencl/test/test_convolution.py b/silx/opencl/test/test_convolution.py index 8acd385..c213808 100644 --- a/silx/opencl/test/test_convolution.py +++ b/silx/opencl/test/test_convolution.py @@ -34,12 +34,13 @@ __authors__ = ["Pierre Paleo"] __contact__ = "pierre.paleo@esrf.fr" __license__ = "MIT" __copyright__ = "2019 European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "15/02/2019" +__date__ = "01/08/2019" import logging from itertools import product import numpy as np from silx.utils.testutils import parameterize +from silx.image.utils import gaussian_kernel try: from scipy.ndimage import convolve, convolve1d from scipy.misc import ascent @@ -52,7 +53,7 @@ from ..common import ocl if ocl: import pyopencl as cl import pyopencl.array as parray - from ..convolution import Convolution, gaussian_kernel + from silx.opencl.convolution import Convolution logger = logging.getLogger(__name__) @@ -178,7 +179,8 @@ class TestConvolution(unittest.TestCase): else: data_ref = data if self.param["output_on_device"]: - d_res = parray.zeros_like(conv.data_out) + d_res = parray.empty_like(conv.data_out) + d_res.fill(0) res = d_res else: res = None diff --git a/silx/opencl/test/test_kahan.py b/silx/opencl/test/test_kahan.py index bb9ea3f..167640c 100644 --- a/silx/opencl/test/test_kahan.py +++ b/silx/opencl/test/test_kahan.py @@ -34,7 +34,7 @@ __author__ = "Jérôme Kieffer" __contact__ = "Jerome.Kieffer@ESRF.eu" __license__ = "MIT" __copyright__ = "European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "30/01/2019" +__date__ = "01/08/2019" import unittest @@ -120,7 +120,8 @@ class TestKahan(unittest.TestCase): """ prg = pyopencl.Program(self.ctx, read_cl_file("kahan.cl") + src).build(self.args) ones_d = pyopencl.array.to_device(self.queue, data) - res_d = pyopencl.array.zeros(self.queue, 2, numpy.float32) + res_d = pyopencl.array.empty(self.queue, 2, numpy.float32) + res_d.fill(0) evt = prg.summation(self.queue, (1,), (1,), ones_d.data, numpy.int32(N), res_d.data) evt.wait() res = res_d.get().sum(dtype=numpy.float64) @@ -202,7 +203,8 @@ class TestKahan(unittest.TestCase): prg = pyopencl.Program(self.ctx, read_cl_file("kahan.cl") + src).build(self.args) ones_d = pyopencl.array.to_device(self.queue, data) - res_d = pyopencl.array.zeros(self.queue, 2, numpy.float32) + res_d = pyopencl.array.empty(self.queue, 2, numpy.float32) + res_d.fill(0) evt = prg.test_dot16(self.queue, (1,), (1,), ones_d.data, numpy.int32(N), res_d.data) evt.wait() res = res_d.get().sum(dtype="float64") diff --git a/silx/opencl/test/test_linalg.py b/silx/opencl/test/test_linalg.py index 7d03983..b72fa20 100644 --- a/silx/opencl/test/test_linalg.py +++ b/silx/opencl/test/test_linalg.py @@ -30,7 +30,7 @@ from __future__ import division, print_function __authors__ = ["Pierre paleo"] __license__ = "MIT" __copyright__ = "2013-2017 European Synchrotron Radiation Facility, Grenoble, France" -__date__ = "14/06/2017" +__date__ = "01/08/2019" import time @@ -109,7 +109,8 @@ class TestLinAlg(unittest.TestCase): self.div_ref = divergence(self.grad_ref) self.image2 = np.zeros_like(self.image) # Device images - self.gradient_parray = parray.zeros(self.la.queue, self.image.shape, np.complex64) + self.gradient_parray = parray.empty(self.la.queue, self.image.shape, np.complex64) + self.gradient_parray.fill(0) # we should be using cl.Buffer(self.la.ctx, cl.mem_flags.READ_WRITE, size=self.image.nbytes*2), # but platforms not suporting openCL 1.2 have a problem with enqueue_fill_buffer, # so we use the parray "fill" utility diff --git a/silx/opencl/test/test_sparse.py b/silx/opencl/test/test_sparse.py index 56f1ba4..76a6a0a 100644 --- a/silx/opencl/test/test_sparse.py +++ b/silx/opencl/test/test_sparse.py @@ -82,39 +82,45 @@ class TestCSR(unittest.TestCase): """Test CSR format""" def setUp(self): - self.array = generate_sparse_random_data(shape=(512, 511)) - # Compute reference sparsification - a_s = sp.csr_matrix(self.array) - self.ref_data = a_s.data - self.ref_indices = a_s.indices - self.ref_indptr = a_s.indptr - self.ref_nnz = a_s.nnz # Test possible configurations input_on_device = [False, True] output_on_device = [False, True] - self._test_configs = list(product(input_on_device, output_on_device)) + dtypes = [np.float32, np.int32, np.uint16] + self._test_configs = list(product(input_on_device, output_on_device, dtypes)) + + + def compute_ref_sparsification(self, array): + ref_sparse = sp.csr_matrix(array) + return ref_sparse def test_sparsification(self): - for input_on_device, output_on_device in self._test_configs: - self._test_sparsification(input_on_device, output_on_device) + for input_on_device, output_on_device, dtype in self._test_configs: + self._test_sparsification(input_on_device, output_on_device, dtype) - def _test_sparsification(self, input_on_device, output_on_device): - current_config = "input on device: %s, output on device: %s" % ( - str(input_on_device), str(output_on_device) + def _test_sparsification(self, input_on_device, output_on_device, dtype): + current_config = "input on device: %s, output on device: %s, dtype: %s" % ( + str(input_on_device), str(output_on_device), str(dtype) ) + logger.debug("CSR: %s" % current_config) + # Generate data and reference CSR + array = generate_sparse_random_data(shape=(512, 511), dtype=dtype) + ref_sparse = self.compute_ref_sparsification(array) # Sparsify on device - csr = CSR(self.array.shape) + csr = CSR(array.shape, dtype=dtype) if input_on_device: # The array has to be flattened - arr = parray.to_device(csr.queue, self.array.ravel()) + arr = parray.to_device(csr.queue, array.ravel()) else: - arr = self.array + arr = array if output_on_device: - d_data = parray.zeros_like(csr.data) - d_indices = parray.zeros_like(csr.indices) - d_indptr = parray.zeros_like(csr.indptr) + d_data = parray.empty_like(csr.data) + d_indices = parray.empty_like(csr.indices) + d_indptr = parray.empty_like(csr.indptr) + d_data.fill(0) + d_indices.fill(0) + d_indptr.fill(0) output = (d_data, d_indices, d_indptr) else: output = None @@ -124,45 +130,50 @@ class TestCSR(unittest.TestCase): indices = indices.get() indptr = indptr.get() # Compare - nnz = self.ref_nnz + nnz = ref_sparse.nnz self.assertTrue( - np.allclose(data[:nnz], self.ref_data), + np.allclose(data[:nnz], ref_sparse.data), "something wrong with sparsified data (%s)" % current_config ) self.assertTrue( - np.allclose(indices[:nnz], self.ref_indices), + np.allclose(indices[:nnz], ref_sparse.indices), "something wrong with sparsified indices (%s)" % current_config ) self.assertTrue( - np.allclose(indptr, self.ref_indptr), + np.allclose(indptr, ref_sparse.indptr), "something wrong with sparsified indices pointers (indptr) (%s)" % current_config ) def test_desparsification(self): - for input_on_device, output_on_device in self._test_configs: - self._test_desparsification(input_on_device, output_on_device) + for input_on_device, output_on_device, dtype in self._test_configs: + self._test_desparsification(input_on_device, output_on_device, dtype) - def _test_desparsification(self, input_on_device, output_on_device): - current_config = "input on device: %s, output on device: %s" % ( - str(input_on_device), str(output_on_device) + def _test_desparsification(self, input_on_device, output_on_device, dtype): + current_config = "input on device: %s, output on device: %s, dtype: %s" % ( + str(input_on_device), str(output_on_device), str(dtype) ) + logger.debug("CSR: %s" % current_config) + # Generate data and reference CSR + array = generate_sparse_random_data(shape=(512, 511), dtype=dtype) + ref_sparse = self.compute_ref_sparsification(array) # De-sparsify on device - csr = CSR(self.array.shape, max_nnz=self.ref_nnz) + csr = CSR(array.shape, dtype=dtype, max_nnz=ref_sparse.nnz) if input_on_device: - data = parray.to_device(csr.queue, self.ref_data) - indices = parray.to_device(csr.queue, self.ref_indices) - indptr = parray.to_device(csr.queue, self.ref_indptr) + data = parray.to_device(csr.queue, ref_sparse.data) + indices = parray.to_device(csr.queue, ref_sparse.indices) + indptr = parray.to_device(csr.queue, ref_sparse.indptr) else: - data = self.ref_data - indices = self.ref_indices - indptr = self.ref_indptr + data = ref_sparse.data + indices = ref_sparse.indices + indptr = ref_sparse.indptr if output_on_device: - d_arr = parray.zeros_like(csr.array) + d_arr = parray.empty_like(csr.array) + d_arr.fill(0) output = d_arr else: output = None @@ -171,7 +182,7 @@ class TestCSR(unittest.TestCase): arr = arr.get() # Compare self.assertTrue( - np.allclose(arr.reshape(self.array.shape), self.array), + np.allclose(arr.reshape(array.shape), array), "something wrong with densified data (%s)" % current_config ) |