def eval(self, pars): _ctx,queue = card() radius, length = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in OneDGpuCylinder.PD_PARS] #Get the weights for each radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True) #Perform the computation, with all weight points sum, norm, vol = 0.0, 0.0, 0.0, sub = pars['sldCyl'] - pars['sldSolv'] real = np.float32 if self.q.dtype == np.dtype('float32') else np.float64 #Loop over radius, length, theta, phi weight points for r in xrange(len(radius.weight)): for l in xrange(len(length.weight)): self.prg.OneDCylKernel(queue, self.q.shape, None, self.q_b, self.res_b, real(sub), real(length.value[l]), real(radius.value[r]), real(pars['scale']), np.uint32(self.q.size), real(pars['uplim']), real(pars['bolim'])) cl.enqueue_copy(queue, self.res, self.res_b) sum += radius.weight[r]*length.weight[l]*self.res*pow(radius.value[r],2)*length.value[l] vol += radius.weight[r]*length.weight[l] *pow(radius.value[r],2)*length.value[l] norm += radius.weight[r]*length.weight[l] if vol != 0.0 and norm != 0.0: sum *= norm/vol return sum/norm + pars['background']
def __init__(self, qx, qy, dtype='float32', cutoff=1e-5): ctx,_queue = card() src, qx, qy = set_precision(open('Kernel/Kernel-Ellipse_f.cpp').read(), qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy self.cutoff = cutoff self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) self.res_b = cl.Buffer(ctx, mf.READ_WRITE, self.qx.nbytes) self.res = np.empty_like(self.qx)
def __init__(self, qx, qy, dtype='float32', cutoff=1e-5): #create context, queue, and build program ctx,_queue = card() src, qx, qy = set_precision(open('Kernel/NR_BessJ1.cpp').read()+"\n"+open('Kernel/Kernel-CoreShellCylinder_f.cpp').read(), qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy self.cutoff = cutoff self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) self.res_b = cl.Buffer(ctx, mf.READ_WRITE, self.qx.nbytes) self.res = np.empty_like(self.qx)
def eval(self, pars): #b_n = radius_b # want, a_n = radius_a # want, etc _ctx,queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius_a, radius_b, axis_theta, axis_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuEllipse.PD_PARS] radius_a.value, radius_a.weight = radius_a.get_weights(pars['radius_a'], 0, 10000, True) radius_b.value, radius_b.weight = radius_b.get_weights(pars['radius_b'], 0, 10000, True) axis_theta.value, axis_theta.weight = axis_theta.get_weights(pars['axis_theta'], -90, 180, False) axis_phi.value, axis_phi.weight = axis_phi.get_weights(pars['axis_phi'], -90, 180, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) sub = pars['sldEll'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 #Loop over radius weight points for i in xrange(len(radius_a.weight)): #Loop over length weight points for j in xrange(len(radius_b.weight)): #Average over theta distribution vol += radius_a.weight[i]*radius_b.weight[j]*pow(radius_b.value[j], 2)*radius_a.value[i] norm_vol += radius_a.weight[i]*radius_b.weight[j] for k in xrange(len(axis_theta.weight)): #Average over phi distribution for l in xrange(len(axis_phi.weight)): #call the kernel self.prg.EllipsoidKernel(queue, self.qx.shape, None, real(radius_a.weight[i]), real(radius_b.weight[j]), real(axis_theta.weight[k]), real(axis_phi.weight[l]), real(pars['scale']), real(radius_a.value[i]), real(radius_b.value[j]), real(sub), real(axis_theta.value[k]), real(axis_phi.value[l]), self.qx_b, self.qy_b, self.res_b, np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) norm += radius_a.weight[i]*radius_b.weight[j]*axis_theta.weight[k]*axis_phi.weight[l] # Averaging in theta needs an extra normalization # factor to account for the sin(theta) term in the # integration (see documentation). # if size > 1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol/vol return sum/norm+pars['background']
def __init__(self, qx, qy, dtype='float32'): ctx,_queue = card() src, qx, qy = set_precision(open('Kernel-TriaxialEllipse.cpp').read(), qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy #buffers mf = cl.mem_flags self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes) self.res = np.empty_like(self.qx)
def eval(self, pars): _ctx,queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) rad_cyl,len_cyl,rad_cap,theta,phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCapCylinder.PD_PARS] rad_cyl.value, rad_cyl.weight = rad_cyl.get_weights(pars['rad_cyl'], 0, 10000, True) rad_cap.value, rad_cap.weight = rad_cap.get_weights(pars['rad_cap'], 0, 10000, True) len_cyl.value, len_cyl.weight = len_cyl.get_weights(pars['len_cyl'], 0, 10000, True) theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False) phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(theta.weight) sub = pars['sld_capcyl']-pars['sld_solv'] real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 for i in xrange(len(rad_cyl.weight)): for m in xrange(len(rad_cap.weight)): for j in xrange(len(len_cyl.weight)): hDist = -1.0*sqrt(fabs(rad_cap.value[m]*rad_cap.value[m]-rad_cyl.value[i]*rad_cyl.value[i])) vol_i = 4.0*atan(1.0)*rad_cyl.value[i]*rad_cyl.value[i]*len_cyl.value[j]+2.0*4.0*atan(1.0)/3.0\ *((rad_cap.value[m]-hDist)*(rad_cap.value[m]-hDist)*(2*rad_cap.value[m]+hDist)) vol += rad_cyl.weight[i]*len_cyl.weight[j]*rad_cap.weight[m]*vol_i norm_vol += rad_cyl.weight[i]*len_cyl.weight[j]*rad_cap.weight[m] for k in xrange(len(theta.weight)): for l in xrange(len(phi.weight)): self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(vol_i), real(hDist), real(rad_cyl.value[i]), real(rad_cap.value[m]), real(len_cyl.value[j]), real(theta.value[k]), real(phi.value[l]), real(sub), real(pars['scale']), real(phi.weight[l]), real(theta.weight[k]), real(rad_cap.weight[m]), real(rad_cyl.weight[i]), real(len_cyl.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size)) norm += rad_cyl.weight[i]*len_cyl.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l] #if size > 1: # norm /= asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol/vol return sum/norm + pars['background']
def __init__(self, q, dtype='float32'): #create context, queue, and build program ctx,_queue = card() trala = open('Kernel/NR_BessJ1.cpp').read()+"\n"+open('Kernel/OneDCyl_Kfun.cpp').read()+"\n"+open('Kernel/Kernel-OneDCylinder.cpp').read() src, self.q = set_precision_1d(trala, q, dtype=dtype) self.prg = cl.Program(ctx, src).build() #buffers mf = cl.mem_flags self.q_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.q) self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, q.nbytes) self.res = np.empty_like(self.q)
def eval(self, pars): tic() _ctx,queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius, length, cyl_theta, cyl_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCylinder.PD_PARS] #Get the weights for each radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True) cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights(pars['cyl_theta'], -np.inf, np.inf, False) cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights(pars['cyl_phi'], -np.inf, np.inf, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(cyl_theta.weight) sub = pars['sldCyl'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 #Loop over radius, length, theta, phi weight points for i in xrange(len(radius.weight)): for j in xrange(len(length.weight)): vol += radius.weight[i]*length.weight[j]*pow(radius.value[i], 2)*length.value[j] norm_vol += radius.weight[i]*length.weight[j] for k in xrange(len(cyl_theta.weight)): for l in xrange(len(cyl_phi.weight)): self.prg.CylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(sub), real(radius.value[i]), real(length.value[j]), real(pars['scale']), real(radius.weight[i]), real(length.weight[j]), real(cyl_theta.weight[k]), real(cyl_phi.weight[l]), real(cyl_theta.value[k]), real(cyl_phi.value[l]), np.uint32(self.qx.size), np.uint32(size)) norm += radius.weight[i]*length.weight[j]*cyl_theta.weight[k]*cyl_phi.weight[l] # if size > 1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol/vol print toc()*1000, self.qx.shape[0] return sum/norm+pars['background']
def eval(self, pars): _ctx,queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius, length, thickness, axis_phi, axis_theta = [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCoreShellCylinder.PD_PARS] radius.value, radius.weight = radius.get_weights(pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights(pars['length'], 0, 10000, True) thickness.value, thickness.weight = thickness.get_weights(pars['thickness'], 0, 10000, True) axis_phi.value, axis_phi.weight = axis_phi.get_weights(pars['axis_phi'], -90, 180, False) axis_theta.value, axis_theta.weight = axis_theta.get_weights(pars['axis_theta'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 for r in xrange(len(radius.weight)): for l in xrange(len(length.weight)): for th in xrange(len(thickness.weight)): vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ *(length.value[l]+2.0*thickness.value[th]) norm_vol += radius.weight[r]*length.weight[l]*thickness.weight[th] for at in xrange(len(axis_theta.weight)): for p in xrange(len(axis_phi.weight)): self.prg.CoreShellCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(axis_theta.value[at]), real(axis_phi.value[p]), real(thickness.value[th]), real(length.value[l]), real(radius.value[r]), real(pars['scale']), real(radius.weight[r]), real(length.weight[l]), real(thickness.weight[th]), real(axis_theta.weight[at]), real(axis_phi.weight[p]), real(pars['core_sld']), real(pars['shell_sld']), real(pars['solvent_sld']),np.uint32(size), np.uint32(self.qx.size)) norm += radius.weight[r]*length.weight[l]*thickness.weight[th]*axis_theta.weight[at]\ *axis_phi.weight[p] #if size>1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol/vol return sum/norm + pars['background']
def eval(self, pars): _ctx,queue = card() rad_cyl,length,rad_cap,theta,phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCapCylinder.PD_PARS] rad_cyl.value, rad_cyl.weight = rad_cyl.get_weights(pars['rad_cyl'], 0, 1000, True) rad_cap.value, rad_cap.weight = rad_cap.get_weights(pars['rad_cap'], 0, 1000, True) length.value, length.weight = length.get_weights(pars['length'], 0, 1000, True) theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False) phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(theta.weight) sub = pars['sld_capcyl']-pars['sld_solv'] real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 for i in xrange(len(rad_cyl.weight)): for m in xrange(len(rad_cap.weight)): for j in xrange(len(length.weight)): for k in xrange(len(theta.weight)): for l in xrange(len(phi.weight)): self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, self.vol_b, real(rad_cyl.value[i]), real(rad_cap.value[m]), real(length.value[j]), real(theta.value[k]), real(phi.value[l]), real(sub), real(pars['scale']), real(phi.weight[l]), real(theta.weight[k]), real(rad_cap.weight[m]), real(rad_cyl.weight[i]), real(length.weight[j]), np.uint32(self.qx.size), np.uint32(size), self.Gauss76W_b, self.Gauss76Z_b) cl.enqueue_copy(queue, self.res, self.res_b) cl.enqueue_copy(queue, self.vol_i, self.vol_b) sum += self.res vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*self.vol_i norm_vol += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m] norm += rad_cyl.weight[i]*length.weight[j]*rad_cap.weight[m]*theta.weight[k]*phi.weight[l] if size > 1: norm /= asin(1.0) if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol/vol return sum/norm + pars['background']
def __init__(self, q, dtype='float32'): #create context, queue, and build program ctx, _queue = card() trala = open('Kernel/NR_BessJ1.cpp').read() + "\n" + open( 'Kernel/OneDCyl_Kfun.cpp').read() + "\n" + open( 'Kernel/Kernel-OneDCylinder.cpp').read() src, self.q = set_precision_1d(trala, q, dtype=dtype) self.prg = cl.Program(ctx, src).build() #buffers mf = cl.mem_flags self.q_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.q) self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, q.nbytes) self.res = np.empty_like(self.q)
def __init__(self, qx, qy, dtype='float32', cutoff=1e-5): ctx, _queue = card() src, qx, qy = set_precision(open('Kernel/Kernel-Ellipse_f.cpp').read(), qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy self.cutoff = cutoff self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) self.res_b = cl.Buffer(ctx, mf.READ_WRITE, self.qx.nbytes) self.res = np.empty_like(self.qx)
def eval(self, pars): tic() ctx,queue = card() real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 loops, loop_lengths = make_loops(pars, dtype=self.qx.dtype) loops_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=loops) loops_l = cl.LocalMemory(len(loops.data)) self.prg.CylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, loops_b, loops_l, real(self.cutoff), real(pars['scale']), real(pars['background']), real(pars['sldCyl']-pars['sldSolv']), *[np.uint32(pn) for pn in loop_lengths]) cl.enqueue_copy(queue, self.res, self.res_b) print toc()*1000, self.qx.shape[0] return self.res
def __init__(self, qx, qy, dtype='float32'): ctx, _queue = card() src, qx, qy = set_precision( open('Kernel/Kernel-TriaxialEllipse.cpp').read(), qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy #buffers mf = cl.mem_flags self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes) self.res = np.empty_like(self.qx)
def eval(self, pars): _ctx, queue = card() radius, length = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in OneDGpuCylinder.PD_PARS] #Get the weights for each radius.value, radius.weight = radius.get_weights( pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights( pars['length'], 0, 10000, True) #Perform the computation, with all weight points sum, norm, vol = 0.0, 0.0, 0.0, sub = pars['sldCyl'] - pars['sldSolv'] real = np.float32 if self.q.dtype == np.dtype( 'float32') else np.float64 #Loop over radius, length, theta, phi weight points for r in xrange(len(radius.weight)): for l in xrange(len(length.weight)): self.prg.OneDCylKernel(queue, self.q.shape, None, self.q_b, self.res_b, real(sub), real(length.value[l]), real(radius.value[r]), real(pars['scale']), np.uint32(self.q.size), real(pars['uplim']), real(pars['bolim'])) cl.enqueue_copy(queue, self.res, self.res_b) sum += radius.weight[r] * length.weight[l] * self.res * pow( radius.value[r], 2) * length.value[l] vol += radius.weight[r] * length.weight[l] * pow( radius.value[r], 2) * length.value[l] norm += radius.weight[r] * length.weight[l] if vol != 0.0 and norm != 0.0: sum *= norm / vol return sum / norm + pars['background']
def __init__(self, qx, qy, dtype='float32', cutoff=1e-5): #create context, queue, and build program ctx, _queue = card() src, qx, qy = set_precision( open('Kernel/NR_BessJ1.cpp').read() + "\n" + open('Kernel/Kernel-CoreShellCylinder_f.cpp').read(), qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy self.cutoff = cutoff self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) self.res_b = cl.Buffer(ctx, mf.READ_WRITE, self.qx.nbytes) self.res = np.empty_like(self.qx)
def __init__(self, qx, qy, dtype='float32'): #create context, queue, and build program ctx,_queue = card() trala = open('NR_BessJ1.cpp').read()+"\n"+open('Capcyl_Kfun.cpp').read()+"\n"+open('Kernel-Cylinder.cpp').read() src, qx, qy = set_precision(trala, qx, qy, dtype=dtype) self.prg = cl.Program(ctx, src).build() self.qx, self.qy = qx, qy #buffers mf = cl.mem_flags self.qx_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qx) self.qy_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=self.qy) G, Z = Gauss76Wt, Gauss76Z self.Gauss76W_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=G) self.Gauss76Z_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=Z) self.res_b = cl.Buffer(ctx, mf.WRITE_ONLY, qx.nbytes) self.res = np.empty_like(self.qx) self.vol_i = float(0.0) self.vol_b = cl.Buffer(ctx, mf.WRITE_ONLY, self.vol_i.nbytes)
def eval(self, pars): tic() ctx, queue = card() real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 loops, loop_lengths = make_loops(pars, dtype=self.qx.dtype) loops_b = cl.Buffer(ctx, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=loops) loops_l = cl.LocalMemory(len(loops.data)) self.prg.CylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, loops_b, loops_l, real(self.cutoff), real(pars['scale']), real(pars['background']), real(pars['sldCyl'] - pars['sldSolv']), *[np.uint32(pn) for pn in loop_lengths]) cl.enqueue_copy(queue, self.res, self.res_b) print toc() * 1000, self.qx.shape[0] return self.res
def eval(self, pars): tic() _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius, length, cyl_theta, cyl_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCylinder.PD_PARS] #Get the weights for each radius.value, radius.weight = radius.get_weights( pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights( pars['length'], 0, 10000, True) cyl_theta.value, cyl_theta.weight = cyl_theta.get_weights( pars['cyl_theta'], -np.inf, np.inf, False) cyl_phi.value, cyl_phi.weight = cyl_phi.get_weights( pars['cyl_phi'], -np.inf, np.inf, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(cyl_theta.weight) sub = pars['sldCyl'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 #Loop over radius, length, theta, phi weight points for i in xrange(len(radius.weight)): for j in xrange(len(length.weight)): vol += radius.weight[i] * length.weight[j] * pow( radius.value[i], 2) * length.value[j] norm_vol += radius.weight[i] * length.weight[j] for k in xrange(len(cyl_theta.weight)): for l in xrange(len(cyl_phi.weight)): self.prg.CylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(sub), real(radius.value[i]), real(length.value[j]), real(pars['scale']), real(radius.weight[i]), real(length.weight[j]), real(cyl_theta.weight[k]), real(cyl_phi.weight[l]), real(cyl_theta.value[k]), real(cyl_phi.value[l]), np.uint32(self.qx.size), np.uint32(size)) norm += radius.weight[i] * length.weight[ j] * cyl_theta.weight[k] * cyl_phi.weight[l] # if size > 1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol print toc() * 1000, self.qx.shape[0] return sum / norm + pars['background']
def eval(self, pars): _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) rad_cyl,len_cyl,rad_cap,theta,phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuCapCylinder.PD_PARS] rad_cyl.value, rad_cyl.weight = rad_cyl.get_weights( pars['rad_cyl'], 0, 10000, True) rad_cap.value, rad_cap.weight = rad_cap.get_weights( pars['rad_cap'], 0, 10000, True) len_cyl.value, len_cyl.weight = len_cyl.get_weights( pars['len_cyl'], 0, 10000, True) theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False) phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(theta.weight) sub = pars['sld_capcyl'] - pars['sld_solv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 for i in xrange(len(rad_cyl.weight)): for m in xrange(len(rad_cap.weight)): for j in xrange(len(len_cyl.weight)): hDist = -1.0 * sqrt( fabs(rad_cap.value[m] * rad_cap.value[m] - rad_cyl.value[i] * rad_cyl.value[i])) vol_i = 4.0*atan(1.0)*rad_cyl.value[i]*rad_cyl.value[i]*len_cyl.value[j]+2.0*4.0*atan(1.0)/3.0\ *((rad_cap.value[m]-hDist)*(rad_cap.value[m]-hDist)*(2*rad_cap.value[m]+hDist)) vol += rad_cyl.weight[i] * len_cyl.weight[ j] * rad_cap.weight[m] * vol_i norm_vol += rad_cyl.weight[i] * len_cyl.weight[ j] * rad_cap.weight[m] for k in xrange(len(theta.weight)): for l in xrange(len(phi.weight)): self.prg.CapCylinderKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(vol_i), real(hDist), real(rad_cyl.value[i]), real(rad_cap.value[m]), real(len_cyl.value[j]), real(theta.value[k]), real(phi.value[l]), real(sub), real(pars['scale']), real(phi.weight[l]), real(theta.weight[k]), real(rad_cap.weight[m]), real(rad_cyl.weight[i]), real(len_cyl.weight[j]), real(theta.weight[k]), np.uint32(self.qx.size), np.uint32(size)) norm += rad_cyl.weight[i] * len_cyl.weight[ j] * rad_cap.weight[m] * theta.weight[ k] * phi.weight[l] #if size > 1: # norm /= asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) semi_axisA, semi_axisB, semi_axisC, axis_theta, axis_phi, axis_psi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuTriEllipse.PD_PARS] semi_axisA.value, semi_axisA.weight = semi_axisA.get_weights( pars['semi_axisA'], 0, 10000, True) semi_axisB.value, semi_axisB.weight = semi_axisB.get_weights( pars['semi_axisB'], 0, 10000, True) semi_axisC.value, semi_axisC.weight = semi_axisC.get_weights( pars['semi_axisC'], 0, 10000, True) axis_theta.value, axis_theta.weight = axis_theta.get_weights( pars['axis_theta'], -90, 180, False) axis_phi.value, axis_phi.weight = axis_phi.get_weights( pars['axis_phi'], -90, 180, False) axis_psi.value, axis_psi.weight = axis_psi.get_weights( pars['axis_psi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) sub = pars['sldEll'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 for a in xrange(len(semi_axisA.weight)): for b in xrange(len(semi_axisB.weight)): for c in xrange(len(semi_axisC.weight)): vol += semi_axisA.weight[a] * semi_axisB.weight[ b] * semi_axisC.weight[c] * semi_axisA.value[ a] * semi_axisB.value[b] * semi_axisC.value[c] norm_vol += semi_axisA.weight[a] * semi_axisB.weight[ b] * semi_axisC.weight[c] for t in xrange(len(axis_theta.weight)): for i in xrange(len(axis_phi.weight)): for s in xrange(len(axis_psi.weight)): self.prg.TriaxialEllipseKernel( queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(sub), real(pars['scale']), real(semi_axisA.value[a]), real(semi_axisB.value[b]), real(semi_axisC.value[c]), real(axis_phi.value[i]), real(axis_theta.value[t]), real(axis_psi.value[s]), real(semi_axisA.weight[a]), real(semi_axisB.weight[b]), real(semi_axisC.weight[c]), real(axis_psi.weight[s]), real(axis_phi.weight[i]), real(axis_theta.weight[t]), np.uint32(self.qx.size), np.uint32(size)) norm += semi_axisA.weight[ a] * semi_axisB.weight[ b] * semi_axisC.weight[ c] * axis_theta.weight[ t] * axis_phi.weight[ i] * axis_psi.weight[s] # if size > 1: # norm /= asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): _ctx,queue = card() axisA, axisB, axisC, theta, phi, psi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuTriEllipse.PD_PARS] axisA.value, axisA.weight = axisA.get_weights(pars['axisA'], 0, 1000, True) axisB.value, axisB.weight = axisB.get_weights(pars['axisB'], 0, 1000, True) axisC.value, axisC.weight = axisC.get_weights(pars['axisC'], 0, 1000, True) theta.value, theta.weight = theta.get_weights(pars['theta'], -90, 180, False) phi.value, phi.weight = phi.get_weights(pars['phi'], -90, 180, False) psi.value, psi.weight = psi.get_weights(pars['psi'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(theta.weight) sub = pars['sldEll'] - pars['sldSolv'] start_time = time() run_time = 0 real = np.float32 if self.qx.dtype == np.dtype('float32') else np.float64 print "Before kernel" print "The len of axisA.weight is ",len(axisA.weight) print "The len of axisB.weight is ",len(axisB.weight) print "The len of axisC.weight is ",len(axisC.weight) print "The len of theta.weight is ",len(theta.weight) print "The len of phi.weight is ",len(phi.weight) print "The len of psi.weight is ",len(psi.weight) print print print "The axisA.weight is ",(axisA.weight) print "The axisB.weight is ",(axisB.weight) print "The axisC.weight is ",(axisC.weight) print "The theta.weight is ",(theta.weight) print "The phi.weight is ",(phi.weight) print "The psi.weight is ",(psi.weight) for a in xrange(len(axisA.weight)): for b in xrange(len(axisB.weight)): for c in xrange(len(axisC.weight)): for t in xrange(len(theta.weight)): for i in xrange(len(phi.weight)): for s in xrange(len(psi.weight)): self.prg.TriaxialEllipseKernel(queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(sub), real(pars['scale']), real(axisA.value[a]), real(axisB.value[b]), real(axisC.value[c]), real(phi.value[i]), real(theta.value[t]), real(psi.value[s]), real(axisA.weight[a]), real(axisB.weight[b]), real(axisC.weight[c]), real(psi.weight[s]), real(phi.weight[i]), real(theta.weight[t]), np.uint32(self.qx.size), np.uint32(size)) queue.finish() run_time = time() - start_time cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*axisA.value[a]*axisB.value[b]*axisC.value[c] norm_vol += axisA.weight[a]*axisB.weight[b]*axisC.weight[c] norm += axisA.weight[a]*axisB.weight[b]*axisC.weight[c]*theta.weight[t]*phi.weight[i]*psi.weight[s] print run_time, "seconds it TOOK!!!!!!!!!!!!" if size > 1: norm /= asin(1.0) if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol/vol return sum/norm + pars['background']
def eval(self, pars): #b_n = radius_b # want, a_n = radius_a # want, etc _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius_a, radius_b, axis_theta, axis_phi = \ [GaussianDispersion(int(pars[base+'_pd_n']), pars[base+'_pd'], pars[base+'_pd_nsigma']) for base in GpuEllipse.PD_PARS] radius_a.value, radius_a.weight = radius_a.get_weights( pars['radius_a'], 0, 10000, True) radius_b.value, radius_b.weight = radius_b.get_weights( pars['radius_b'], 0, 10000, True) axis_theta.value, axis_theta.weight = axis_theta.get_weights( pars['axis_theta'], -90, 180, False) axis_phi.value, axis_phi.weight = axis_phi.get_weights( pars['axis_phi'], -90, 180, False) #Perform the computation, with all weight points sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) sub = pars['sldEll'] - pars['sldSolv'] real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 #Loop over radius weight points for i in xrange(len(radius_a.weight)): #Loop over length weight points for j in xrange(len(radius_b.weight)): #Average over theta distribution vol += radius_a.weight[i] * radius_b.weight[j] * pow( radius_b.value[j], 2) * radius_a.value[i] norm_vol += radius_a.weight[i] * radius_b.weight[j] for k in xrange(len(axis_theta.weight)): #Average over phi distribution for l in xrange(len(axis_phi.weight)): #call the kernel self.prg.EllipsoidKernel( queue, self.qx.shape, None, real(radius_a.weight[i]), real(radius_b.weight[j]), real(axis_theta.weight[k]), real(axis_phi.weight[l]), real(pars['scale']), real(radius_a.value[i]), real(radius_b.value[j]), real(sub), real(axis_theta.value[k]), real(axis_phi.value[l]), self.qx_b, self.qy_b, self.res_b, np.uint32(self.qx.size), np.uint32(len(axis_theta.weight))) norm += radius_a.weight[i] * radius_b.weight[ j] * axis_theta.weight[k] * axis_phi.weight[l] # Averaging in theta needs an extra normalization # factor to account for the sin(theta) term in the # integration (see documentation). # if size > 1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum += self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']
def eval(self, pars): _ctx, queue = card() self.res[:] = 0 cl.enqueue_copy(queue, self.res_b, self.res) radius, length, thickness, axis_phi, axis_theta = [ GaussianDispersion(int(pars[base + '_pd_n']), pars[base + '_pd'], pars[base + '_pd_nsigma']) for base in GpuCoreShellCylinder.PD_PARS ] radius.value, radius.weight = radius.get_weights( pars['radius'], 0, 10000, True) length.value, length.weight = length.get_weights( pars['length'], 0, 10000, True) thickness.value, thickness.weight = thickness.get_weights( pars['thickness'], 0, 10000, True) axis_phi.value, axis_phi.weight = axis_phi.get_weights( pars['axis_phi'], -90, 180, False) axis_theta.value, axis_theta.weight = axis_theta.get_weights( pars['axis_theta'], -90, 180, False) sum, norm, norm_vol, vol = 0.0, 0.0, 0.0, 0.0 size = len(axis_theta.weight) real = np.float32 if self.qx.dtype == np.dtype( 'float32') else np.float64 for r in xrange(len(radius.weight)): for l in xrange(len(length.weight)): for th in xrange(len(thickness.weight)): vol += radius.weight[r]*length.weight[l]*thickness.weight[th]*pow(radius.value[r]+thickness.value[th],2)\ *(length.value[l]+2.0*thickness.value[th]) norm_vol += radius.weight[r] * length.weight[ l] * thickness.weight[th] for at in xrange(len(axis_theta.weight)): for p in xrange(len(axis_phi.weight)): self.prg.CoreShellCylinderKernel( queue, self.qx.shape, None, self.qx_b, self.qy_b, self.res_b, real(axis_theta.value[at]), real(axis_phi.value[p]), real(thickness.value[th]), real(length.value[l]), real(radius.value[r]), real(pars['scale']), real(radius.weight[r]), real(length.weight[l]), real(thickness.weight[th]), real(axis_theta.weight[at]), real(axis_phi.weight[p]), real(pars['core_sld']), real(pars['shell_sld']), real(pars['solvent_sld']), np.uint32(size), np.uint32(self.qx.size)) norm += radius.weight[r]*length.weight[l]*thickness.weight[th]*axis_theta.weight[at]\ *axis_phi.weight[p] #if size>1: # norm /= math.asin(1.0) cl.enqueue_copy(queue, self.res, self.res_b) sum = self.res if vol != 0.0 and norm_vol != 0.0: sum *= norm_vol / vol return sum / norm + pars['background']