def test_FDGdTV_CPU_vs_GPU(self):
        #filename = os.path.join("test","lena_gray_512.tif")
        #plt = TiffReader()
        # read image
        filename = os.path.join("test","test_imageLena.bin")
        plt = BinReader()
        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.02, \
        'number_of_iterations' :500 ,\
        'tolerance_constant':0.0,\
        'eta_const':0.2,\
        'methodTV': 0 ,\
        'nonneg': 0}

        print ("#############FGP dTV CPU####################")
        start_time = timeit.default_timer()
        (fgp_dtv_cpu,info_vec_cpu) = FGP_dTV(pars['input'],
              pars['refdata'],
              pars['regularisation_parameter'],
              pars['number_of_iterations'],
              pars['tolerance_constant'],
              pars['eta_const'],
              pars['methodTV'],
              pars['nonneg'],'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,info_vec_gpu) = FGP_dTV(pars['input'],
              pars['refdata'],
              pars['regularisation_parameter'],
              pars['number_of_iterations'],
              pars['tolerance_constant'],
              pars['eta_const'],
              pars['methodTV'],
              pars['nonneg'],'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_Diff4th_CPU_vs_GPU(self):
        #filename = os.path.join("test","lena_gray_512.tif")
        #plt = TiffReader()
        # read image
        filename = os.path.join("test","test_imageLena.bin")
        plt = BinReader()
        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':0.8, \
        'edge_parameter':0.02,\
        'number_of_iterations' :1000 ,\
        'time_marching_parameter':0.0001,\
        'tolerance_constant':0.0}

        print ("#############Diff4th CPU####################")
        start_time = timeit.default_timer()
        (diff4th_cpu,info_vec_cpu) = Diff4th(pars['input'],
              pars['regularisation_parameter'],
              pars['edge_parameter'],
              pars['number_of_iterations'],
              pars['time_marching_parameter'],
              pars['tolerance_constant'],'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,info_vec_gpu) = Diff4th(pars['input'],
              pars['regularisation_parameter'],
              pars['edge_parameter'],
              pars['number_of_iterations'],
              pars['time_marching_parameter'],
              pars['tolerance_constant'],'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)