diff options
author | Picca Frédéric-Emmanuel <picca@debian.org> | 2018-03-04 10:20:27 +0100 |
---|---|---|
committer | Picca Frédéric-Emmanuel <picca@debian.org> | 2018-03-04 10:20:27 +0100 |
commit | 270d5ddc31c26b62379e3caa9044dd75ccc71847 (patch) | |
tree | 55c5bfc851dfce7172d335cd2405b214323e3caf /silx/opencl/test | |
parent | e19c96eff0c310c06c4f268c8b80cb33bd08996f (diff) |
New upstream version 0.7.0+dfsg
Diffstat (limited to 'silx/opencl/test')
-rw-r--r-- | silx/opencl/test/__init__.py | 7 | ||||
-rw-r--r-- | silx/opencl/test/test_addition.py | 6 | ||||
-rw-r--r-- | silx/opencl/test/test_backprojection.py | 4 | ||||
-rw-r--r-- | silx/opencl/test/test_image.py | 137 | ||||
-rw-r--r-- | silx/opencl/test/test_projection.py | 16 |
5 files changed, 151 insertions, 19 deletions
diff --git a/silx/opencl/test/__init__.py b/silx/opencl/test/__init__.py index f6aadcd..2fe88ea 100644 --- a/silx/opencl/test/__init__.py +++ b/silx/opencl/test/__init__.py @@ -24,7 +24,7 @@ __authors__ = ["J. Kieffer"] __license__ = "MIT" -__date__ = "01/09/2017" +__date__ = "17/10/2017" import os import unittest @@ -34,6 +34,8 @@ from . import test_backprojection from . import test_projection from . import test_linalg from . import test_array_utils +from ..codec import test as test_codec +from . import test_image def suite(): test_suite = unittest.TestSuite() @@ -43,7 +45,8 @@ def suite(): test_suite.addTests(test_projection.suite()) test_suite.addTests(test_linalg.suite()) test_suite.addTests(test_array_utils.suite()) - + test_suite.addTests(test_codec.suite()) + test_suite.addTests(test_image.suite()) # Allow to remove sift from the project test_base_dir = os.path.dirname(__file__) sift_dir = os.path.join(test_base_dir, "..", "sift") diff --git a/silx/opencl/test/test_addition.py b/silx/opencl/test/test_addition.py index 89e49be..cde86e2 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__ = "15/03/2017" +__date__ = "12/02/2018" import logging import numpy @@ -108,7 +108,7 @@ class TestAddition(unittest.TestCase): else: res = d_array_result.get() good = numpy.allclose(res, self.data - 5) - if good and wg>self.max_valid_wg: + if good and wg > self.max_valid_wg: self.__class__.max_valid_wg = wg self.assert_(good, "calculation is correct for WG=%s" % wg) @@ -127,7 +127,7 @@ class TestAddition(unittest.TestCase): def suite(): testSuite = unittest.TestSuite() testSuite.addTest(TestAddition("test_add")) - testSuite.addTest(TestAddition("test_measurement")) + # testSuite.addTest(TestAddition("test_measurement")) return testSuite diff --git a/silx/opencl/test/test_backprojection.py b/silx/opencl/test/test_backprojection.py index 342bd2f..70ce2ae 100644 --- a/silx/opencl/test/test_backprojection.py +++ b/silx/opencl/test/test_backprojection.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__ = "05/10/2017" +__date__ = "19/01/2018" import time @@ -89,7 +89,7 @@ class TestFBP(unittest.TestCase): # ~ self.skipTest("Backprojection is not implemented on CPU for OS X yet") self.getfiles() self.fbp = backprojection.Backprojection(self.sino.shape, profile=True) - if self.fbp.compiletime_workgroup_size < 16: + if self.fbp.compiletime_workgroup_size < 16 * 16: self.skipTest("Current implementation of OpenCL backprojection is not supported on this platform yet") def tearDown(self): diff --git a/silx/opencl/test/test_image.py b/silx/opencl/test/test_image.py new file mode 100644 index 0000000..d73a854 --- /dev/null +++ b/silx/opencl/test/test_image.py @@ -0,0 +1,137 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# Project: image manipulation in OpenCL +# https://github.com/silx-kit/silx +# +# Permission is hereby granted, free of charge, to any person +# obtaining a copy of this software and associated documentation +# files (the "Software"), to deal in the Software without +# restriction, including without limitation the rights to use, +# copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following +# conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +# OTHER DEALINGS IN THE SOFTWARE. + +""" +Simple test of image manipulation +""" + +from __future__ import division, print_function + +__authors__ = ["Jérôme Kieffer"] +__contact__ = "jerome.kieffer@esrf.eu" +__license__ = "MIT" +__copyright__ = "2017 European Synchrotron Radiation Facility, Grenoble, France" +__date__ = "13/02/2018" + +import logging +import numpy + +import unittest +from ..common import ocl, _measure_workgroup_size +if ocl: + import pyopencl + import pyopencl.array +from ...test.utils import utilstest +from ..image import ImageProcessing +logger = logging.getLogger(__name__) +try: + from PIL import Image +except ImportError: + Image = None + + +@unittest.skipUnless(ocl and Image, "PyOpenCl/Image is missing") +class TestImage(unittest.TestCase): + + @classmethod + def setUpClass(cls): + super(TestImage, cls).setUpClass() + if ocl: + cls.ctx = ocl.create_context() + cls.lena = utilstest.getfile("lena.png") + cls.data = numpy.asarray(Image.open(cls.lena)) + cls.ip = ImageProcessing(ctx=cls.ctx, template=cls.data, profile=True) + + @classmethod + def tearDownClass(cls): + super(TestImage, cls).tearDownClass() + cls.ctx = None + cls.lena = None + cls.data = None + if logger.level <= logging.INFO: + logger.warning("\n".join(cls.ip.log_profile())) + cls.ip = None + + def setUp(self): + if ocl is None: + return + self.data = numpy.asarray(Image.open(self.lena)) + + def tearDown(self): + self.img = self.data = None + + @unittest.skipUnless(ocl, "pyopencl is missing") + def test_cast(self): + """ + tests the cast kernel + """ + res = self.ip.to_float(self.data) + self.assertEqual(res.shape, self.data.shape, "shape") + self.assertEqual(res.dtype, numpy.float32, "dtype") + self.assertEqual(abs(res - self.data).max(), 0, "content") + + @unittest.skipUnless(ocl, "pyopencl is missing") + def test_normalize(self): + """ + tests that all devices are working properly ... + """ + tmp = pyopencl.array.empty(self.ip.ctx, self.data.shape, "float32") + res = self.ip.to_float(self.data, out=tmp) + res2 = self.ip.normalize(tmp, -100, 100, copy=False) + norm = (self.data.astype(numpy.float32) - self.data.min()) / (self.data.max() - self.data.min()) + ref2 = 200 * norm - 100 + self.assertLess(abs(res2 - ref2).max(), 3e-5, "content") + + @unittest.skipUnless(ocl, "pyopencl is missing") + def test_histogram(self): + """ + Test on a greyscaled image ... of Lena :) + """ + lena_bw = (0.2126 * self.data[:, :, 0] + + 0.7152 * self.data[:, :, 1] + + 0.0722 * self.data[:, :, 2]).astype("int32") + ref = numpy.histogram(lena_bw, 255) + ip = ImageProcessing(ctx=self.ctx, template=lena_bw, profile=True) + res = ip.histogram(lena_bw, 255) + ip.log_profile() + delta = (ref[0] - res[0]) + deltap = (ref[1] - res[1]) + self.assertEqual(delta.sum(), 0, "errors are self-compensated") + self.assertLessEqual(abs(delta).max(), 1, "errors are small") + self.assertLessEqual(abs(deltap).max(), 3e-5, "errors on position are small: %s" % (abs(deltap).max())) + + +def suite(): + testSuite = unittest.TestSuite() + testSuite.addTest(TestImage("test_cast")) + testSuite.addTest(TestImage("test_normalize")) + testSuite.addTest(TestImage("test_histogram")) + return testSuite + + +if __name__ == '__main__': + unittest.main(defaultTest="suite") diff --git a/silx/opencl/test/test_projection.py b/silx/opencl/test/test_projection.py index c9a3a1c..7631128 100644 --- a/silx/opencl/test/test_projection.py +++ b/silx/opencl/test/test_projection.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__ = "19/01/2018" import time @@ -49,35 +49,31 @@ from silx.test.utils import utilstest logger = logging.getLogger(__name__) - @unittest.skipUnless(ocl and mako, "PyOpenCl is missing") class TestProj(unittest.TestCase): def setUp(self): if ocl is None: return - #~ if sys.platform.startswith('darwin'): - #~ self.skipTest("Projection is not implemented on CPU for OS X yet") + # ~ if sys.platform.startswith('darwin'): + # ~ self.skipTest("Projection is not implemented on CPU for OS X yet") self.getfiles() n_angles = self.sino.shape[0] self.proj = projection.Projection(self.phantom.shape, n_angles) - if self.proj.compiletime_workgroup_size < 16: + if self.proj.compiletime_workgroup_size < 16 * 16: self.skipTest("Current implementation of OpenCL projection is not supported on this platform yet") - def tearDown(self): self.phantom = None self.sino = None self.proj = None - def getfiles(self): # load 512x512 MRI phantom self.phantom = np.load(utilstest.getfile("Brain512.npz"))["data"] # load sinogram computed with PyHST self.sino = np.load(utilstest.getfile("sino500_pyhst.npz"))["data"] - def measure(self): "Common measurement of timings" t1 = time.time() @@ -89,7 +85,6 @@ class TestProj(unittest.TestCase): t2 = time.time() return t2 - t1, result - def compare(self, res): """ Compare a result with the reference reconstruction. @@ -100,7 +95,6 @@ class TestProj(unittest.TestCase): ref = self.sino return np.max(np.abs(res - ref)) - @unittest.skipUnless(ocl and mako, "pyopencl is missing") def test_proj(self): """ @@ -127,13 +121,11 @@ class TestProj(unittest.TestCase): self.assertTrue(errmax < 1.e-6, "Max error is too high") - def suite(): testSuite = unittest.TestSuite() testSuite.addTest(TestProj("test_proj")) return testSuite - if __name__ == '__main__': unittest.main(defaultTest="suite") |