Changeset e65c3ba in sasmodels for sasmodels/special.py
- Timestamp:
- Nov 28, 2017 6:09:34 PM (6 years ago)
- Branches:
- master, core_shell_microgels, magnetic_model, ticket-1257-vesicle-product, ticket_1156, ticket_1265_superball, ticket_822_more_unit_tests
- Children:
- 32398dc
- Parents:
- 110f69c
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sasmodels/special.py
r110f69c re65c3ba 192 192 193 193 """ 194 # pylint: disable=unused-import 195 194 196 import numpy as np 195 import scipy.special196 197 197 198 # Functions to add to our standard set … … 199 200 200 201 # C99 standard math library functions 201 M_PI, M_PI_2, M_PI_4, M_SQRT1_2, M_E = np.pi, np.pi/2, np.pi/4, np.sqrt(0.5), np.e202 202 from numpy import exp, log, power as pow, expm1, sqrt 203 203 from numpy import sin, cos, tan, arcsin as asin, arccos as acos, arctan as atan … … 207 207 from numpy import NAN, inf as INFINITY 208 208 209 # erf, erfc, tgamma, lgamma **do not use**210 211 # non-standard constants and functions212 M_PI_180, M_4PI_3 = M_PI/180, 4*M_PI/3213 214 # can't do SINCOS in python; use "s, c = SINCOS(x)" instead215 def SINCOS(x): return sin(x), cos(x)216 217 def square(x): return x*x218 219 def cube(x): return x*x*x220 221 from numpy import sinc as _sinc222 def sas_sinx_x(x): return _sinc(x/M_PI)223 def powr(x, y): return x**y224 def pown(x, n): return x**n225 226 FLOAT_SIZE = 8227 228 def polevl(x, c, n): return np.polyval(c[:n], x)229 def p1evl(x, c, n): return np.polyval(np.hstack(([1.], c))[:n], x)230 231 209 from scipy.special import gamma as sas_gamma 232 210 from scipy.special import erf as sas_erf … … 236 214 from scipy.special import jn as sas_JN 237 215 216 # erf, erfc, tgamma, lgamma **do not use** 217 218 # C99 standard math constants 219 M_PI, M_PI_2, M_PI_4, M_SQRT1_2, M_E = np.pi, np.pi/2, np.pi/4, np.sqrt(0.5), np.e 220 221 # non-standard constants 222 M_PI_180, M_4PI_3 = M_PI/180, 4*M_PI/3 223 224 # can't do SINCOS in python; use "s, c = SINCOS(x)" instead 225 def SINCOS(x): 226 """return sin(x), cos(x)""" 227 return sin(x), cos(x) 228 229 def square(x): 230 """return x^2""" 231 return x*x 232 233 def cube(x): 234 """return x^3""" 235 return x*x*x 236 237 def sas_sinx_x(x): 238 """return sin(x)/x""" 239 from numpy import sinc as _sinc 240 return _sinc(x/M_PI) 241 242 def powr(x, y): 243 """return x^y for x>0""" 244 return x**y 245 def pown(x, n): 246 """return x^n for n integer""" 247 return x**n 248 249 FLOAT_SIZE = 8 250 251 def polevl(x, c, n): 252 """return p(x) for polynomial p of degree n-1 with coefficients c""" 253 return np.polyval(c[:n], x) 254 255 def p1evl(x, c, n): 256 """return x^n + p(x) for polynomial p of degree n-1 with coefficients c""" 257 return np.polyval(np.hstack(([1.], c))[:n], x) 258 238 259 def sas_Si(x): 239 return scipy.special.sici(x)[0] 260 """return Si(x)""" 261 from scipy.special import sici 262 return sici(x)[0] 240 263 241 264 def sas_j1(x): 265 """return j1(x)""" 242 266 if np.isscalar(x): 243 267 retvalue = (sin(x) - x*cos(x))/x**2 if x != 0. else 0. … … 246 270 retvalue = (sin(x) - x*cos(x))/x**2 247 271 retvalue[x == 0.] = 0. 272 return retvalue 248 273 249 274 def sas_3j1x_x(x): 275 """return 3*j1(x)/x""" 250 276 if np.isscalar(x): 251 277 retvalue = 3*(sin(x) - x*cos(x))/x**3 if x != 0. else 1. … … 257 283 258 284 def sas_2J1x_x(x): 285 """return 2*J1(x)/x""" 259 286 if np.isscalar(x): 260 287 retvalue = 2*sas_J1(x)/x if x != 0 else 1.
Note: See TracChangeset
for help on using the changeset viewer.