Changeset e930946 in sasmodels


Ignore:
Timestamp:
Mar 3, 2015 2:07:47 PM (9 years ago)
Author:
Doucet, Mathieu <doucetm@…>
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:
de0c4ba
Parents:
c85db69 (diff), 49f92c1 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge branch 'master' of https://github.com/SasView/sasmodels

Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extra/pylint.rc

    rc85db69 re930946  
    261261# (useful for modules/projects where namespaces are manipulated during runtime 
    262262# and thus existing member attributes cannot be deduced by static analysis 
    263 ignored-modules=numpy 
     263ignored-modules=numpy,np 
    264264 
    265265# List of classes names for which member attributes should not be checked 
  • sasmodels/kernelcl.py

    r664c8e7 rc85db69  
    3232    context = cl.create_some_context(interactive=False) 
    3333    del context 
    34 except Exception,exc: 
     34except Exception, exc: 
    3535    warnings.warn(str(exc)) 
    3636    raise RuntimeError("OpenCL not available") 
     
    3939 
    4040from . import generate 
    41 from .kernelpy import PyInput, PyModel 
     41from .kernelpy import PyModel 
    4242 
    4343F64_DEFS = """\ 
     
    6363    """ 
    6464    source, info = generate.make(kernel_module) 
    65     if callable(info.get('Iq',None)): 
     65    if callable(info.get('Iq', None)): 
    6666        return PyModel(info) 
    6767    ## for debugging, save source to a .cl file, edit it, and reload as model 
     
    110110    device.min_data_type_align_size//4. 
    111111    """ 
    112     remainder = vector.size%boundary 
     112    remainder = vector.size % boundary 
    113113    if remainder != 0: 
    114114        size = vector.size + (boundary - remainder) 
    115         vector = np.hstack((vector, [extra]*(size-vector.size))) 
     115        vector = np.hstack((vector, [extra] * (size - vector.size))) 
    116116    return np.ascontiguousarray(vector, dtype=dtype) 
    117117 
     
    126126    """ 
    127127    dtype = np.dtype(dtype) 
    128     if dtype==generate.F64 and not all(has_double(d) for d in context.devices): 
     128    if dtype == generate.F64 and not all(has_double(d) for d in context.devices): 
    129129        raise RuntimeError("Double precision not supported for devices") 
    130130 
     
    135135    if context.devices[0].type == cl.device_type.GPU: 
    136136        header += "#define USE_SINCOS\n" 
    137     program  = cl.Program(context, header+source).build() 
     137    program = cl.Program(context, header + source).build() 
    138138    return program 
    139139 
     
    173173        try: 
    174174            self.context = cl.create_some_context(interactive=False) 
    175         except Exception,exc: 
     175        except Exception, exc: 
    176176            warnings.warn(str(exc)) 
    177177            warnings.warn("pyopencl.create_some_context() failed") 
     
    230230        self.__dict__ = state.copy() 
    231231 
    232     def __call__(self, input): 
    233         if self.dtype != input.dtype: 
     232    def __call__(self, input_value): 
     233        if self.dtype != input_value.dtype: 
    234234            raise TypeError("data and kernel have different types") 
    235235        if self.program is None: 
    236             self.program = environment().compile_program(self.info['name'],self.source, self.dtype) 
    237         kernel_name = generate.kernel_name(self.info, input.is_2D) 
     236            self.program = environment().compile_program(self.info['name'], self.source, self.dtype) 
     237        kernel_name = generate.kernel_name(self.info, input_value.is_2D) 
    238238        kernel = getattr(self.program, kernel_name) 
    239         return GpuKernel(kernel, self.info, input) 
     239        return GpuKernel(kernel, self.info, input_value) 
    240240 
    241241    def release(self): 
     
    285285        self.q_vectors = [_stretch_input(q, self.dtype, 32) for q in q_vectors] 
    286286        self.q_buffers = [ 
    287             cl.Buffer(env.context,  mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=q) 
     287            cl.Buffer(env.context, mf.READ_ONLY | mf.COPY_HOST_PTR, hostbuf=q) 
    288288            for q in self.q_vectors 
    289289        ] 
     
    320320        self.res = np.empty(input.nq, input.dtype) 
    321321        dim = '2d' if input.is_2D else '1d' 
    322         self.fixed_pars = info['partype']['fixed-'+dim] 
    323         self.pd_pars = info['partype']['pd-'+dim] 
     322        self.fixed_pars = info['partype']['fixed-' + dim] 
     323        self.pd_pars = info['partype']['pd-' + dim] 
    324324 
    325325        # Inputs and outputs for each kernel call 
     
    327327        env = environment() 
    328328        self.loops_b = [cl.Buffer(env.context, mf.READ_WRITE, 
    329                                   2*MAX_LOOPS*input.dtype.itemsize) 
     329                                  2 * MAX_LOOPS * input.dtype.itemsize) 
    330330                        for _ in env.queues] 
    331331        self.res_b = [cl.Buffer(env.context, mf.READ_WRITE, 
    332                                 input.global_size[0]*input.dtype.itemsize) 
     332                                input.global_size[0] * input.dtype.itemsize) 
    333333                      for _ in env.queues] 
    334334 
     
    344344            cutoff = real(cutoff) 
    345345            loops_N = [np.uint32(len(p[0])) for p in pd_pars] 
    346             loops = np.hstack(pd_pars) if pd_pars else np.empty(0,dtype=self.input.dtype) 
     346            loops = np.hstack(pd_pars) if pd_pars else np.empty(0, dtype=self.input.dtype) 
    347347            loops = np.ascontiguousarray(loops.T, self.input.dtype).flatten() 
    348348            #print "loops",Nloops, loops 
     
    350350            #import sys; print >>sys.stderr,"opencl eval",pars 
    351351            #print "opencl eval",pars 
    352             if len(loops) > 2*MAX_LOOPS: 
     352            if len(loops) > 2 * MAX_LOOPS: 
    353353                raise ValueError("too many polydispersity points") 
    354354 
  • sasmodels/kernelpy.py

    rf734e7d rc85db69  
    11import numpy as np 
    2 from numpy import pi, sin, cos, sqrt 
    3  
    4 from .generate import F32, F64 
     2from numpy import pi, cos 
     3 
     4from .generate import F64 
    55 
    66class PyModel(object): 
    77    def __init__(self, info): 
    88        self.info = info 
    9     def __call__(self, input): 
    10         kernel = self.info['Iqxy'] if input.is_2D else self.info['Iq'] 
    11         return PyKernel(kernel, self.info, input) 
     9    def __call__(self, input_value): 
     10        kernel = self.info['Iqxy'] if input_value.is_2D else self.info['Iq'] 
     11        return PyKernel(kernel, self.info, input_value) 
    1212    def make_input(self, q_vectors): 
    1313        return PyInput(q_vectors, dtype=F64) 
     
    3838        self.dtype = dtype 
    3939        self.is_2D = (len(q_vectors) == 2) 
    40         self.q_vectors = [np.ascontiguousarray(q,self.dtype) for q in q_vectors] 
     40        self.q_vectors = [np.ascontiguousarray(q, self.dtype) for q in q_vectors] 
    4141        self.q_pointers = [q.ctypes.data for q in q_vectors] 
    4242 
     
    7373            if dim == '2d': 
    7474                def vector_kernel(qx, qy, *args): 
    75                     return np.array([kernel(qxi,qyi,*args) for qxi,qyi in zip(qx,qy)]) 
     75                    return np.array([kernel(qxi, qyi, *args) for qxi, qyi in zip(qx, qy)]) 
    7676            else: 
    7777                def vector_kernel(q, *args): 
    78                     return np.array([kernel(qi,*args) for qi in q]) 
     78                    return np.array([kernel(qi, *args) for qi in q]) 
    7979            self.kernel = vector_kernel 
    8080        else: 
    8181            self.kernel = kernel 
    82         fixed_pars = info['partype']['fixed-'+dim] 
    83         pd_pars = info['partype']['pd-'+dim] 
     82        fixed_pars = info['partype']['fixed-' + dim] 
     83        pd_pars = info['partype']['pd-' + dim] 
    8484        vol_pars = info['partype']['volume'] 
    8585 
     
    8787        pars = [p[0] for p in info['parameters'][2:]] 
    8888        offset = len(self.input.q_vectors) 
    89         self.args = self.input.q_vectors + [None]*len(pars) 
    90         self.fixed_index = np.array([pars.index(p)+offset for p in fixed_pars[2:] ]) 
    91         self.pd_index = np.array([pars.index(p)+offset for p in pd_pars]) 
    92         self.vol_index = np.array([pars.index(p)+offset for p in vol_pars]) 
    93         try: self.theta_index = pars.index('theta')+offset 
     89        self.args = self.input.q_vectors + [None] * len(pars) 
     90        self.fixed_index = np.array([pars.index(p) + offset for p in fixed_pars[2:]]) 
     91        self.pd_index = np.array([pars.index(p) + offset for p in pd_pars]) 
     92        self.vol_index = np.array([pars.index(p) + offset for p in vol_pars]) 
     93        try: self.theta_index = pars.index('theta') + offset 
    9494        except ValueError: self.theta_index = -1 
    9595 
     
    105105        # First two fixed 
    106106        scale, background = fixed[:2] 
    107         for index,value in zip(self.fixed_index, fixed[2:]): 
     107        for index, value in zip(self.fixed_index, fixed[2:]): 
    108108            args[index] = float(value) 
    109         res = _loops(form, form_volume, cutoff, scale, background,  args, 
     109        res = _loops(form, form_volume, cutoff, scale, background, args, 
    110110                     pd, self.pd_index, self.vol_index, self.theta_index) 
    111111 
     
    185185    for k in range(stride[-1]): 
    186186        # update polydispersity parameter values 
    187         fast_index = k%stride[0] 
     187        fast_index = k % stride[0] 
    188188        if fast_index == 0:  # bottom loop complete ... check all other loops 
    189189            if weight.size > 0: 
    190                 for i,index, in enumerate(k%stride): 
     190                for i, index, in enumerate(k % stride): 
    191191                    args[pd_index[i]] = pd[i][0][index] 
    192192                    weight[i] = pd[i][1][index] 
     
    202202        if w > cutoff: 
    203203            I = form(*args) 
    204             positive = (I>=0.0) 
     204            positive = (I >= 0.0) 
    205205 
    206206            # Note: can precompute spherical correction if theta_index is not the fast index 
    207207            # Correction factor for spherical integration p(theta) I(q) sin(theta) dtheta 
    208208            #spherical_correction = abs(sin(pi*args[theta_index])) if theta_index>=0 else 1.0 
    209             spherical_correction = abs(cos(pi*args[theta_index]))*pi/2 if theta_index>=0 else 1.0 
     209            spherical_correction = abs(cos(pi * args[theta_index])) * pi / 2 if theta_index >= 0 else 1.0 
    210210            #spherical_correction = 1.0 
    211             ret += w*I*spherical_correction*positive 
    212             norm += w*positive 
     211            ret += w * I * spherical_correction * positive 
     212            norm += w * positive 
    213213 
    214214            # Volume normalization. 
     
    220220                vol_args = [args[index] for index in vol_index] 
    221221                vol_weight = np.prod(weight[vol_weight_index]) 
    222                 vol += vol_weight*form_volume(*vol_args)*positive 
    223                 vol_norm += vol_weight*positive 
    224  
    225     positive = (vol*vol_norm != 0.0) 
     222                vol += vol_weight * form_volume(*vol_args) * positive 
     223                vol_norm += vol_weight * positive 
     224 
     225    positive = (vol * vol_norm != 0.0) 
    226226    ret[positive] *= vol_norm[positive] / vol[positive] 
    227     result = scale*ret/norm+background 
     227    result = scale * ret / norm + background 
    228228    return result 
Note: See TracChangeset for help on using the changeset viewer.