Changeset a503bfd in sasmodels for compare.py


Ignore:
Timestamp:
Feb 16, 2015 5:41:55 PM (9 years ago)
Author:
pkienzle
Branches:
master, core_shell_microgels, costrafo411, magnetic_model, release_v0.94, release_v0.95, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
Children:
a1542aae, 373d1b6
Parents:
d547f16
Message:

move sasview→sasmodels conversion info to model definition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • compare.py

    rd547f16 ra503bfd  
    156156    return data, index 
    157157 
    158 def compare(name, pars, Ncpu, Ngpu, opts, set_pars): 
     158def compare(name, pars, Ncpu, Nocl, opts, set_pars): 
    159159    opt_values = dict(split 
    160160                      for s in opts for split in ((s.split('='),)) 
     
    185185 
    186186    # OpenCl calculation 
    187     if Ngpu > 0: 
    188         gpu, gpu_time = eval_opencl(name, pars, data, dtype, Ngpu) 
    189         print "opencl t=%.1f ms, intensity=%.0f"%(gpu_time, sum(gpu[index])) 
    190         #print max(gpu), min(gpu) 
     187    if Nocl > 0: 
     188        ocl, ocl_time = eval_opencl(name, pars, data, dtype, Nocl) 
     189        print "opencl t=%.1f ms, intensity=%.0f"%(ocl_time, sum(ocl[index])) 
     190        #print max(ocl), min(ocl) 
    191191 
    192192    # ctypes/sasview calculation 
     
    201201 
    202202    # Compare, but only if computing both forms 
    203     if Ngpu > 0 and Ncpu > 0: 
    204         #print "speedup %.2g"%(cpu_time/gpu_time) 
    205         #print "max |gpu/cpu|", max(abs(gpu/cpu)), "%.15g"%max(abs(gpu)), "%.15g"%max(abs(cpu)) 
    206         #cpu *= max(gpu/cpu) 
    207         resid, relerr = np.zeros_like(gpu), np.zeros_like(gpu) 
    208         resid[index] = (gpu - cpu)[index] 
     203    if Nocl > 0 and Ncpu > 0: 
     204        #print "speedup %.2g"%(cpu_time/ocl_time) 
     205        #print "max |ocl/cpu|", max(abs(ocl/cpu)), "%.15g"%max(abs(ocl)), "%.15g"%max(abs(cpu)) 
     206        #cpu *= max(ocl/cpu) 
     207        resid, relerr = np.zeros_like(ocl), np.zeros_like(ocl) 
     208        resid[index] = (ocl - cpu)[index] 
    209209        relerr[index] = resid[index]/cpu[index] 
    210210        #bad = (relerr>1e-4) 
    211         #print relerr[bad],cpu[bad],gpu[bad],data.qx_data[bad],data.qy_data[bad] 
     211        #print relerr[bad],cpu[bad],ocl[bad],data.qx_data[bad],data.qy_data[bad] 
    212212        print "max(|ocl-%s|)"%comp, max(abs(resid[index])) 
    213213        print "max(|(ocl-%s)/%s|)"%(comp,comp), max(abs(relerr[index])) 
     
    220220    import matplotlib.pyplot as plt 
    221221    if Ncpu > 0: 
    222         if Ngpu > 0: plt.subplot(131) 
     222        if Nocl > 0: plt.subplot(131) 
    223223        plot_data(data, cpu, scale='log') 
    224224        plt.title("%s t=%.1f ms"%(comp,cpu_time)) 
    225     if Ngpu > 0: 
     225    if Nocl > 0: 
    226226        if Ncpu > 0: plt.subplot(132) 
    227         plot_data(data, gpu, scale='log') 
    228         plt.title("opencl t=%.1f ms"%gpu_time) 
    229     if Ncpu > 0 and Ngpu > 0: 
     227        plot_data(data, ocl, scale='log') 
     228        plt.title("opencl t=%.1f ms"%ocl_time) 
     229    if Ncpu > 0 and Nocl > 0: 
    230230        plt.subplot(133) 
    231231        err = resid if '-abs' in opts else relerr 
    232232        errstr = "abs err" if '-abs' in opts else "rel err" 
    233         #err,errstr = gpu/cpu,"ratio" 
     233        #err,errstr = ocl/cpu,"ratio" 
    234234        plot_data(data, err, scale='linear') 
    235235        plt.title("max %s = %.3g"%(errstr, max(abs(err[index])))) 
    236236    if is2D: plt.colorbar() 
    237237 
    238     if Ncpu > 0 and Ngpu > 0 and '-hist' in opts: 
     238    if Ncpu > 0 and Nocl > 0 and '-hist' in opts: 
    239239        plt.figure() 
    240240        v = relerr[index] 
Note: See TracChangeset for help on using the changeset viewer.