Changeset a738209 in sasmodels for sasmodels/details.py
- Timestamp:
- Jul 15, 2016 7:33:33 AM (8 years ago)
- 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
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/details.py
r0ff62d4 ra738209 1 from __future__ import print_function 2 1 3 import numpy as np # type: ignore 2 4 … … 15 17 parameters = model_info.parameters 16 18 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') 20 30 21 31 # generate views on different parts of the array … … 24 34 self._pd_offset = self.buffer[2 * max_pd:3 * max_pd] 25 35 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]29 36 30 37 # theta_par is fixed 31 self. buffer[-1]= parameters.theta_offset38 self.theta_par = parameters.theta_offset 32 39 33 40 @property … … 44 51 45 52 @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 47 56 48 57 @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 50 61 51 62 @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] 56 64 @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 68 66 69 67 @property 70 68 def theta_par(self): return self.buffer[-1] 69 @theta_par.setter 70 def theta_par(self, v): self.buffer[-1] = v 71 71 72 72 def show(self): 73 print("total_pd", self.total_pd)74 73 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) 75 77 print("pd_par", self.pd_par) 76 78 print("pd_length", self.pd_length) 77 79 print("pd_offset", self.pd_offset) 78 80 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])84 81 85 82 def mono_details(model_info): 86 83 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 89 85 return call_details 90 86 91 87 def poly_details(model_info, weights): 92 88 #print("weights",weights) 93 weights = weights[2:] # Skip scale and background89 #weights = weights[2:] # Skip scale and background 94 90 95 91 # Decreasing list of polydispersity lengths 96 # Note: the reversing view, x[::-1], does not require a copy97 92 pd_length = np.array([len(w) for w in weights]) 98 93 num_active = np.sum(pd_length>1) … … 101 96 102 97 pd_offset = np.cumsum(np.hstack((0, pd_length))) 98 # Note: the reversing view, x[::-1], does not require a copy 103 99 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]) 105 101 pd_stride = np.cumprod(np.hstack((1, par_length[idx]))) 106 par_offsets = np.cumsum(np.hstack((2, par_length)))107 102 108 103 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 110 105 call_details.pd_length[:num_active] = pd_length[idx] 111 106 call_details.pd_offset[:num_active] = pd_offset[idx] 112 107 call_details.pd_stride[:num_active] = pd_stride[:-1] 113 call_details.p ar_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) 115 110 call_details.num_active = num_active 116 # Without constraints coordinated parameters are just the pd parameters117 call_details.par_coord[:num_active] = idx118 call_details.pd_coord[:num_active] = 2**np.arange(num_active)119 call_details.num_coord = num_active120 111 #call_details.show() 121 112 return call_details 122 123 def constrained_poly_details(model_info, weights, constraints):124 # Need to find the independently varying pars and sort them125 # Need to build a coordination list for the dependent variables126 # Need to generate a constraints function which takes values127 # and weights, returning par blocks128 raise NotImplementedError("Can't handle constraints yet")129
Note: See TracChangeset
for help on using the changeset viewer.