Changes in sasmodels/kerneldll.py [a30cdd5:5edfe12] in sasmodels


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/kerneldll.py

    ra30cdd5 r5edfe12  
    1 """ 
     1r""" 
    22C types wrapper for sasview models. 
    33 
     
    55you wish to allow single precision floating point evaluation for the compiled 
    66models, otherwise it defaults to *False*. 
     7 
     8The compiler command line is stored in the attribute *COMPILE*, with string 
     9substitutions for %(source)s and %(output)s indicating what to compile and 
     10where to store it.  The actual command is system dependent. 
     11 
     12On windows systems, you have a choice of compilers.  *MinGW* is the GNU 
     13compiler toolchain, available in packages such as anaconda and PythonXY, 
     14or available stand alone. This toolchain has had difficulties on some 
     15systems, and may or may not work for you.  In order to build DLLs, *gcc* 
     16must be on your path.  If the environment variable *SAS_OPENMP* is given 
     17then -fopenmp is added to the compiler flags.  This requires a version 
     18of MinGW compiled with OpenMP support. 
     19 
     20An alternative toolchain uses the Microsoft Visual C++ compiler, available 
     21free from microsoft: 
     22 
     23    `http://www.microsoft.com/en-us/download/details.aspx?id=44266`_ 
     24 
     25Again, this requires that the compiler is available on your path.  This is 
     26done by running vcvarsall.bat in a windows terminal.  Install locations are 
     27system dependent, such as: 
     28 
     29    C:\Program Files (x86)\Common Files\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
     30 
     31or maybe 
     32 
     33    C:\Users\yourname\AppData\Local\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat 
     34 
     35And again, the environment variable *SAS_OPENMP* controls whether OpenMP is 
     36used to compile the C code.  This requires the Microsoft vcomp90.dll library, 
     37which doesn't seem to be included with the compiler, nor does there appear 
     38to be a public download location.  There may be one on your machine already 
     39in a location such as: 
     40 
     41    C:\Windows\winsxs\x86_microsoft.vc90.openmp*\vcomp90.dll 
     42 
     43If you copy this onto your path, such as the python directory or the install 
     44directory for this application, then OpenMP should be supported. 
    745""" 
    846 
     
    1149import tempfile 
    1250import ctypes as ct 
    13 from ctypes import c_void_p, c_int, c_double, c_float 
     51from ctypes import c_void_p, c_int, c_longdouble, c_double, c_float 
    1452 
    1553import numpy as np 
     
    5896    if np.dtype(dtype) == generate.F32: 
    5997        basename += "32" 
     98    elif np.dtype(dtype) == generate.F64: 
     99        basename += "64" 
     100    else: 
     101        basename += "128" 
    60102    return joinpath(DLL_PATH, basename+'.so') 
    61103 
     
    80122    models are allowed as DLLs. 
    81123    """ 
    82     if not ALLOW_SINGLE_PRECISION_DLLS: dtype = "double"   # Force 64-bit dll 
    83124    dtype = np.dtype(dtype) 
     125    if dtype == generate.F32 and not ALLOW_SINGLE_PRECISION_DLLS: 
     126        dtype = generate.F64  # Force 64-bit dll 
    84127 
    85128    if callable(info.get('Iq',None)): 
     
    89132        source = generate.use_single(source) 
    90133        tempfile_prefix = 'sas_'+info['name']+'32_' 
     134    elif dtype == generate.F64: 
     135        tempfile_prefix = 'sas_'+info['name']+'64_' 
    91136    else: 
    92         tempfile_prefix = 'sas_'+info['name']+'_' 
     137        source = generate.use_long_double(source) 
     138        tempfile_prefix = 'sas_'+info['name']+'128_' 
    93139 
    94140    source_files = generate.sources(info) + [info['filename']] 
     
    158204            raise 
    159205 
    160         fp = c_float if self.dtype == generate.F32 else c_double 
     206        fp = (c_float if self.dtype == generate.F32 
     207              else c_double if self.dtype == generate.F64 
     208              else c_longdouble) 
    161209        pd_args_1d = [c_void_p, fp] + [c_int]*Npd1d if Npd1d else [] 
    162210        pd_args_2d= [c_void_p, fp] + [c_int]*Npd2d if Npd2d else [] 
     
    227275 
    228276    def __call__(self, fixed_pars, pd_pars, cutoff): 
    229         real = np.float32 if self.q_input.dtype == generate.F32 else np.float64 
     277        real = (np.float32 if self.q_input.dtype == generate.F32 
     278                else np.float64 if self.q_input.dtype == generate.F64 
     279                else np.float128) 
    230280 
    231281        nq = c_int(self.q_input.nq) 
Note: See TracChangeset for help on using the changeset viewer.