Changeset 0880966 in sasmodels


Ignore:
Timestamp:
Mar 21, 2016 12:34:51 PM (8 years ago)
Author:
wojciech
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:
839283a
Parents:
9f4409a
Message:

Mono and poly reading fixes

Location:
sasmodels
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    r39cc3be r0880966  
    183183    value = values.get(parameter.name, parameter.default) 
    184184    if parameter.type not in ('volume', 'orientation'): 
    185         return [value], [] 
     185        return np.array([value]), np.array([1.0]) 
    186186    relative = parameter.type == 'volume' 
    187187    limits = parameter.limits 
     
    208208    return value, weight 
    209209 
    210 def call_kernel(kernel, values, cutoff=0, mono=False): 
     210def call_kernel(kernel, pars, cutoff=0, mono=False): 
    211211    """ 
    212212    Call *kernel* returned from :func:`make_kernel` with parameters *pars*. 
     
    221221    *mono* is True if polydispersity should be set to none on all parameters. 
    222222    """ 
    223     if mono or True: 
    224         pars = np.array([values.get(p.name, p.default) 
    225                          for p in kernel.info['parameters']], 
    226                         dtype=kernel.dtype) 
    227         weights = np.array([1.0], dtype=kernel.dtype) 
     223    if mono: 
     224        values = [pars.get(p.name, p.default) for p in kernel.info['parameters']] 
     225        weights = [1.0]*len(values) 
     226    else: 
     227        wv_pairs = [get_weights(p, pars) for p in kernel.info['parameters']] 
     228        weights, values = [v for v in zip(*wv_pairs)] 
     229 
     230    #TODO: This is what we thought to do if max([len(w) for w in weights]) > 1: 
     231    if max([w for w in weights]) > 1: 
     232        details = generate.poly_details(kernel.info, weights) 
     233    else: 
    228234        details = kernel.info['mono_details'] 
    229         return kernel(details,  weights, pars, cutoff) 
    230     else: 
    231         pairs = [get_weights(p, values) for p in kernel.info['parameters']] 
    232         weights, pars = [v for v in zip(*pairs)] 
    233         details = generate.poly_details(kernel.info, weights, pars) 
    234         weights, pars = [np.hstack(v) for v in (weights, pars)] 
    235         return kernel(details, weights, pars, cutoff) 
     235 
     236    weights, values = [np.hstack(v) for v in (weights, values)] 
     237 
     238    weights = weights.astype(dtype=kernel.dtype) 
     239    values = values.astype(dtype=kernel.dtype) 
     240 
     241    return kernel(details, weights, values, cutoff) 
    236242 
    237243def call_ER_VR(model_info, vol_pars): 
  • sasmodels/generate.py

    ra6f9577 r0880966  
    693693    # Note: the reversing view, x[::-1], does not require a copy 
    694694    pd_length = np.array([len(w) for w in weights]) 
     695    print (pd_length) 
    695696    pd_offset = np.cumsum(np.hstack((0, pd_length))) 
    696697    pd_isvol = np.array([p.type=='volume' for p in pars]) 
    697698    idx = np.argsort(pd_length)[::-1][:max_pd] 
    698     pd_stride = np.cumprod(np.hstack((1, np.maximum(pd_length[idx][:-1],1)))) 
    699     par_offsets = np.cumsum(np.hstack((2, np.maximum(pd_length, 1))))[:-1] 
    700     theta_par = model_info['theta_par'] 
    701     if theta_par >= 0 and pd_length[theta_par] <= 1: 
    702         theta_par = -1 
     699    print (idx) 
     700    pd_stride = np.cumprod(np.hstack((1, pd_length[idx][:-1]))) 
     701    par_offsets = np.cumsum(np.hstack((2, pd_length)))[:-1] 
     702 
     703    theta_par = -1 
     704    if 'theta_par' in model_info: 
     705        theta_par = model_info['theta_par'] 
     706        if theta_par >= 0 and pd_length[theta_par] <= 1: 
     707            theta_par = -1 
    703708 
    704709    details = np.empty(constants_offset + 3, 'int32') 
  • sasmodels/kerneldll.py

    r39cc3be r0880966  
    271271        #weights = np.asarray(weights, dtype=real) 
    272272        #values = np.asarray(values, dtype=real) 
     273        #TODO: How can I access max_pd and is this the way to do it? 
     274        #max_pd = model_info['max_pd'] 
     275        max_pd = 1 
    273276        args = [ 
    274277            self.q_input.nq, # nq 
     278            #TODO: pd_start will need to be changed 
    275279            0, # pd_start 
    276             1, # pd_stop 
     280            details[3*max_pd:4*max_pd], # pd_stop pd_stride[MAX_PD] 
    277281            details.ctypes.data, # problem 
    278282            weights.ctypes.data,  # weights 
Note: See TracChangeset for help on using the changeset viewer.