Changeset 6e7ba14 in sasmodels for sasmodels/kernelpy.py
- Timestamp:
- Aug 20, 2018 8:52:21 AM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- aa44a6a
- Parents:
- bad3093
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kernelpy.py
r108e70e r6e7ba14 12 12 13 13 import numpy as np # type: ignore 14 from numpy import pi 15 try: 16 from numpy import cbrt 17 except ImportError: 18 def cbrt(x): return x ** (1.0/3.0) 14 19 15 20 from .generate import F64 … … 158 163 159 164 # Generate a closure which calls the form_volume if it exists. 160 form_volume = model_info.form_volume 161 self._volume = ((lambda: form_volume(*volume_args)) if form_volume else 162 (lambda: 1.0)) 163 164 def __call__(self, call_details, values, cutoff, magnetic): 165 self._volume_args = volume_args 166 volume = model_info.form_volume 167 radius = model_info.effective_radius 168 self._volume = ((lambda: volume(*volume_args)) if volume 169 else (lambda: 1.0)) 170 self._radius = ((lambda mode: radius(mode, *volume_args)) if radius 171 else (lambda mode: cbrt(0.75/pi*volume(*volume_args))) if volume 172 else (lambda mode: 1.0)) 173 174 175 176 def _call_kernel(self, call_details, values, cutoff, magnetic, effective_radius_type): 165 177 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 166 178 if magnetic: … … 168 180 #print("Calling python kernel") 169 181 #call_details.show(values) 170 res = _loops(self._parameter_vector, self._form, self._volume, 182 radius = ((lambda: 0.0) if effective_radius_type == 0 183 else (lambda: self._radius(effective_radius_type))) 184 res = _loops(self._parameter_vector, self._form, self._volume, radius, 171 185 self.q_input.nq, call_details, values, cutoff) 172 186 return res … … 183 197 form, # type: Callable[[], np.ndarray] 184 198 form_volume, # type: Callable[[], float] 199 form_radius, # type: Callable[[], float] 185 200 nq, # type: int 186 201 call_details, # type: details.CallDetails 187 202 values, # type: np.ndarray 188 cutoff 203 cutoff, # type: float 189 204 ): 190 205 # type: (...) -> None … … 209 224 pd_weight = values[2+n_pars + call_details.num_weights:] 210 225 211 pd_norm = 0.0 226 weight_norm = 0.0 227 weighted_volume = 0.0 228 weighted_radius = 0.0 212 229 partial_weight = np.NaN 213 230 weight = np.NaN … … 246 263 # update value and norm 247 264 total += weight * Iq 248 pd_norm += weight * form_volume() 249 250 scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0) 251 background = values[1] 252 return scale*total + background 265 weight_norm += weight 266 weighted_volume += weight * form_volume() 267 weighted_radius += weight * form_radius() 268 269 result = np.hstack((total, weight_norm, weighted_volume, weighted_radius)) 270 return result 253 271 254 272
Note: See TracChangeset
for help on using the changeset viewer.