Changeset 32c160a in sasmodels for sasmodels/core.py


Ignore:
Timestamp:
Aug 25, 2014 12:55:08 AM (10 years ago)
Author:
Paul Kienzle <pkienzle@…>
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:
13d86bc
Parents:
1f21edf
Message:

support ER/VR python kernels; move metadata to python

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/core.py

    rce27e21 r32c160a  
    88import numpy as np 
    99 
    10 def load_model(modelname): 
    11     from os.path import abspath, join as joinpath, dirname 
    12     from sasmodels import gen 
    13     modelpath = abspath(joinpath(dirname(gen.__file__), 'models', 
    14                                  modelname+'.c')) 
    15     return gen.make(modelpath) 
    16  
    17  
    18  
    19 def opencl_model(modelname, dtype="single"): 
    20     from sasmodels import gpu 
    21  
    22     source, info, _ = load_model(modelname) 
    23     # for debugging, save source to a .cl file, edit it, and reload as model 
     10 
     11def opencl_model(kernel_module, dtype="single"): 
     12    from sasmodels import gen, gpu 
     13 
     14    source, info = gen.make(kernel_module) 
     15    ## for debugging, save source to a .cl file, edit it, and reload as model 
    2416    #open(modelname+'.cl','w').write(source) 
    2517    #source = open(modelname+'.cl','r').read() 
     
    4234 
    4335 
    44 def dll_model(modelname): 
     36def dll_model(kernel_module): 
    4537    import os 
    46     from sasmodels import dll 
    47  
    48     source, info, _ = load_model(modelname) 
     38    import tempfile 
     39    from sasmodels import gen, dll 
     40 
     41    source, info = gen.make(kernel_module) 
    4942    dllpath = dll_path(info) 
    5043    if not os.path.exists(dllpath) \ 
    5144            or (os.path.getmtime(dllpath) < os.path.getmtime(info['filename'])): 
    5245        # Replace with a proper temp file 
    53         srcfile = '/tmp/%s.c'%modelname 
     46        srcfile = tempfile.mkstemp(suffix=".c",prefix="sas_"+info['name']) 
    5447        open(srcfile, 'w').write(source) 
    5548        os.system(COMPILE%(srcfile, dllpath)) 
     49        ## comment the following to keep the generated c file 
     50        #os.unlink(srcfile) 
    5651    return dll.DllModel(dllpath, info) 
    5752 
Note: See TracChangeset for help on using the changeset viewer.