__init__.py 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  1. __version__ = '1.2.1'
  2. from .usertools import monitor, timing
  3. from .ctx_fp import FPContext
  4. from .ctx_mp import MPContext
  5. from .ctx_iv import MPIntervalContext
  6. fp = FPContext()
  7. mp = MPContext()
  8. iv = MPIntervalContext()
  9. fp._mp = mp
  10. mp._mp = mp
  11. iv._mp = mp
  12. mp._fp = fp
  13. fp._fp = fp
  14. mp._iv = iv
  15. fp._iv = iv
  16. iv._iv = iv
  17. # XXX: extremely bad pickle hack
  18. from . import ctx_mp as _ctx_mp
  19. _ctx_mp._mpf_module.mpf = mp.mpf
  20. _ctx_mp._mpf_module.mpc = mp.mpc
  21. make_mpf = mp.make_mpf
  22. make_mpc = mp.make_mpc
  23. extraprec = mp.extraprec
  24. extradps = mp.extradps
  25. workprec = mp.workprec
  26. workdps = mp.workdps
  27. autoprec = mp.autoprec
  28. maxcalls = mp.maxcalls
  29. memoize = mp.memoize
  30. mag = mp.mag
  31. bernfrac = mp.bernfrac
  32. qfrom = mp.qfrom
  33. mfrom = mp.mfrom
  34. kfrom = mp.kfrom
  35. taufrom = mp.taufrom
  36. qbarfrom = mp.qbarfrom
  37. ellipfun = mp.ellipfun
  38. jtheta = mp.jtheta
  39. kleinj = mp.kleinj
  40. eta = mp.eta
  41. qp = mp.qp
  42. qhyper = mp.qhyper
  43. qgamma = mp.qgamma
  44. qfac = mp.qfac
  45. nint_distance = mp.nint_distance
  46. plot = mp.plot
  47. cplot = mp.cplot
  48. splot = mp.splot
  49. odefun = mp.odefun
  50. jacobian = mp.jacobian
  51. findroot = mp.findroot
  52. multiplicity = mp.multiplicity
  53. isinf = mp.isinf
  54. isnan = mp.isnan
  55. isnormal = mp.isnormal
  56. isint = mp.isint
  57. isfinite = mp.isfinite
  58. almosteq = mp.almosteq
  59. nan = mp.nan
  60. rand = mp.rand
  61. absmin = mp.absmin
  62. absmax = mp.absmax
  63. fraction = mp.fraction
  64. linspace = mp.linspace
  65. arange = mp.arange
  66. mpmathify = convert = mp.convert
  67. mpc = mp.mpc
  68. mpi = iv._mpi
  69. nstr = mp.nstr
  70. nprint = mp.nprint
  71. chop = mp.chop
  72. fneg = mp.fneg
  73. fadd = mp.fadd
  74. fsub = mp.fsub
  75. fmul = mp.fmul
  76. fdiv = mp.fdiv
  77. fprod = mp.fprod
  78. quad = mp.quad
  79. quadgl = mp.quadgl
  80. quadts = mp.quadts
  81. quadosc = mp.quadosc
  82. invertlaplace = mp.invertlaplace
  83. invlaptalbot = mp.invlaptalbot
  84. invlapstehfest = mp.invlapstehfest
  85. invlapdehoog = mp.invlapdehoog
  86. pslq = mp.pslq
  87. identify = mp.identify
  88. findpoly = mp.findpoly
  89. richardson = mp.richardson
  90. shanks = mp.shanks
  91. levin = mp.levin
  92. cohen_alt = mp.cohen_alt
  93. nsum = mp.nsum
  94. nprod = mp.nprod
  95. difference = mp.difference
  96. diff = mp.diff
  97. diffs = mp.diffs
  98. diffs_prod = mp.diffs_prod
  99. diffs_exp = mp.diffs_exp
  100. diffun = mp.diffun
  101. differint = mp.differint
  102. taylor = mp.taylor
  103. pade = mp.pade
  104. polyval = mp.polyval
  105. polyroots = mp.polyroots
  106. fourier = mp.fourier
  107. fourierval = mp.fourierval
  108. sumem = mp.sumem
  109. sumap = mp.sumap
  110. chebyfit = mp.chebyfit
  111. limit = mp.limit
  112. matrix = mp.matrix
  113. eye = mp.eye
  114. diag = mp.diag
  115. zeros = mp.zeros
  116. ones = mp.ones
  117. hilbert = mp.hilbert
  118. randmatrix = mp.randmatrix
  119. swap_row = mp.swap_row
  120. extend = mp.extend
  121. norm = mp.norm
  122. mnorm = mp.mnorm
  123. lu_solve = mp.lu_solve
  124. lu = mp.lu
  125. qr = mp.qr
  126. unitvector = mp.unitvector
  127. inverse = mp.inverse
  128. residual = mp.residual
  129. qr_solve = mp.qr_solve
  130. cholesky = mp.cholesky
  131. cholesky_solve = mp.cholesky_solve
  132. det = mp.det
  133. cond = mp.cond
  134. hessenberg = mp.hessenberg
  135. schur = mp.schur
  136. eig = mp.eig
  137. eig_sort = mp.eig_sort
  138. eigsy = mp.eigsy
  139. eighe = mp.eighe
  140. eigh = mp.eigh
  141. svd_r = mp.svd_r
  142. svd_c = mp.svd_c
  143. svd = mp.svd
  144. gauss_quadrature = mp.gauss_quadrature
  145. expm = mp.expm
  146. sqrtm = mp.sqrtm
  147. powm = mp.powm
  148. logm = mp.logm
  149. sinm = mp.sinm
  150. cosm = mp.cosm
  151. mpf = mp.mpf
  152. j = mp.j
  153. exp = mp.exp
  154. expj = mp.expj
  155. expjpi = mp.expjpi
  156. ln = mp.ln
  157. im = mp.im
  158. re = mp.re
  159. inf = mp.inf
  160. ninf = mp.ninf
  161. sign = mp.sign
  162. eps = mp.eps
  163. pi = mp.pi
  164. ln2 = mp.ln2
  165. ln10 = mp.ln10
  166. phi = mp.phi
  167. e = mp.e
  168. euler = mp.euler
  169. catalan = mp.catalan
  170. khinchin = mp.khinchin
  171. glaisher = mp.glaisher
  172. apery = mp.apery
  173. degree = mp.degree
  174. twinprime = mp.twinprime
  175. mertens = mp.mertens
  176. ldexp = mp.ldexp
  177. frexp = mp.frexp
  178. fsum = mp.fsum
  179. fdot = mp.fdot
  180. sqrt = mp.sqrt
  181. cbrt = mp.cbrt
  182. exp = mp.exp
  183. ln = mp.ln
  184. log = mp.log
  185. log10 = mp.log10
  186. power = mp.power
  187. cos = mp.cos
  188. sin = mp.sin
  189. tan = mp.tan
  190. cosh = mp.cosh
  191. sinh = mp.sinh
  192. tanh = mp.tanh
  193. acos = mp.acos
  194. asin = mp.asin
  195. atan = mp.atan
  196. asinh = mp.asinh
  197. acosh = mp.acosh
  198. atanh = mp.atanh
  199. sec = mp.sec
  200. csc = mp.csc
  201. cot = mp.cot
  202. sech = mp.sech
  203. csch = mp.csch
  204. coth = mp.coth
  205. asec = mp.asec
  206. acsc = mp.acsc
  207. acot = mp.acot
  208. asech = mp.asech
  209. acsch = mp.acsch
  210. acoth = mp.acoth
  211. cospi = mp.cospi
  212. sinpi = mp.sinpi
  213. sinc = mp.sinc
  214. sincpi = mp.sincpi
  215. cos_sin = mp.cos_sin
  216. cospi_sinpi = mp.cospi_sinpi
  217. fabs = mp.fabs
  218. re = mp.re
  219. im = mp.im
  220. conj = mp.conj
  221. floor = mp.floor
  222. ceil = mp.ceil
  223. nint = mp.nint
  224. frac = mp.frac
  225. root = mp.root
  226. nthroot = mp.nthroot
  227. hypot = mp.hypot
  228. fmod = mp.fmod
  229. ldexp = mp.ldexp
  230. frexp = mp.frexp
  231. sign = mp.sign
  232. arg = mp.arg
  233. phase = mp.phase
  234. polar = mp.polar
  235. rect = mp.rect
  236. degrees = mp.degrees
  237. radians = mp.radians
  238. atan2 = mp.atan2
  239. fib = mp.fib
  240. fibonacci = mp.fibonacci
  241. lambertw = mp.lambertw
  242. zeta = mp.zeta
  243. altzeta = mp.altzeta
  244. gamma = mp.gamma
  245. rgamma = mp.rgamma
  246. factorial = mp.factorial
  247. fac = mp.fac
  248. fac2 = mp.fac2
  249. beta = mp.beta
  250. betainc = mp.betainc
  251. psi = mp.psi
  252. #psi0 = mp.psi0
  253. #psi1 = mp.psi1
  254. #psi2 = mp.psi2
  255. #psi3 = mp.psi3
  256. polygamma = mp.polygamma
  257. digamma = mp.digamma
  258. #trigamma = mp.trigamma
  259. #tetragamma = mp.tetragamma
  260. #pentagamma = mp.pentagamma
  261. harmonic = mp.harmonic
  262. bernoulli = mp.bernoulli
  263. bernfrac = mp.bernfrac
  264. stieltjes = mp.stieltjes
  265. hurwitz = mp.hurwitz
  266. dirichlet = mp.dirichlet
  267. bernpoly = mp.bernpoly
  268. eulerpoly = mp.eulerpoly
  269. eulernum = mp.eulernum
  270. polylog = mp.polylog
  271. clsin = mp.clsin
  272. clcos = mp.clcos
  273. gammainc = mp.gammainc
  274. gammaprod = mp.gammaprod
  275. binomial = mp.binomial
  276. rf = mp.rf
  277. ff = mp.ff
  278. hyper = mp.hyper
  279. hyp0f1 = mp.hyp0f1
  280. hyp1f1 = mp.hyp1f1
  281. hyp1f2 = mp.hyp1f2
  282. hyp2f1 = mp.hyp2f1
  283. hyp2f2 = mp.hyp2f2
  284. hyp2f0 = mp.hyp2f0
  285. hyp2f3 = mp.hyp2f3
  286. hyp3f2 = mp.hyp3f2
  287. hyperu = mp.hyperu
  288. hypercomb = mp.hypercomb
  289. meijerg = mp.meijerg
  290. appellf1 = mp.appellf1
  291. appellf2 = mp.appellf2
  292. appellf3 = mp.appellf3
  293. appellf4 = mp.appellf4
  294. hyper2d = mp.hyper2d
  295. bihyper = mp.bihyper
  296. erf = mp.erf
  297. erfc = mp.erfc
  298. erfi = mp.erfi
  299. erfinv = mp.erfinv
  300. npdf = mp.npdf
  301. ncdf = mp.ncdf
  302. expint = mp.expint
  303. e1 = mp.e1
  304. ei = mp.ei
  305. li = mp.li
  306. ci = mp.ci
  307. si = mp.si
  308. chi = mp.chi
  309. shi = mp.shi
  310. fresnels = mp.fresnels
  311. fresnelc = mp.fresnelc
  312. airyai = mp.airyai
  313. airybi = mp.airybi
  314. airyaizero = mp.airyaizero
  315. airybizero = mp.airybizero
  316. scorergi = mp.scorergi
  317. scorerhi = mp.scorerhi
  318. ellipk = mp.ellipk
  319. ellipe = mp.ellipe
  320. ellipf = mp.ellipf
  321. ellippi = mp.ellippi
  322. elliprc = mp.elliprc
  323. elliprj = mp.elliprj
  324. elliprf = mp.elliprf
  325. elliprd = mp.elliprd
  326. elliprg = mp.elliprg
  327. agm = mp.agm
  328. jacobi = mp.jacobi
  329. chebyt = mp.chebyt
  330. chebyu = mp.chebyu
  331. legendre = mp.legendre
  332. legenp = mp.legenp
  333. legenq = mp.legenq
  334. hermite = mp.hermite
  335. pcfd = mp.pcfd
  336. pcfu = mp.pcfu
  337. pcfv = mp.pcfv
  338. pcfw = mp.pcfw
  339. gegenbauer = mp.gegenbauer
  340. laguerre = mp.laguerre
  341. spherharm = mp.spherharm
  342. besselj = mp.besselj
  343. j0 = mp.j0
  344. j1 = mp.j1
  345. besseli = mp.besseli
  346. bessely = mp.bessely
  347. besselk = mp.besselk
  348. besseljzero = mp.besseljzero
  349. besselyzero = mp.besselyzero
  350. hankel1 = mp.hankel1
  351. hankel2 = mp.hankel2
  352. struveh = mp.struveh
  353. struvel = mp.struvel
  354. angerj = mp.angerj
  355. webere = mp.webere
  356. lommels1 = mp.lommels1
  357. lommels2 = mp.lommels2
  358. whitm = mp.whitm
  359. whitw = mp.whitw
  360. ber = mp.ber
  361. bei = mp.bei
  362. ker = mp.ker
  363. kei = mp.kei
  364. coulombc = mp.coulombc
  365. coulombf = mp.coulombf
  366. coulombg = mp.coulombg
  367. barnesg = mp.barnesg
  368. superfac = mp.superfac
  369. hyperfac = mp.hyperfac
  370. loggamma = mp.loggamma
  371. siegeltheta = mp.siegeltheta
  372. siegelz = mp.siegelz
  373. grampoint = mp.grampoint
  374. zetazero = mp.zetazero
  375. riemannr = mp.riemannr
  376. primepi = mp.primepi
  377. primepi2 = mp.primepi2
  378. primezeta = mp.primezeta
  379. bell = mp.bell
  380. polyexp = mp.polyexp
  381. expm1 = mp.expm1
  382. log1p = mp.log1p
  383. powm1 = mp.powm1
  384. unitroots = mp.unitroots
  385. cyclotomic = mp.cyclotomic
  386. mangoldt = mp.mangoldt
  387. secondzeta = mp.secondzeta
  388. nzeros = mp.nzeros
  389. backlunds = mp.backlunds
  390. lerchphi = mp.lerchphi
  391. stirling1 = mp.stirling1
  392. stirling2 = mp.stirling2
  393. # be careful when changing this name, don't use test*!
  394. def runtests():
  395. """
  396. Run all mpmath tests and print output.
  397. """
  398. import os.path
  399. from inspect import getsourcefile
  400. from .tests import runtests as tests
  401. testdir = os.path.dirname(os.path.abspath(getsourcefile(tests)))
  402. importdir = os.path.abspath(testdir + '/../..')
  403. tests.testit(importdir, testdir)
  404. def doctests(filter=[]):
  405. import sys
  406. from timeit import default_timer as clock
  407. for i, arg in enumerate(sys.argv):
  408. if '__init__.py' in arg:
  409. filter = [sn for sn in sys.argv[i+1:] if not sn.startswith("-")]
  410. break
  411. import doctest
  412. globs = globals().copy()
  413. for obj in globs: #sorted(globs.keys()):
  414. if filter:
  415. if not sum([pat in obj for pat in filter]):
  416. continue
  417. sys.stdout.write(str(obj) + " ")
  418. sys.stdout.flush()
  419. t1 = clock()
  420. doctest.run_docstring_examples(globs[obj], {}, verbose=("-v" in sys.argv))
  421. t2 = clock()
  422. print(round(t2-t1, 3))
  423. if __name__ == '__main__':
  424. doctests()