Changeset a738209 in sasmodels for sasmodels/details.py


Ignore:
Timestamp:
Jul 15, 2016 7:33:33 AM (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:
def2c1b
Parents:
98ba1fc
Message:

simplify kernels by remove coordination parameter logic

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/details.py

    r0ff62d4 ra738209  
     1from __future__ import print_function 
     2 
    13import numpy as np  # type: ignore 
    24 
     
    1517        parameters = model_info.parameters 
    1618        max_pd = parameters.max_pd 
    17         npars = parameters.npars 
    18         par_offset = 4*max_pd 
    19         self.buffer = np.zeros(par_offset + 3 * npars + 4, 'i4') 
     19 
     20        # Structure of the call details buffer: 
     21        #   pd_par[max_pd]     pd params in order of length 
     22        #   pd_length[max_pd]  length of each pd param 
     23        #   pd_offset[max_pd]  offset of pd values in parameter array 
     24        #   pd_stride[max_pd]  index of pd value in loop = n//stride[k] 
     25        #   pd_prod            total length of pd loop 
     26        #   pd_sum             total length of the weight vector 
     27        #   num_active         number of pd params 
     28        #   theta_par          parameter number for theta parameter 
     29        self.buffer = np.zeros(4*max_pd + 4, 'i4') 
    2030 
    2131        # generate views on different parts of the array 
     
    2434        self._pd_offset  = self.buffer[2 * max_pd:3 * max_pd] 
    2535        self._pd_stride  = self.buffer[3 * max_pd:4 * max_pd] 
    26         self._par_offset = self.buffer[par_offset + 0 * npars:par_offset + 1 * npars] 
    27         self._par_coord  = self.buffer[par_offset + 1 * npars:par_offset + 2 * npars] 
    28         self._pd_coord   = self.buffer[par_offset + 2 * npars:par_offset + 3 * npars] 
    2936 
    3037        # theta_par is fixed 
    31         self.buffer[-1] = parameters.theta_offset 
     38        self.theta_par = parameters.theta_offset 
    3239 
    3340    @property 
     
    4451 
    4552    @property 
    46     def pd_coord(self): return self._pd_coord 
     53    def pd_prod(self): return self.buffer[-4] 
     54    @pd_prod.setter 
     55    def pd_prod(self, v): self.buffer[-4] = v 
    4756 
    4857    @property 
    49     def par_coord(self): return self._par_coord 
     58    def pd_sum(self): return self.buffer[-3] 
     59    @pd_sum.setter 
     60    def pd_sum(self, v): self.buffer[-3] = v 
    5061 
    5162    @property 
    52     def par_offset(self): return self._par_offset 
    53  
    54     @property 
    55     def num_active(self): return self.buffer[-4] 
     63    def num_active(self): return self.buffer[-2] 
    5664    @num_active.setter 
    57     def num_active(self, v): self.buffer[-4] = v 
    58  
    59     @property 
    60     def total_pd(self): return self.buffer[-3] 
    61     @total_pd.setter 
    62     def total_pd(self, v): self.buffer[-3] = v 
    63  
    64     @property 
    65     def num_coord(self): return self.buffer[-2] 
    66     @num_coord.setter 
    67     def num_coord(self, v): self.buffer[-2] = v 
     65    def num_active(self, v): self.buffer[-2] = v 
    6866 
    6967    @property 
    7068    def theta_par(self): return self.buffer[-1] 
     69    @theta_par.setter 
     70    def theta_par(self, v): self.buffer[-1] = v 
    7171 
    7272    def show(self): 
    73         print("total_pd", self.total_pd) 
    7473        print("num_active", self.num_active) 
     74        print("pd_prod", self.pd_prod) 
     75        print("pd_sum", self.pd_sum) 
     76        print("theta par", self.theta_par) 
    7577        print("pd_par", self.pd_par) 
    7678        print("pd_length", self.pd_length) 
    7779        print("pd_offset", self.pd_offset) 
    7880        print("pd_stride", self.pd_stride) 
    79         print("par_offsets", self.par_offset) 
    80         print("num_coord", self.num_coord) 
    81         print("par_coord", self.par_coord) 
    82         print("pd_coord", self.pd_coord) 
    83         print("theta par", self.buffer[-1]) 
    8481 
    8582def mono_details(model_info): 
    8683    call_details = CallDetails(model_info) 
    87     # The zero defaults for monodisperse systems are mostly fine 
    88     call_details.par_offset[:] = np.arange(2, len(call_details.par_offset)+2) 
     84    call_details.pd_prod = 1 
    8985    return call_details 
    9086 
    9187def poly_details(model_info, weights): 
    9288    #print("weights",weights) 
    93     weights = weights[2:] # Skip scale and background 
     89    #weights = weights[2:] # Skip scale and background 
    9490 
    9591    # Decreasing list of polydispersity lengths 
    96     # Note: the reversing view, x[::-1], does not require a copy 
    9792    pd_length = np.array([len(w) for w in weights]) 
    9893    num_active = np.sum(pd_length>1) 
     
    10196 
    10297    pd_offset = np.cumsum(np.hstack((0, pd_length))) 
     98    # Note: the reversing view, x[::-1], does not require a copy 
    10399    idx = np.argsort(pd_length)[::-1][:num_active] 
    104     par_length = np.array([max(len(w),1) for w in weights]) 
     100    par_length = np.array([len(w) for w in weights]) 
    105101    pd_stride = np.cumprod(np.hstack((1, par_length[idx]))) 
    106     par_offsets = np.cumsum(np.hstack((2, par_length))) 
    107102 
    108103    call_details = CallDetails(model_info) 
    109     call_details.pd_par[:num_active] = idx 
     104    call_details.pd_par[:num_active] = idx - 2  # skip background & scale 
    110105    call_details.pd_length[:num_active] = pd_length[idx] 
    111106    call_details.pd_offset[:num_active] = pd_offset[idx] 
    112107    call_details.pd_stride[:num_active] = pd_stride[:-1] 
    113     call_details.par_offset[:] = par_offsets[:-1] 
    114     call_details.total_pd = pd_stride[-1] 
     108    call_details.pd_prod = pd_stride[-1] 
     109    call_details.pd_sum = np.sum(par_length) 
    115110    call_details.num_active = num_active 
    116     # Without constraints coordinated parameters are just the pd parameters 
    117     call_details.par_coord[:num_active] = idx 
    118     call_details.pd_coord[:num_active] = 2**np.arange(num_active) 
    119     call_details.num_coord = num_active 
    120111    #call_details.show() 
    121112    return call_details 
    122  
    123 def constrained_poly_details(model_info, weights, constraints): 
    124     # Need to find the independently varying pars and sort them 
    125     # Need to build a coordination list for the dependent variables 
    126     # Need to generate a constraints function which takes values 
    127     # and weights, returning par blocks 
    128     raise NotImplementedError("Can't handle constraints yet") 
    129  
Note: See TracChangeset for help on using the changeset viewer.