Changeset b966a96 in sasmodels


Ignore:
Timestamp:
Jul 21, 2016 5:12:18 PM (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:
6a0d6aa
Parents:
32e3c9b
Message:

better line numbers for compiler errors; tinycc support (mostly)

Location:
sasmodels
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • sasmodels/generate.py

    r32e3c9b rb966a96  
    540540 
    541541    # Define the parameter table 
     542    # TODO: plug in current line number 
     543    source.append('#line 542 "sasmodels/generate.py"') 
    542544    source.append("#define PARAMETER_TABLE \\") 
    543545    source.append("\\\n".join(p.as_definition() 
     
    580582 
    581583    source.append("#if defined(USE_OPENCL)") 
    582     source.extend(_add_kernels(ocl_code[0], call_iq, call_iqxy, model_info.name)) 
     584    source.extend(_add_kernels(ocl_code, call_iq, call_iqxy, model_info.name)) 
    583585    source.append("#else /* !USE_OPENCL */") 
    584     source.extend(_add_kernels(dll_code[0], call_iq, call_iqxy, model_info.name)) 
     586    source.extend(_add_kernels(dll_code, call_iq, call_iqxy, model_info.name)) 
    585587    source.append("#endif /* !USE_OPENCL */") 
    586588    return '\n'.join(source) 
    587589 
    588590 
    589 def _add_kernels(kernel_code, call_iq, call_iqxy, name): 
    590     # type: (str, str, str, str) -> List[str] 
     591def _add_kernels(kernel, call_iq, call_iqxy, name): 
     592    # type: ([str,str], str, str, str) -> List[str] 
     593    code = kernel[0] 
     594    path = kernel[1].replace('\\', '\\\\') 
    591595    source = [ 
    592596        # define the Iq kernel 
    593597        "#define KERNEL_NAME %s_Iq" % name, 
    594598        call_iq, 
    595         kernel_code, 
     599        '#line 1 "%s-Iq"' % path, 
     600        code, 
    596601        "#undef CALL_IQ", 
    597602        "#undef KERNEL_NAME", 
     
    600605        "#define KERNEL_NAME %s_Iqxy" % name, 
    601606        call_iqxy, 
    602         kernel_code, 
     607        '#line 1 "%s-Iqxy"' % path, 
     608        code, 
    603609        "#undef CALL_IQ", 
    604610        "#undef KERNEL_NAME", 
     
    608614        "#define MAGNETIC 1", 
    609615        call_iqxy, 
    610         kernel_code, 
     616        '#line 1 "%s-Imagnetic"' % path, 
     617        code, 
    611618        "#undef MAGNETIC", 
    612619        "#undef CALL_IQ", 
  • sasmodels/kernel_header.c

    rba32cdd rb966a96  
    88// Note: if using a C++ compiler, then define kernel as extern "C" 
    99#ifndef USE_OPENCL 
     10// Use SAS_DOUBLE to force the use of double even for float kernels 
     11#  define SAS_DOUBLE dou ## ble 
    1012#  ifdef __cplusplus 
    1113      #include <cstdio> 
     
    1618         #include <float.h> 
    1719         #define kernel extern "C" __declspec( dllexport ) 
    18          static double trunc(double x) { return x>=0?floor(x):-floor(-x); } 
    19          static double fmin(double x, double y) { return x>y ? y : x; } 
    20          static double fmax(double x, double y) { return x<y ? y : x; } 
    21          static double isnan(double x) { return _isnan(x); } 
     20         inline double trunc(double x) { return x>=0?floor(x):-floor(-x); } 
     21         inline double fmin(double x, double y) { return x>y ? y : x; } 
     22         inline double fmax(double x, double y) { return x<y ? y : x; } 
     23         #define isnan(x) _isnan(x) 
     24         #define isinf(x) (!_finite(x)) 
     25         #define isfinite(x) _finite(x) 
    2226         #define NAN (std::numeric_limits<double>::quiet_NaN()) // non-signalling NaN 
    23          static double cephes_expm1(double x) { 
    24             // Adapted from the cephes math library. 
    25             // Copyright 1984 - 1992 by Stephen L. Moshier 
    26             if (x != x || x == 0.0) { 
    27                return x; // NaN and +/- 0 
    28             } else if (x < -0.5 || x > 0.5) { 
    29                return exp(x) - 1.0; 
    30             } else { 
    31                const double xsq = x*x; 
    32                const double p = ((( 
    33                   +1.2617719307481059087798E-4)*xsq 
    34                   +3.0299440770744196129956E-2)*xsq 
    35                   +9.9999999999999999991025E-1); 
    36                const double q = (((( 
    37                   +3.0019850513866445504159E-6)*xsq 
    38                   +2.5244834034968410419224E-3)*xsq 
    39                   +2.2726554820815502876593E-1)*xsq 
    40                   +2.0000000000000000000897E0); 
    41                double r = x * p; 
    42                r =  r / (q - r); 
    43                return r+r; 
    44              } 
    45          } 
    46          #define expm1 cephes_expm1 
    47          typedef __int32 int32_t 
     27         #define INFINITY (std::numeric_limits<double>::infinity()) 
     28         #define NEED_EXPM1 
     29         #define NEED_TGAMMA 
    4830     #else 
    4931         #define kernel extern "C" 
    5032         #include <cstdint> 
    5133     #endif 
    52      static void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); } 
     34     inline void SINCOS(double angle, double &svar, double &cvar) { svar=sin(angle); cvar=cos(angle); } 
    5335#  else 
    5436     #include <inttypes.h>  // C99 guarantees that int32_t types is here 
    5537     #include <stdio.h> 
    56      #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf 
     38     #if defined(__TINYC__) 
     39         typedef int int32_t; 
     40         #include <math.h> 
     41         // TODO: test isnan 
     42         inline double _isnan(double x) { return x != x; } // hope this doesn't optimize away! 
     43         #undef isnan 
     44         #define isnan(x) _isnan(x) 
     45         // Defeat the double->float conversion since we don't have tgmath 
     46         inline SAS_DOUBLE trunc(SAS_DOUBLE x) { return x>=0?floor(x):-floor(-x); } 
     47         inline SAS_DOUBLE fmin(SAS_DOUBLE x, SAS_DOUBLE y) { return x>y ? y : x; } 
     48         inline SAS_DOUBLE fmax(SAS_DOUBLE x, SAS_DOUBLE y) { return x<y ? y : x; } 
     49         #define NEED_EXPM1 
     50         #define NEED_TGAMMA 
     51     #else 
     52         #include <tgmath.h> // C99 type-generic math, so sin(float) => sinf 
     53     #endif 
    5754     // MSVC doesn't support C99, so no need for dllexport on C99 branch 
    5855     #define kernel 
     
    7370#    define SINCOS(angle,svar,cvar) do {const double _t_=angle; svar=sin(_t_);cvar=cos(_t_);} while (0) 
    7471#  endif 
     72#endif 
     73 
     74#if defined(NEED_EXPM1) 
     75   static SAS_DOUBLE expm1(SAS_DOUBLE x_in) { 
     76      double x = (double)x_in;  // go back to float for single precision kernels 
     77      // Adapted from the cephes math library. 
     78      // Copyright 1984 - 1992 by Stephen L. Moshier 
     79      if (x != x || x == 0.0) { 
     80         return x; // NaN and +/- 0 
     81      } else if (x < -0.5 || x > 0.5) { 
     82         return exp(x) - 1.0; 
     83      } else { 
     84         const double xsq = x*x; 
     85         const double p = ((( 
     86            +1.2617719307481059087798E-4)*xsq 
     87            +3.0299440770744196129956E-2)*xsq 
     88            +9.9999999999999999991025E-1); 
     89         const double q = (((( 
     90            +3.0019850513866445504159E-6)*xsq 
     91            +2.5244834034968410419224E-3)*xsq 
     92            +2.2726554820815502876593E-1)*xsq 
     93            +2.0000000000000000000897E0); 
     94         double r = x * p; 
     95         r =  r / (q - r); 
     96         return r+r; 
     97       } 
     98   } 
    7599#endif 
    76100 
     
    103127#  define M_4PI_3 4.18879020478639 
    104128#endif 
    105 static double square(double x) { return x*x; } 
    106 static double cube(double x) { return x*x*x; } 
    107 static double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; } 
     129inline double square(double x) { return x*x; } 
     130inline double cube(double x) { return x*x*x; } 
     131inline double sinc(double x) { return x==0 ? 1.0 : sin(x)/x; } 
    108132 
  • sasmodels/kernel_iq.c

    r32e3c9b rb966a96  
    2929 
    3030typedef struct { 
    31     PARAMETER_TABLE; 
     31    PARAMETER_TABLE 
    3232} ParameterBlock; 
    3333#endif 
     
    4141static double clip(double value, double low, double high) 
    4242{ 
    43     return (value < low ? low : (value > high ? high : value)); 
     43  return (value < low ? low : (value > high ? high : value)); 
    4444} 
    4545 
     
    5353    double *uu, double *dd, double *ud, double *du) 
    5454{ 
    55     in_spin = clip(in_spin, 0.0, 1.0); 
    56     out_spin = clip(out_spin, 0.0, 1.0); 
    57         *uu = sqrt(sqrt(in_spin * out_spin)); 
    58         *dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin))); 
    59         *ud = sqrt(sqrt(in_spin * (1.0-out_spin))); 
    60         *du = sqrt(sqrt((1.0-in_spin) * out_spin)); 
     55  in_spin = clip(in_spin, 0.0, 1.0); 
     56  out_spin = clip(out_spin, 0.0, 1.0); 
     57  *uu = sqrt(sqrt(in_spin * out_spin)); 
     58  *dd = sqrt(sqrt((1.0-in_spin) * (1.0-out_spin))); 
     59  *ud = sqrt(sqrt(in_spin * (1.0-out_spin))); 
     60  *du = sqrt(sqrt((1.0-in_spin) * out_spin)); 
    6161} 
    6262 
    6363// Convert polar to rectangular coordinates. 
    6464static void polrec(double r, double theta, double phi, 
    65     double *x, double *y, double *z) 
     65  double *x, double *y, double *z) 
    6666{ 
    67     double cos_theta, sin_theta, cos_phi, sin_phi; 
    68     SINCOS(theta*M_PI_180, sin_theta, cos_theta); 
    69     SINCOS(phi*M_PI_180, sin_phi, cos_phi); 
    70     *x = r * cos_theta * cos_phi; 
    71     *y = r * sin_theta; 
    72     *z = -r * cos_theta * sin_phi; 
     67  double cos_theta, sin_theta, cos_phi, sin_phi; 
     68  SINCOS(theta*M_PI_180, sin_theta, cos_theta); 
     69  SINCOS(phi*M_PI_180, sin_phi, cos_phi); 
     70  *x = r * cos_theta * cos_phi; 
     71  *y = r * sin_theta; 
     72  *z = -r * cos_theta * sin_phi; 
    7373} 
    7474#endif 
  • sasmodels/kerneldll.py

    r32e3c9b rb966a96  
    292292        if self._dll is None: 
    293293            self._load_dll() 
    294         kernel = [self._Iqxy, self._Imagnetic] if q_input.is_2d else self._Iq 
     294        kernel = [self._Iqxy, self._Imagnetic] if q_input.is_2d else [self._Iq]*2 
    295295        return DllKernel(kernel, self.info, q_input) 
    296296 
Note: See TracChangeset for help on using the changeset viewer.