diff options
| author | Tomas Kulhanek <tomas.kulhanek@stfc.ac.uk> | 2019-02-21 02:10:14 -0500 | 
|---|---|---|
| committer | Tomas Kulhanek <tomas.kulhanek@stfc.ac.uk> | 2019-02-21 02:10:14 -0500 | 
| commit | 3caa686662f7d937cf7eb852dde437cd66e79a6e (patch) | |
| tree | 76088f5924ff9278e0a37140fce888cd89b84a7e /Wrappers/Python/conda-recipe | |
| parent | 8f2e86726669b9dadb3c788e0ea681d397a2eeb7 (diff) | |
| download | regularization-3caa686662f7d937cf7eb852dde437cd66e79a6e.tar.gz regularization-3caa686662f7d937cf7eb852dde437cd66e79a6e.tar.bz2 regularization-3caa686662f7d937cf7eb852dde437cd66e79a6e.tar.xz regularization-3caa686662f7d937cf7eb852dde437cd66e79a6e.zip  | |
restructured sources
Diffstat (limited to 'Wrappers/Python/conda-recipe')
| -rw-r--r-- | Wrappers/Python/conda-recipe/bld.bat | 20 | ||||
| -rw-r--r-- | Wrappers/Python/conda-recipe/build.sh | 17 | ||||
| -rw-r--r-- | Wrappers/Python/conda-recipe/conda_build_config.yaml | 9 | ||||
| -rw-r--r-- | Wrappers/Python/conda-recipe/meta.yaml | 40 | ||||
| -rwxr-xr-x | Wrappers/Python/conda-recipe/run_test.py | 819 | 
5 files changed, 0 insertions, 905 deletions
diff --git a/Wrappers/Python/conda-recipe/bld.bat b/Wrappers/Python/conda-recipe/bld.bat deleted file mode 100644 index 6c84355..0000000 --- a/Wrappers/Python/conda-recipe/bld.bat +++ /dev/null @@ -1,20 +0,0 @@ -IF NOT DEFINED CIL_VERSION ( -ECHO CIL_VERSION Not Defined. -exit 1 -) - -mkdir "%SRC_DIR%\ccpi" -ROBOCOPY /E "%RECIPE_DIR%\..\.." "%SRC_DIR%\ccpi" -ROBOCOPY /E "%RECIPE_DIR%\..\..\..\Core" "%SRC_DIR%\Core" -::cd %SRC_DIR%\ccpi\Python -cd %SRC_DIR% - -:: issue cmake to create setup.py -cmake -G "NMake Makefiles" %RECIPE_DIR%\..\..\..\ -DBUILD_PYTHON_WRAPPERS=ON -DCONDA_BUILD=ON -DBUILD_CUDA=OFF -DCMAKE_BUILD_TYPE="Release" -DLIBRARY_LIB="%CONDA_PREFIX%\lib" -DLIBRARY_INC="%CONDA_PREFIX%" -DCMAKE_INSTALL_PREFIX="%PREFIX%\Library"  - -::%PYTHON% setup-regularisers.py build_ext -::if errorlevel 1 exit 1 -::%PYTHON% setup-regularisers.py install -::if errorlevel 1 exit 1 -nmake install -if errorlevel 1 exit 1
\ No newline at end of file diff --git a/Wrappers/Python/conda-recipe/build.sh b/Wrappers/Python/conda-recipe/build.sh deleted file mode 100644 index 39c0f2c..0000000 --- a/Wrappers/Python/conda-recipe/build.sh +++ /dev/null @@ -1,17 +0,0 @@ - -mkdir "$SRC_DIR/ccpi" -cp -rv "$RECIPE_DIR/../.." "$SRC_DIR/ccpi" -cp -rv "$RECIPE_DIR/../../../Core" "$SRC_DIR/Core" - -cd $SRC_DIR -##cuda=off - -cmake -G "Unix Makefiles" $RECIPE_DIR/../../../ -DBUILD_PYTHON_WRAPPER=ON -DCONDA_BUILD=ON -DBUILD_CUDA=ON -DCMAKE_BUILD_TYPE="Release" -DLIBRARY_LIB=$CONDA_PREFIX/lib -DLIBRARY_INC=$CONDA_PREFIX -DCMAKE_INSTALL_PREFIX=$PREFIX - - -make install - -#$PYTHON setup-regularisers.py build_ext -#$PYTHON setup-regularisers.py install - - diff --git a/Wrappers/Python/conda-recipe/conda_build_config.yaml b/Wrappers/Python/conda-recipe/conda_build_config.yaml deleted file mode 100644 index fbe82dc..0000000 --- a/Wrappers/Python/conda-recipe/conda_build_config.yaml +++ /dev/null @@ -1,9 +0,0 @@ -python: -  - 2.7 # [not win] -  - 3.5 -  - 3.6 -#  - 3.7 -numpy: -  - 1.12 -  - 1.14 -  - 1.15 diff --git a/Wrappers/Python/conda-recipe/meta.yaml b/Wrappers/Python/conda-recipe/meta.yaml deleted file mode 100644 index 7435b2b..0000000 --- a/Wrappers/Python/conda-recipe/meta.yaml +++ /dev/null @@ -1,40 +0,0 @@ -package: -  name: ccpi-regulariser -  version: {{CIL_VERSION}} -   -build: -  preserve_egg_dir: False -  number: 0 -  script_env: -    - CIL_VERSION -   -test: -  files: -    - lena_gray_512.tif -  requires: -    - pillow=4.1.1 - -requirements: -  build: -    - python -    - numpy {{ numpy }} -    - setuptools -    - cython -    - vc 14 # [win and py36]  -    - vc 14 # [win and py35]  -    - vc 9  # [win and py27] -    - cmake  - -  run: -    - {{ pin_compatible('numpy', max_pin='x.x') }} -    - python -    - numpy -    - vc 14 # [win and py36]  -    - vc 14 # [win and py35]  -    - vc 9  # [win and py27] -    - libgcc-ng - -about: -  home: http://www.ccpi.ac.uk -  license:  BSD license -  summary: 'CCPi Core Imaging Library Quantification Toolbox' diff --git a/Wrappers/Python/conda-recipe/run_test.py b/Wrappers/Python/conda-recipe/run_test.py deleted file mode 100755 index 21f3216..0000000 --- a/Wrappers/Python/conda-recipe/run_test.py +++ /dev/null @@ -1,819 +0,0 @@ -import unittest
 -import numpy as np
 -import os
 -import timeit
 -from ccpi.filters.regularisers import ROF_TV, FGP_TV, SB_TV, TGV, LLT_ROF, FGP_dTV, NDF, Diff4th
 -from PIL import Image
 -
 -class TiffReader(object):
 -    def imread(self, filename):
 -        return np.asarray(Image.open(filename))
 -###############################################################################
 -def printParametersToString(pars):
 -        txt = r''
 -        for key, value in pars.items():
 -            if key== 'algorithm' :
 -                txt += "{0} = {1}".format(key, value.__name__)
 -            elif key == 'input':
 -                txt += "{0} = {1}".format(key, np.shape(value))
 -            elif key == 'refdata':
 -                txt += "{0} = {1}".format(key, np.shape(value))
 -            else:
 -                txt += "{0} = {1}".format(key, value)
 -            txt += '\n'
 -        return txt
 -def nrmse(im1, im2):
 -    rmse = np.sqrt(np.sum((im2 - im1) ** 2) / float(im1.size))
 -    max_val = max(np.max(im1), np.max(im2))
 -    min_val = min(np.min(im1), np.min(im2))
 -    return 1 - (rmse / (max_val - min_val))
 -    
 -def rmse(im1, im2):
 -    rmse = np.sqrt(np.sum((im1 - im2) ** 2) / float(im1.size))
 -    return rmse
 -###############################################################################
 -
 -class TestRegularisers(unittest.TestCase):
 -    
 -
 -    def test_ROF_TV_CPU_vs_GPU(self):
 -        #print ("tomas debug test function")
 -        print(__name__)
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("____________ROF-TV bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        # set parameters
 -        pars = {'algorithm': ROF_TV, \
 -        'input' : u0,\
 -        'regularisation_parameter':0.04,\
 -        'number_of_iterations': 2500,\
 -        'time_marching_parameter': 0.00002
 -        }
 -        print ("#############ROF TV CPU####################")
 -        start_time = timeit.default_timer()
 -        rof_cpu = ROF_TV(pars['input'],
 -                     pars['regularisation_parameter'],
 -                     pars['number_of_iterations'],
 -                     pars['time_marching_parameter'],'cpu')
 -        rms = rmse(Im, rof_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("##############ROF TV GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            rof_gpu = ROF_TV(pars['input'], 
 -                             pars['regularisation_parameter'],
 -                             pars['number_of_iterations'], 
 -                             pars['time_marching_parameter'],'gpu')
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -
 -        rms = rmse(Im, rof_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = ROF_TV
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-04
 -        diff_im = np.zeros(np.shape(rof_cpu))
 -        diff_im = abs(rof_cpu - rof_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum() , 1)
 -        
 -    def test_FGP_TV_CPU_vs_GPU(self):
 -        print(__name__)
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("____________FGP-TV bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        
 -        # set parameters
 -        pars = {'algorithm' : FGP_TV, \
 -                'input' : u0,\
 -                'regularisation_parameter':0.04, \
 -                'number_of_iterations' :1200 ,\
 -                'tolerance_constant':0.00001,\
 -                'methodTV': 0 ,\
 -                'nonneg': 0 ,\
 -                'printingOut': 0 
 -                }
 -                
 -        print ("#############FGP TV CPU####################")
 -        start_time = timeit.default_timer()
 -        fgp_cpu = FGP_TV(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['number_of_iterations'],
 -                      pars['tolerance_constant'], 
 -                      pars['methodTV'],
 -                      pars['nonneg'],
 -                      pars['printingOut'],'cpu')  
 -                     
 -                     
 -        rms = rmse(Im, fgp_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        
 -        print ("##############FGP TV GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            fgp_gpu = FGP_TV(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['number_of_iterations'],
 -                      pars['tolerance_constant'], 
 -                      pars['methodTV'],
 -                      pars['nonneg'],
 -                      pars['printingOut'],'gpu')
 -
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -
 -        rms = rmse(Im, fgp_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = FGP_TV
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-05
 -        diff_im = np.zeros(np.shape(fgp_cpu))
 -        diff_im = abs(fgp_cpu - fgp_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -
 -        self.assertLessEqual(diff_im.sum() , 1)
 -
 -    def test_SB_TV_CPU_vs_GPU(self):
 -        print(__name__)
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("____________SB-TV bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        
 -        # set parameters
 -        pars = {'algorithm' : SB_TV, \
 -                'input' : u0,\
 -                'regularisation_parameter':0.04, \
 -                'number_of_iterations' :150 ,\
 -                'tolerance_constant':1e-05,\
 -                'methodTV': 0 ,\
 -                'printingOut': 0 
 -                }
 -                
 -        print ("#############SB-TV CPU####################")
 -        start_time = timeit.default_timer()
 -        sb_cpu = SB_TV(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['number_of_iterations'],
 -                      pars['tolerance_constant'], 
 -                      pars['methodTV'],
 -                      pars['printingOut'],'cpu')  
 -                     
 -                     
 -        rms = rmse(Im, sb_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        
 -        print ("##############SB TV GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            
 -            sb_gpu = SB_TV(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['number_of_iterations'],
 -                      pars['tolerance_constant'], 
 -                      pars['methodTV'],
 -                      pars['printingOut'],'gpu')
 -
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -
 -        rms = rmse(Im, sb_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = SB_TV
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-05
 -        diff_im = np.zeros(np.shape(sb_cpu))
 -        diff_im = abs(sb_cpu - sb_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum(), 1)
 -
 -    def test_TGV_CPU_vs_GPU(self):
 -        print(__name__)
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("____________TGV bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        
 -        # set parameters
 -        pars = {'algorithm' : TGV, \
 -                'input' : u0,\
 -                'regularisation_parameter':0.04, \
 -                'alpha1':1.0,\
 -                'alpha0':2.0,\
 -                'number_of_iterations' :250 ,\
 -                'LipshitzConstant' :12 ,\
 -                }
 -                
 -        print ("#############TGV CPU####################")
 -        start_time = timeit.default_timer()
 -        tgv_cpu = TGV(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['alpha1'],
 -                      pars['alpha0'],
 -                      pars['number_of_iterations'],
 -                      pars['LipshitzConstant'],'cpu')
 -                     
 -        rms = rmse(Im, tgv_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        
 -        print ("##############TGV GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            tgv_gpu = TGV(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['alpha1'],
 -                      pars['alpha0'],
 -                      pars['number_of_iterations'],
 -                      pars['LipshitzConstant'],'gpu')
 -
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -
 -        rms = rmse(Im, tgv_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = TGV
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-05
 -        diff_im = np.zeros(np.shape(tgv_gpu))
 -        diff_im = abs(tgv_cpu - tgv_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum() , 1)
 -
 -    def test_LLT_ROF_CPU_vs_GPU(self):
 -        print(__name__)
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("____________LLT-ROF bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        
 -        # set parameters
 -        pars = {'algorithm' : LLT_ROF, \
 -                'input' : u0,\
 -                'regularisation_parameterROF':0.04, \
 -                'regularisation_parameterLLT':0.01, \
 -                'number_of_iterations' :1000 ,\
 -                'time_marching_parameter' :0.0001 ,\
 -                }
 -                
 -        print ("#############LLT- ROF CPU####################")
 -        start_time = timeit.default_timer()
 -        lltrof_cpu = LLT_ROF(pars['input'], 
 -                      pars['regularisation_parameterROF'],
 -                      pars['regularisation_parameterLLT'],
 -                      pars['number_of_iterations'],
 -                      pars['time_marching_parameter'],'cpu')
 -        
 -        rms = rmse(Im, lltrof_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("#############LLT- ROF GPU####################")
 -        start_time = timeit.default_timer()
 -        try:
 -            lltrof_gpu = LLT_ROF(pars['input'], 
 -                      pars['regularisation_parameterROF'],
 -                      pars['regularisation_parameterLLT'],
 -                      pars['number_of_iterations'],
 -                      pars['time_marching_parameter'],'gpu')
 -        
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -
 -        rms = rmse(Im, lltrof_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = LLT_ROF
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-04
 -        diff_im = np.zeros(np.shape(lltrof_gpu))
 -        diff_im = abs(lltrof_cpu - lltrof_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum(), 1)
 -
 -    def test_NDF_CPU_vs_GPU(self):
 -        print(__name__)
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("_______________NDF bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        
 -        # set parameters
 -        pars = {'algorithm' : NDF, \
 -                'input' : u0,\
 -                'regularisation_parameter':0.06, \
 -                'edge_parameter':0.04,\
 -                'number_of_iterations' :1000 ,\
 -                'time_marching_parameter':0.025,\
 -                'penalty_type':  1
 -                }
 -                
 -        print ("#############NDF CPU####################")
 -        start_time = timeit.default_timer()
 -        ndf_cpu = NDF(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['edge_parameter'], 
 -                      pars['number_of_iterations'],
 -                      pars['time_marching_parameter'], 
 -                      pars['penalty_type'],'cpu')
 -                     
 -        rms = rmse(Im, ndf_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        
 -        print ("##############NDF GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            ndf_gpu = NDF(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['edge_parameter'], 
 -                      pars['number_of_iterations'],
 -                      pars['time_marching_parameter'], 
 -                      pars['penalty_type'],'gpu')
 -                     
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -        rms = rmse(Im, ndf_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = NDF
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-05
 -        diff_im = np.zeros(np.shape(ndf_cpu))
 -        diff_im = abs(ndf_cpu - ndf_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum(), 1)
 -
 -        
 -    def test_Diff4th_CPU_vs_GPU(self):
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("___Anisotropic Diffusion 4th Order (2D)____")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        # set parameters
 -        pars = {'algorithm' : Diff4th, \
 -        'input' : u0,\
 -        'regularisation_parameter':3.5, \
 -        'edge_parameter':0.02,\
 -        'number_of_iterations' :500 ,\
 -        'time_marching_parameter':0.001
 -        }
 -        
 -        print ("#############Diff4th CPU####################")
 -        start_time = timeit.default_timer()
 -        diff4th_cpu = Diff4th(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['edge_parameter'], 
 -                      pars['number_of_iterations'],
 -                      pars['time_marching_parameter'],'cpu')
 -                     
 -        rms = rmse(Im, diff4th_cpu)
 -        pars['rmse'] = rms
 -
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("##############Diff4th GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            diff4th_gpu = Diff4th(pars['input'], 
 -                      pars['regularisation_parameter'],
 -                      pars['edge_parameter'], 
 -                      pars['number_of_iterations'],
 -                      pars['time_marching_parameter'], 'gpu')
 -                     
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -        rms = rmse(Im, diff4th_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = Diff4th
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-05
 -        diff_im = np.zeros(np.shape(diff4th_cpu))
 -        diff_im = abs(diff4th_cpu - diff4th_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum() , 1)
 -
 -    def test_FDGdTV_CPU_vs_GPU(self):
 -        filename = os.path.join("lena_gray_512.tif")
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        
 -        Im = Im/255
 -        perc = 0.05
 -        u0 = Im + np.random.normal(loc = 0 ,
 -                                          scale = perc * Im , 
 -                                          size = np.shape(Im))
 -        u_ref = Im + np.random.normal(loc = 0 ,
 -                                          scale = 0.01 * Im , 
 -                                          size = np.shape(Im))
 -        
 -        # map the u0 u0->u0>0
 -        # f = np.frompyfunc(lambda x: 0 if x < 0 else x, 1,1)
 -        u0 = u0.astype('float32')
 -        u_ref = u_ref.astype('float32')
 -        
 -
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("____________FGP-dTV bench___________________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        
 -        # set parameters
 -        pars = {'algorithm' : FGP_dTV, \
 -                'input' : u0,\
 -                'refdata' : u_ref,\
 -                'regularisation_parameter':0.04, \
 -                'number_of_iterations' :1000 ,\
 -                'tolerance_constant':1e-07,\
 -                'eta_const':0.2,\
 -                'methodTV': 0 ,\
 -                'nonneg': 0 ,\
 -                'printingOut': 0 
 -                }
 -                
 -        print ("#############FGP dTV CPU####################")
 -        start_time = timeit.default_timer()
 -        fgp_dtv_cpu = FGP_dTV(pars['input'], 
 -                      pars['refdata'], 
 -                      pars['regularisation_parameter'],
 -                      pars['number_of_iterations'],
 -                      pars['tolerance_constant'], 
 -                      pars['eta_const'], 
 -                      pars['methodTV'],
 -                      pars['nonneg'],
 -                      pars['printingOut'],'cpu')
 -                     
 -                     
 -        rms = rmse(Im, fgp_dtv_cpu)
 -        pars['rmse'] = rms
 -        
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("##############FGP dTV GPU##################")
 -        start_time = timeit.default_timer()
 -        try:
 -            fgp_dtv_gpu = FGP_dTV(pars['input'], 
 -                      pars['refdata'], 
 -                      pars['regularisation_parameter'],
 -                      pars['number_of_iterations'],
 -                      pars['tolerance_constant'], 
 -                      pars['eta_const'], 
 -                      pars['methodTV'],
 -                      pars['nonneg'],
 -                      pars['printingOut'],'gpu')
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -        rms = rmse(Im, fgp_dtv_gpu)
 -        pars['rmse'] = rms
 -        pars['algorithm'] = FGP_dTV
 -        txtstr = printParametersToString(pars)
 -        txtstr += "%s = %.3fs" % ('elapsed time',timeit.default_timer() - start_time)
 -        print (txtstr)
 -        print ("--------Compare the results--------")
 -        tolerance = 1e-05
 -        diff_im = np.zeros(np.shape(fgp_dtv_cpu))
 -        diff_im = abs(fgp_dtv_cpu - fgp_dtv_gpu)
 -        diff_im[diff_im > tolerance] = 1
 -        self.assertLessEqual(diff_im.sum(), 1)
 -
 -    def test_cpu_ROF_TV(self):
 -        #filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
 -        
 -        filename = os.path.join("lena_gray_512.tif")
 -
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        Im = Im/255
 -        
 -        """
 -        # read noiseless image
 -        Im = plt.imread(filename)
 -        Im = np.asarray(Im, dtype='float32')
 -        """
 -        tolerance = 1e-05
 -        rms_rof_exp = 8.313131464999238e-05 #expected value for ROF model
 -
 -        # set parameters for ROF-TV
 -        pars_rof_tv = {'algorithm': ROF_TV, \
 -                            'input' : Im,\
 -                            'regularisation_parameter':0.04,\
 -                            'number_of_iterations': 50,\
 -                            'time_marching_parameter': 0.00001
 -                            }
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("_________testing ROF-TV (2D, CPU)__________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        rof_cpu = ROF_TV(pars_rof_tv['input'],
 -             pars_rof_tv['regularisation_parameter'],
 -             pars_rof_tv['number_of_iterations'],
 -             pars_rof_tv['time_marching_parameter'],'cpu')
 -        rms_rof = rmse(Im, rof_cpu)
 -        
 -        # now compare obtained rms with the expected value
 -        self.assertLess(abs(rms_rof-rms_rof_exp) , tolerance)
 -    def test_cpu_FGP_TV(self):
 -        #filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
 -        
 -        filename = os.path.join("lena_gray_512.tif")
 -
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        Im = Im/255
 -        """
 -        # read noiseless image
 -        Im = plt.imread(filename)
 -        Im = np.asarray(Im, dtype='float32')
 -        """
 -        tolerance = 1e-05
 -        rms_fgp_exp = 0.019152347 #expected value for FGP model
 -        
 -        pars_fgp_tv = {'algorithm' : FGP_TV, \
 -                            'input' : Im,\
 -                            'regularisation_parameter':0.04, \
 -                            'number_of_iterations' :50 ,\
 -                            'tolerance_constant':1e-06,\
 -                            'methodTV': 0 ,\
 -                            'nonneg': 0 ,\
 -                            'printingOut': 0 
 -                            }
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("_________testing FGP-TV (2D, CPU)__________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        fgp_cpu = FGP_TV(pars_fgp_tv['input'], 
 -              pars_fgp_tv['regularisation_parameter'],
 -              pars_fgp_tv['number_of_iterations'],
 -              pars_fgp_tv['tolerance_constant'], 
 -              pars_fgp_tv['methodTV'],
 -              pars_fgp_tv['nonneg'],
 -              pars_fgp_tv['printingOut'],'cpu')  
 -        rms_fgp = rmse(Im, fgp_cpu)
 -        # now compare obtained rms with the expected value
 -        self.assertLess(abs(rms_fgp-rms_fgp_exp) , tolerance)
 -
 -    def test_gpu_ROF(self):
 -        #filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
 -        filename = os.path.join("lena_gray_512.tif")
 -
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)
 -        Im = np.asarray(Im, dtype='float32')
 -        Im = Im/255
 -        
 -        tolerance = 1e-05
 -        rms_rof_exp = 8.313131464999238e-05 #expected value for ROF model
 -        
 -        # set parameters for ROF-TV
 -        pars_rof_tv = {'algorithm': ROF_TV, \
 -                            'input' : Im,\
 -                            'regularisation_parameter':0.04,\
 -                            'number_of_iterations': 50,\
 -                            'time_marching_parameter': 0.00001
 -                            }
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("_________testing ROF-TV (2D, GPU)__________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        try:
 -            rof_gpu = ROF_TV(pars_rof_tv['input'],
 -             pars_rof_tv['regularisation_parameter'],
 -             pars_rof_tv['number_of_iterations'],
 -             pars_rof_tv['time_marching_parameter'],'gpu')
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -
 -        rms_rof = rmse(Im, rof_gpu)
 -        # now compare obtained rms with the expected value
 -        self.assertLess(abs(rms_rof-rms_rof_exp) , tolerance)
 -    
 -    def test_gpu_FGP(self):
 -        #filename = os.path.join(".." , ".." , ".." , "data" ,"testLena.npy")
 -        filename = os.path.join("lena_gray_512.tif")
 -
 -        plt = TiffReader()
 -        # read image
 -        Im = plt.imread(filename)                     
 -        Im = np.asarray(Im, dtype='float32')
 -        Im = Im/255
 -        tolerance = 1e-05
 -        
 -        rms_fgp_exp = 0.019152347 #expected value for FGP model
 -        
 -        # set parameters for FGP-TV
 -        pars_fgp_tv = {'algorithm' : FGP_TV, \
 -                            'input' : Im,\
 -                            'regularisation_parameter':0.04, \
 -                            'number_of_iterations' :50 ,\
 -                            'tolerance_constant':1e-06,\
 -                            'methodTV': 0 ,\
 -                            'nonneg': 0 ,\
 -                            'printingOut': 0 
 -                            }
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        print ("_________testing FGP-TV (2D, GPU)__________")
 -        print ("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
 -        try:
 -            fgp_gpu = FGP_TV(pars_fgp_tv['input'], 
 -              pars_fgp_tv['regularisation_parameter'],
 -              pars_fgp_tv['number_of_iterations'],
 -              pars_fgp_tv['tolerance_constant'], 
 -              pars_fgp_tv['methodTV'],
 -              pars_fgp_tv['nonneg'],
 -              pars_fgp_tv['printingOut'],'gpu')  
 -        except ValueError as ve:
 -            self.skipTest("Results not comparable. GPU computing error.")
 -        rms_fgp = rmse(Im, fgp_gpu)
 -        # now compare obtained rms with the expected value
 -
 -        self.assertLess(abs(rms_fgp-rms_fgp_exp) , tolerance)
 -
 -if __name__ == '__main__':
 -    unittest.main()
  | 
