Changeset 40a87fa in sasmodels for sasmodels/kerneldll.py


Ignore:
Timestamp:
Aug 8, 2016 9:24:11 AM (8 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:
2472141
Parents:
2d65d51
Message:

lint and latex cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kerneldll.py

    r739aad4 r40a87fa  
    4848import sys 
    4949import os 
    50 from os.path import join as joinpath, split as splitpath, splitext 
     50from os.path import join as joinpath, splitext 
    5151import subprocess 
    5252import tempfile 
     
    100100        CC.append("-fopenmp") 
    101101    def compile_command(source, output): 
     102        """unix compiler command""" 
    102103        return CC + [source, "-o", output, "-lm"] 
    103104elif compiler == "msvc": 
     
    115116    LN = "/link /DLL /INCREMENTAL:NO /MANIFEST".split() 
    116117    def compile_command(source, output): 
     118        """MSVC compiler command""" 
    117119        return CC + ["/Tp%s"%source] + LN + ["/OUT:%s"%output] 
    118120elif compiler == "tinycc": 
     
    120122    CC = [tinycc.TCC] + "-shared -rdynamic -Wall".split() 
    121123    def compile_command(source, output): 
     124        """tinycc compiler command""" 
    122125        return CC + [source, "-o", output] 
    123126elif compiler == "mingw": 
     
    127130        CC.append("-fopenmp") 
    128131    def compile_command(source, output): 
     132        """mingw compiler command""" 
    129133        return CC + [source, "-o", output, "-lm"] 
    130134 
     
    142146 
    143147def compile(source, output): 
     148    # type: (str, str) -> None 
     149    """ 
     150    Compile *source* producing *output*. 
     151 
     152    Raises RuntimeError if the compile failed or the output wasn't produced. 
     153    """ 
    144154    command = compile_command(source=source, output=output) 
    145155    command_str = " ".join('"%s"'%p if ' ' in p else p for p in command) 
     
    219229        need_recompile = dll_time < newest_source 
    220230    if need_recompile: 
    221         basename = os.path.splitext(os.path.basename(dll))[0] + "_" 
    222         fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) 
     231        basename = splitext(os.path.basename(dll))[0] + "_" 
     232        system_fd, filename = tempfile.mkstemp(suffix=".c", prefix=basename) 
    223233        source = generate.convert_type(source, dtype) 
    224         with os.fdopen(fd, "w") as file: 
    225             file.write(source) 
     234        with os.fdopen(system_fd, "w") as file_handle: 
     235            file_handle.write(source) 
    226236        compile(source=filename, output=dll) 
    227237        # comment the following to keep the generated c file 
     
    260270    Call :meth:`release` when done with the kernel. 
    261271    """ 
    262      
    263272    def __init__(self, dllpath, model_info, dtype=generate.F32): 
    264273        # type: (str, ModelInfo, np.dtype) -> None 
     
    266275        self.dllpath = dllpath 
    267276        self._dll = None  # type: ct.CDLL 
     277        self._kernels = None # type: List[Callable, Callable] 
    268278        self.dtype = np.dtype(dtype) 
    269279 
     
    277287            raise 
    278288 
    279         fp = (c_float if self.dtype == generate.F32 
    280               else c_double if self.dtype == generate.F64 
    281               else c_longdouble) 
     289        float_type = (c_float if self.dtype == generate.F32 
     290                      else c_double if self.dtype == generate.F64 
     291                      else c_longdouble) 
    282292 
    283293        # int, int, int, int*, double*, double*, double*, double*, double 
    284         argtypes = [c_int32]*3 + [c_void_p]*4 + [fp] 
     294        argtypes = [c_int32]*3 + [c_void_p]*4 + [float_type] 
    285295        names = [generate.kernel_name(self.info, variant) 
    286296                 for variant in ("Iq", "Iqxy", "Imagnetic")] 
     
    316326            #dll = ct.cdll.LoadLibrary(self.dllpath) 
    317327            dll = ct.CDLL(self.dllpath) 
    318             libHandle = dll._handle 
    319             #libHandle = ct.c_void_p(dll._handle) 
     328            dll_handle = dll._handle 
     329            #dll_handle = ct.c_void_p(dll._handle) 
    320330            del dll, self._dll 
    321331            self._dll = None 
    322             ct.windll.kernel32.FreeLibrary(libHandle) 
    323         else:     
    324             pass  
     332            ct.windll.kernel32.FreeLibrary(dll_handle) 
     333        else: 
     334            pass 
    325335 
    326336 
Note: See TracChangeset for help on using the changeset viewer.