Changeset 9eb3632 in sasmodels for sasmodels/kernel.py


Ignore:
Timestamp:
Jul 22, 2016 10:54:17 PM (8 years ago)
Author:
Paul Kienzle <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:
7b7da6b
Parents:
6a0d6aa
Message:

restructure kernels using fixed PD loops

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kernel.py

    r32e3c9b r9eb3632  
    1313 
    1414import numpy as np 
    15 from .details import mono_details, poly_details 
    1615 
    1716try: 
     
    4847        # type: () -> None 
    4948        pass 
    50  
    51 try: 
    52     np.meshgrid([]) 
    53     meshgrid = np.meshgrid 
    54 except ValueError: 
    55     # CRUFT: np.meshgrid requires multiple vectors 
    56     def meshgrid(*args): 
    57         if len(args) > 1: 
    58             return np.meshgrid(*args) 
    59         else: 
    60             return [np.asarray(v) for v in args] 
    61  
    62 def dispersion_mesh(model_info, pars): 
    63     """ 
    64     Create a mesh grid of dispersion parameters and weights. 
    65  
    66     Returns [p1,p2,...],w where pj is a vector of values for parameter j 
    67     and w is a vector containing the products for weights for each 
    68     parameter set in the vector. 
    69     """ 
    70     value, weight = zip(*pars) 
    71     weight = [w if w else [1.] for w in weight] 
    72     weight = np.vstack([v.flatten() for v in meshgrid(*weight)]) 
    73     weight = np.prod(weight, axis=0) 
    74     value = [v.flatten() for v in meshgrid(*value)] 
    75     lengths = [par.length for par in model_info.parameters.kernel_parameters 
    76                if par.type == 'volume'] 
    77     if any(n > 1 for n in lengths): 
    78         pars = [] 
    79         offset = 0 
    80         for n in lengths: 
    81             pars.append(np.vstack(value[offset:offset+n]) if n > 1 else value[offset]) 
    82             offset += n 
    83         value = pars 
    84     return value, weight 
    85  
    86  
    87  
    88 def build_details(kernel, pairs): 
    89     # type: (Kernel, Tuple[List[np.ndarray], List[np.ndarray]]) -> Tuple[CallDetails, np.ndarray, np.ndarray] 
    90     """ 
    91     Construct the kernel call details object for calling the particular kernel. 
    92     """ 
    93     values, weights = zip(*pairs) 
    94     scalars = [v[0] for v in values] 
    95     if all(len(w)==1 for w in weights): 
    96         call_details = mono_details(kernel.info) 
    97         data = np.array(scalars, dtype=kernel.dtype) 
    98     else: 
    99         call_details = poly_details(kernel.info, weights) 
    100         data = np.hstack(scalars+list(values)+list(weights)).astype(kernel.dtype) 
    101     return call_details, data 
Note: See TracChangeset for help on using the changeset viewer.