Changeset 765d025 in sasmodels for sasmodels/kerneldll.py
- Timestamp:
- Oct 30, 2018 12:05:27 PM (6 years ago)
- Children:
- 646eeaa
- Parents:
- 1662ebe (diff), aa8c6e0 (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. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kerneldll.py
r1662ebe re44432d 99 99 pass 100 100 # pylint: enable=unused-import 101 102 # Compiler output is a byte stream that needs to be decode in python 3 103 decode = (lambda s: s) if sys.version_info[0] < 3 else (lambda s: s.decode('utf8')) 104 105 if "SAS_DLL_PATH" in os.environ: 106 SAS_DLL_PATH = os.environ["SAS_DLL_PATH"] 107 else: 108 # Assume the default location of module DLLs is in .sasmodels/compiled_models. 109 SAS_DLL_PATH = os.path.join(os.path.expanduser("~"), ".sasmodels", "compiled_models") 101 110 102 111 if "SAS_COMPILER" in os.environ: … … 161 170 return CC + [source, "-o", output, "-lm"] 162 171 163 # Assume the default location of module DLLs is in .sasmodels/compiled_models.164 DLL_PATH = os.path.join(os.path.expanduser("~"), ".sasmodels", "compiled_models")165 166 172 ALLOW_SINGLE_PRECISION_DLLS = True 167 173 … … 181 187 subprocess.check_output(command, shell=shell, stderr=subprocess.STDOUT) 182 188 except subprocess.CalledProcessError as exc: 183 raise RuntimeError("compile failed.\n%s\n%s"184 % (command_str, exc.output.decode()))189 output = decode(exc.output) 190 raise RuntimeError("compile failed.\n%s\n%s"%(command_str, output)) 185 191 if not os.path.exists(output): 186 192 raise RuntimeError("compile failed. File is in %r"%source) … … 201 207 return path 202 208 203 return joinpath( DLL_PATH, basename)209 return joinpath(SAS_DLL_PATH, basename) 204 210 205 211 … … 210 216 exist yet if it hasn't been compiled. 211 217 """ 212 return os.path.join( DLL_PATH, dll_name(model_info, dtype))218 return os.path.join(SAS_DLL_PATH, dll_name(model_info, dtype)) 213 219 214 220 … … 229 235 models are not allowed as DLLs. 230 236 231 Set *sasmodels.kerneldll.DLL_PATH* to the compiled dll output path. 237 Set *sasmodels.kerneldll.SAS_DLL_PATH* to the compiled dll output path. 238 Alternatively, set the environment variable *SAS_DLL_PATH*. 232 239 The default is in ~/.sasmodels/compiled_models. 233 240 """ … … 248 255 if need_recompile: 249 256 # Make sure the DLL path exists 250 if not os.path.exists( DLL_PATH):251 os.makedirs( DLL_PATH)257 if not os.path.exists(SAS_DLL_PATH): 258 os.makedirs(SAS_DLL_PATH) 252 259 basename = splitext(os.path.basename(dll))[0] + "_" 253 260 system_fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) … … 312 319 313 320 # int, int, int, int*, double*, double*, double*, double*, double 314 argtypes = [ct.c_int32]*3 + [ct.c_void_p]*4 + [float_type ]321 argtypes = [ct.c_int32]*3 + [ct.c_void_p]*4 + [float_type, ct.c_int32] 315 322 names = [generate.kernel_name(self.info, variant) 316 323 for variant in ("Iq", "Iqxy", "Imagnetic")] … … 372 379 def __init__(self, kernel, model_info, q_input): 373 380 # type: (Callable[[], np.ndarray], ModelInfo, PyInput) -> None 381 #,model_info,q_input) 374 382 self.kernel = kernel 375 383 self.info = model_info … … 377 385 self.dtype = q_input.dtype 378 386 self.dim = '2d' if q_input.is_2d else '1d' 379 self.result = np.empty(q_input.nq+1, q_input.dtype) 387 # leave room for f1/f2 results in case we need to compute beta for 1d models 388 nout = 2 if self.info.have_Fq else 1 389 # +4 for total weight, shell volume, effective radius, form volume 390 self.result = np.empty(q_input.nq*nout + 4, self.dtype) 380 391 self.real = (np.float32 if self.q_input.dtype == generate.F32 381 392 else np.float64 if self.q_input.dtype == generate.F64 382 393 else np.float128) 383 394 384 def __call__(self, call_details, values, cutoff, magnetic): 385 # type: (CallDetails, np.ndarray, np.ndarray, float, bool) -> np.ndarray 386 395 def _call_kernel(self, call_details, values, cutoff, magnetic, effective_radius_type): 396 # type: (CallDetails, np.ndarray, np.ndarray, float, bool, int) -> np.ndarray 387 397 kernel = self.kernel[1 if magnetic else 0] 388 398 args = [ … … 391 401 None, # pd_stop pd_stride[MAX_PD] 392 402 call_details.buffer.ctypes.data, # problem 393 values.ctypes.data, # pars394 self.q_input.q.ctypes.data, # q403 values.ctypes.data, # pars 404 self.q_input.q.ctypes.data, # q 395 405 self.result.ctypes.data, # results 396 406 self.real(cutoff), # cutoff 407 effective_radius_type, # cutoff 397 408 ] 398 409 #print("Calling DLL") … … 404 415 kernel(*args) # type: ignore 405 416 406 #print("returned",self.q_input.q, self.result)407 pd_norm = self.result[self.q_input.nq]408 scale = values[0]/(pd_norm if pd_norm != 0.0 else 1.0)409 background = values[1]410 #print("scale",scale,background)411 return scale*self.result[:self.q_input.nq] + background412 413 417 def release(self): 414 418 # type: () -> None
Note: See TracChangeset
for help on using the changeset viewer.