Changeset aa4946b in sasmodels for sasmodels/kerneldll.py
- Timestamp:
- Mar 11, 2015 9:15:40 PM (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:
- af1d68c
- Parents:
- 49d1d42f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/kerneldll.py
r63b32bb raa4946b 54 54 55 55 56 def load_model(kernel_module, dtype="double"):56 def make_dll(source, info, dtype="double"): 57 57 """ 58 58 Load the compiled model defined by *kernel_module*. … … 60 60 Recompile if any files are newer than the model file. 61 61 62 *dtype* is ignored. Compiled files are always double. 63 64 The DLL is not loaded until the kernel is called so models an 62 *dtype* is a numpy floating point precision specifier indicating whether 63 the model should be single or double precision. The default is double 64 precision. 65 66 The DLL is not loaded until the kernel is called so models can 65 67 be defined without using too many resources. 68 69 Set *sasmodels.kerneldll.DLL_PATH* to the compiled dll output path. 70 The default is the system temporary directory. 71 72 Set *sasmodels.ALLOW_SINGLE_PRECISION_DLLS* to True if single precision 73 models are allowed as DLLs. 66 74 """ 67 75 if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double" # Force 64-bit dll 68 76 dtype = np.dtype(dtype) 69 77 70 source, info = generate.make(kernel_module)71 78 if callable(info.get('Iq',None)): 72 79 return PyModel(info) … … 79 86 80 87 source_files = generate.sources(info) + [info['filename']] 81 dll path= dll_path(info, dtype)88 dll= dll_path(info, dtype) 82 89 newest = max(os.path.getmtime(f) for f in source_files) 83 if not os.path.exists(dll path) or os.path.getmtime(dllpath)<newest:90 if not os.path.exists(dll) or os.path.getmtime(dll)<newest: 84 91 # Replace with a proper temp file 85 92 fid, filename = tempfile.mkstemp(suffix=".c",prefix=tempfile_prefix) 86 93 os.fdopen(fid,"w").write(source) 87 command = COMPILE%{"source":filename, "output":dll path}94 command = COMPILE%{"source":filename, "output":dll} 88 95 print "Compile command:",command 89 96 status = os.system(command) 90 if status != 0 :97 if status != 0 or not os.path.exists(dll): 91 98 raise RuntimeError("compile failed. File is in %r"%filename) 92 99 else: 93 100 ## uncomment the following to keep the generated c file 94 #os.unlink(filename); print "saving compiled file in %r"%filename 95 pass 96 return DllModel(dllpath, info, dtype=dtype) 101 os.unlink(filename); print "saving compiled file in %r"%filename 102 return dll 103 104 105 def load_dll(source, info, dtype="double"): 106 """ 107 Create and load a dll corresponding to the source,info pair returned 108 from :func:`sasmodels.generate.make` compiled for the target precision. 109 110 See :func:`make_dll` for details on controlling the dll path and the 111 allowed floating point precision. 112 """ 113 filename = make_dll(source, info, dtype=dtype) 114 return DllModel(filename, info, dtype=dtype) 97 115 98 116
Note: See TracChangeset
for help on using the changeset viewer.