Changeset 8f6817d in sasmodels
- Timestamp:
- Apr 15, 2016 10:16:48 AM (9 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:
- 0ff62d4
- Parents:
- 8d62008 (diff), 299dcce (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - Location:
- sasmodels
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/compare.py
rdd7fc12 r8d62008 49 49 from .modelinfo import ModelInfo, Parameter, ParameterSet 50 50 from .data import Data 51 Calculator = Callable[[float , ...], np.ndarray]51 Calculator = Callable[[float], np.ndarray] 52 52 53 53 USAGE = """ … … 383 383 # import rather than the more obscure smear_selection not imported error 384 384 import sas 385 import sas.models 385 386 from sas.models.qsmearing import smear_selection 386 import sas.models387 from sas.models.MultiplicationModel import MultiplicationModel 387 388 388 389 def get_model(name): … … 399 400 composition_type, parts = model_info.composition 400 401 if composition_type == 'product': 401 from sas.models.MultiplicationModel import MultiplicationModel402 402 P, S = [get_model(revert_name(p)) for p in parts] 403 403 model = MultiplicationModel(P, S) -
sasmodels/details.py
r7ae2b7f r8d62008 5 5 except ImportError: 6 6 pass 7 else: 8 from .modelinfo import ModelInfo 7 9 8 10 … … 10 12 parts = None # type: List["CallDetails"] 11 13 def __init__(self, model_info): 14 # type: (ModelInfo) -> None 12 15 parameters = model_info.parameters 13 16 max_pd = parameters.max_pd 14 17 npars = parameters.npars 15 18 par_offset = 4*max_pd 16 self. _details = np.zeros(par_offset + 3*npars + 4, 'i4')19 self.buffer = np.zeros(par_offset + 3 * npars + 4, 'i4') 17 20 18 21 # generate views on different parts of the array 19 self._pd_par = self. _details[0*max_pd:1*max_pd]20 self._pd_length = self. _details[1*max_pd:2*max_pd]21 self._pd_offset = self. _details[2*max_pd:3*max_pd]22 self._pd_stride = self. _details[3*max_pd:4*max_pd]23 self._par_offset = self. _details[par_offset+0*npars:par_offset+1*npars]24 self._par_coord = self. _details[par_offset+1*npars:par_offset+2*npars]25 self._pd_coord = self. _details[par_offset+2*npars:par_offset+3*npars]22 self._pd_par = self.buffer[0 * max_pd:1 * max_pd] 23 self._pd_length = self.buffer[1 * max_pd:2 * max_pd] 24 self._pd_offset = self.buffer[2 * max_pd:3 * max_pd] 25 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] 26 29 27 30 # theta_par is fixed 28 self._details[-1] = parameters.theta_offset 29 30 @property 31 def ctypes(self): return self._details.ctypes 31 self.buffer[-1] = parameters.theta_offset 32 32 33 33 @property … … 53 53 54 54 @property 55 def num_active(self): return self. _details[-4]55 def num_active(self): return self.buffer[-4] 56 56 @num_active.setter 57 def num_active(self, v): self. _details[-4] = v57 def num_active(self, v): self.buffer[-4] = v 58 58 59 59 @property 60 def total_pd(self): return self. _details[-3]60 def total_pd(self): return self.buffer[-3] 61 61 @total_pd.setter 62 def total_pd(self, v): self. _details[-3] = v62 def total_pd(self, v): self.buffer[-3] = v 63 63 64 64 @property 65 def num_coord(self): return self. _details[-2]65 def num_coord(self): return self.buffer[-2] 66 66 @num_coord.setter 67 def num_coord(self, v): self. _details[-2] = v67 def num_coord(self, v): self.buffer[-2] = v 68 68 69 69 @property 70 def theta_par(self): return self. _details[-1]70 def theta_par(self): return self.buffer[-1] 71 71 72 72 def show(self): … … 81 81 print("par_coord", self.par_coord) 82 82 print("pd_coord", self.pd_coord) 83 print("theta par", self. _details[-1])83 print("theta par", self.buffer[-1]) 84 84 85 85 def build_details(kernel, pairs): … … 88 88 call_details = poly_details(kernel.info, weights) 89 89 else: 90 call_details = kernel.info.mono_details90 call_details = mono_details(kernel.info) 91 91 weights, values = [np.hstack(v) for v in (weights, values)] 92 92 weights = weights.astype(dtype=kernel.dtype) -
sasmodels/kernelcl.py
rdd7fc12 r8d62008 60 60 # Ask OpenCL for the default context so that we know that one exists 61 61 cl.create_some_context(interactive=False) 62 except Exception as exc: 63 warnings.warn(str(exc)) 62 except Exception as ocl_exc: 63 warnings.warn(str(ocl_exc)) 64 del ocl_exc 64 65 raise RuntimeError("OpenCL not available") 65 66 … … 479 480 self.dtype = kernel.dtype 480 481 self.dim = '2d' if q_input.is_2d else '1d' 481 self.pd_stop_index = 4*max_pd-1482 482 # plus three for the normalization values 483 483 self.result = np.empty(q_input.nq+3, q_input.dtype) … … 495 495 496 496 self._need_release = [ self.result_b, self.q_input ] 497 self.real = (np.float32 if self.q_input.dtype == generate.F32 498 else np.float64 if self.q_input.dtype == generate.F64 499 else np.float16 if self.q_input.dtype == generate.F16 500 else np.float32) # will never get here, so use np.float32 497 501 498 502 def __call__(self, call_details, weights, values, cutoff): 499 503 # type: (CallDetails, np.ndarray, np.ndarray, float) -> np.ndarray 500 real = (np.float32 if self.q_input.dtype == generate.F32501 else np.float64 if self.q_input.dtype == generate.F64502 else np.float16 if self.q_input.dtype == generate.F16503 else np.float32) # will never get here, so use np.float32504 assert call_details.dtype == np.int32505 assert weights.dtype == real and values.dtype == real506 504 507 505 context = self.queue.context 506 # Arrange data transfer to card 508 507 details_b = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, 509 hostbuf=call_details )508 hostbuf=call_details.buffer) 510 509 weights_b = cl.Buffer(context, mf.READ_ONLY | mf.COPY_HOST_PTR, 511 510 hostbuf=weights) … … 513 512 hostbuf=values) 514 513 515 start, stop = 0, self.details[self.pd_stop_index]514 start, stop = 0, call_details.total_pd 516 515 args = [ 517 np.uint32(self.q_input.nq), np. uint32(start), np.uint32(stop),518 self.details_b, self.weights_b, self.values_b,519 self. q_input.q_b, self.result_b,real(cutoff),516 np.uint32(self.q_input.nq), np.int32(start), np.int32(stop), 517 details_b, weights_b, values_b, self.q_input.q_b, self.result_b, 518 self.real(cutoff), 520 519 ] 521 520 self.kernel(self.queue, self.q_input.global_size, None, *args) 522 521 cl.enqueue_copy(self.queue, self.result, self.result_b) 523 [v.release() for v in (details_b, weights_b, values_b)] 524 525 return self.result[:self.nq] 522 for v in (details_b, weights_b, values_b): 523 v.release() 524 525 return self.result[:self.q_input.nq] 526 526 527 527 def release(self): -
sasmodels/kerneldll.py
ra5b8477 r8d62008 294 294 start, # pd_start 295 295 stop, # pd_stop pd_stride[MAX_PD] 296 call_details. ctypes.data, # problem296 call_details.buffer.ctypes.data, # problem 297 297 weights.ctypes.data, # weights 298 298 values.ctypes.data, #pars -
sasmodels/modelinfo.py
ra5b8477 r8d62008 13 13 14 14 import numpy as np # type: ignore 15 16 from .details import mono_details17 15 18 16 # Optional typing … … 22 20 pass 23 21 else: 24 from .details import CallDetails25 22 Limits = Tuple[float, float] 26 23 #LimitsOrChoice = Union[Limits, Tuple[Sequence[str]]] … … 658 655 info.hidden = getattr(kernel_module, 'hidden', None) # type: ignore 659 656 660 # Precalculate the monodisperse parameter details661 info.mono_details = mono_details(info)662 657 return info 663 658 … … 811 806 #: the SESANS correlation function. Note: not currently implemented. 812 807 sesans = None # type: Optional[Callable[[np.ndarray], np.ndarray]] 813 #: :class:details.CallDetails data for mono-disperse function evaluation.814 #: This field is created automatically by the model loader, and should815 #: not be defined as part of the model definition file.816 mono_details = None # type: CallDetails817 808 818 809 def __init__(self):
Note: See TracChangeset
for help on using the changeset viewer.