shomez commited on
Commit
e8d9ef4
·
verified ·
1 Parent(s): 101cd2b

Upload __init__.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. __init__.py +466 -130
__init__.py CHANGED
@@ -1,132 +1,468 @@
1
- import sys
2
- import os
3
- import re
4
- import importlib
5
- import warnings
6
-
7
-
8
- is_pypy = '__pypy__' in sys.builtin_module_names
9
-
10
-
11
- warnings.filterwarnings('ignore',
12
- r'.+ distutils\b.+ deprecated',
13
- DeprecationWarning)
14
-
15
-
16
- def warn_distutils_present():
17
- if 'distutils' not in sys.modules:
18
- return
19
- if is_pypy and sys.version_info < (3, 7):
20
- # PyPy for 3.6 unconditionally imports distutils, so bypass the warning
21
- # https://foss.heptapod.net/pypy/pypy/-/blob/be829135bc0d758997b3566062999ee8b23872b4/lib-python/3/site.py#L250
22
- return
23
- warnings.warn(
24
- "Distutils was imported before Setuptools, but importing Setuptools "
25
- "also replaces the `distutils` module in `sys.modules`. This may lead "
26
- "to undesirable behaviors or errors. To avoid these issues, avoid "
27
- "using distutils directly, ensure that setuptools is installed in the "
28
- "traditional way (e.g. not an editable install), and/or make sure "
29
- "that setuptools is always imported before distutils.")
30
-
31
-
32
- def clear_distutils():
33
- if 'distutils' not in sys.modules:
34
- return
35
- warnings.warn("Setuptools is replacing distutils.")
36
- mods = [name for name in sys.modules if re.match(r'distutils\b', name)]
37
- for name in mods:
38
- del sys.modules[name]
39
-
40
-
41
- def enabled():
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  """
43
- Allow selection of distutils by environment variable.
44
  """
45
- which = os.environ.get('SETUPTOOLS_USE_DISTUTILS', 'stdlib')
46
- return which == 'local'
47
-
48
-
49
- def ensure_local_distutils():
50
- clear_distutils()
51
-
52
- # With the DistutilsMetaFinder in place,
53
- # perform an import to cause distutils to be
54
- # loaded from setuptools._distutils. Ref #2906.
55
- add_shim()
56
- importlib.import_module('distutils')
57
- remove_shim()
58
-
59
- # check that submodules load as expected
60
- core = importlib.import_module('distutils.core')
61
- assert '_distutils' in core.__file__, core.__file__
62
-
63
-
64
- def do_override():
65
- """
66
- Ensure that the local copy of distutils is preferred over stdlib.
67
-
68
- See https://github.com/pypa/setuptools/issues/417#issuecomment-392298401
69
- for more motivation.
70
- """
71
- if enabled():
72
- warn_distutils_present()
73
- ensure_local_distutils()
74
-
75
-
76
- class DistutilsMetaFinder:
77
- def find_spec(self, fullname, path, target=None):
78
- if path is not None:
79
- return
80
-
81
- method_name = 'spec_for_{fullname}'.format(**locals())
82
- method = getattr(self, method_name, lambda: None)
83
- return method()
84
-
85
- def spec_for_distutils(self):
86
- import importlib.abc
87
- import importlib.util
88
-
89
- class DistutilsLoader(importlib.abc.Loader):
90
-
91
- def create_module(self, spec):
92
- return importlib.import_module('setuptools._distutils')
93
-
94
- def exec_module(self, module):
95
- pass
96
-
97
- return importlib.util.spec_from_loader('distutils', DistutilsLoader())
98
-
99
- def spec_for_pip(self):
100
- """
101
- Ensure stdlib distutils when running under pip.
102
- See pypa/pip#8761 for rationale.
103
- """
104
- if self.pip_imported_during_build():
105
- return
106
- clear_distutils()
107
- self.spec_for_distutils = lambda: None
108
-
109
- @staticmethod
110
- def pip_imported_during_build():
111
- """
112
- Detect if pip is being imported in a build script. Ref #2355.
113
- """
114
- import traceback
115
- return any(
116
- frame.f_globals['__file__'].endswith('setup.py')
117
- for frame, line in traceback.walk_stack(None)
118
- )
119
-
120
-
121
- DISTUTILS_FINDER = DistutilsMetaFinder()
122
-
123
-
124
- def add_shim():
125
- sys.meta_path.insert(0, DISTUTILS_FINDER)
126
-
127
-
128
- def remove_shim():
129
- try:
130
- sys.meta_path.remove(DISTUTILS_FINDER)
131
- except ValueError:
132
- pass
 
1
+ __version__ = '1.3.0'
2
+
3
+ from .usertools import monitor, timing
4
+
5
+ from .ctx_fp import FPContext
6
+ from .ctx_mp import MPContext
7
+ from .ctx_iv import MPIntervalContext
8
+
9
+ fp = FPContext()
10
+ mp = MPContext()
11
+ iv = MPIntervalContext()
12
+
13
+ fp._mp = mp
14
+ mp._mp = mp
15
+ iv._mp = mp
16
+ mp._fp = fp
17
+ fp._fp = fp
18
+ mp._iv = iv
19
+ fp._iv = iv
20
+ iv._iv = iv
21
+
22
+ # XXX: extremely bad pickle hack
23
+ from . import ctx_mp as _ctx_mp
24
+ _ctx_mp._mpf_module.mpf = mp.mpf
25
+ _ctx_mp._mpf_module.mpc = mp.mpc
26
+
27
+ make_mpf = mp.make_mpf
28
+ make_mpc = mp.make_mpc
29
+
30
+ extraprec = mp.extraprec
31
+ extradps = mp.extradps
32
+ workprec = mp.workprec
33
+ workdps = mp.workdps
34
+ autoprec = mp.autoprec
35
+ maxcalls = mp.maxcalls
36
+ memoize = mp.memoize
37
+
38
+ mag = mp.mag
39
+
40
+ bernfrac = mp.bernfrac
41
+
42
+ qfrom = mp.qfrom
43
+ mfrom = mp.mfrom
44
+ kfrom = mp.kfrom
45
+ taufrom = mp.taufrom
46
+ qbarfrom = mp.qbarfrom
47
+ ellipfun = mp.ellipfun
48
+ jtheta = mp.jtheta
49
+ kleinj = mp.kleinj
50
+ eta = mp.eta
51
+
52
+ qp = mp.qp
53
+ qhyper = mp.qhyper
54
+ qgamma = mp.qgamma
55
+ qfac = mp.qfac
56
+
57
+ nint_distance = mp.nint_distance
58
+
59
+ plot = mp.plot
60
+ cplot = mp.cplot
61
+ splot = mp.splot
62
+
63
+ odefun = mp.odefun
64
+
65
+ jacobian = mp.jacobian
66
+ findroot = mp.findroot
67
+ multiplicity = mp.multiplicity
68
+
69
+ isinf = mp.isinf
70
+ isnan = mp.isnan
71
+ isnormal = mp.isnormal
72
+ isint = mp.isint
73
+ isfinite = mp.isfinite
74
+ almosteq = mp.almosteq
75
+ nan = mp.nan
76
+ rand = mp.rand
77
+
78
+ absmin = mp.absmin
79
+ absmax = mp.absmax
80
+
81
+ fraction = mp.fraction
82
+
83
+ linspace = mp.linspace
84
+ arange = mp.arange
85
+
86
+ mpmathify = convert = mp.convert
87
+ mpc = mp.mpc
88
+
89
+ mpi = iv._mpi
90
+
91
+ nstr = mp.nstr
92
+ nprint = mp.nprint
93
+ chop = mp.chop
94
+
95
+ fneg = mp.fneg
96
+ fadd = mp.fadd
97
+ fsub = mp.fsub
98
+ fmul = mp.fmul
99
+ fdiv = mp.fdiv
100
+ fprod = mp.fprod
101
+
102
+ quad = mp.quad
103
+ quadgl = mp.quadgl
104
+ quadts = mp.quadts
105
+ quadosc = mp.quadosc
106
+ quadsubdiv = mp.quadsubdiv
107
+
108
+ invertlaplace = mp.invertlaplace
109
+ invlaptalbot = mp.invlaptalbot
110
+ invlapstehfest = mp.invlapstehfest
111
+ invlapdehoog = mp.invlapdehoog
112
+
113
+ pslq = mp.pslq
114
+ identify = mp.identify
115
+ findpoly = mp.findpoly
116
+
117
+ richardson = mp.richardson
118
+ shanks = mp.shanks
119
+ levin = mp.levin
120
+ cohen_alt = mp.cohen_alt
121
+ nsum = mp.nsum
122
+ nprod = mp.nprod
123
+ difference = mp.difference
124
+ diff = mp.diff
125
+ diffs = mp.diffs
126
+ diffs_prod = mp.diffs_prod
127
+ diffs_exp = mp.diffs_exp
128
+ diffun = mp.diffun
129
+ differint = mp.differint
130
+ taylor = mp.taylor
131
+ pade = mp.pade
132
+ polyval = mp.polyval
133
+ polyroots = mp.polyroots
134
+ fourier = mp.fourier
135
+ fourierval = mp.fourierval
136
+ sumem = mp.sumem
137
+ sumap = mp.sumap
138
+ chebyfit = mp.chebyfit
139
+ limit = mp.limit
140
+
141
+ matrix = mp.matrix
142
+ eye = mp.eye
143
+ diag = mp.diag
144
+ zeros = mp.zeros
145
+ ones = mp.ones
146
+ hilbert = mp.hilbert
147
+ randmatrix = mp.randmatrix
148
+ swap_row = mp.swap_row
149
+ extend = mp.extend
150
+ norm = mp.norm
151
+ mnorm = mp.mnorm
152
+
153
+ lu_solve = mp.lu_solve
154
+ lu = mp.lu
155
+ qr = mp.qr
156
+ unitvector = mp.unitvector
157
+ inverse = mp.inverse
158
+ residual = mp.residual
159
+ qr_solve = mp.qr_solve
160
+ cholesky = mp.cholesky
161
+ cholesky_solve = mp.cholesky_solve
162
+ det = mp.det
163
+ cond = mp.cond
164
+ hessenberg = mp.hessenberg
165
+ schur = mp.schur
166
+ eig = mp.eig
167
+ eig_sort = mp.eig_sort
168
+ eigsy = mp.eigsy
169
+ eighe = mp.eighe
170
+ eigh = mp.eigh
171
+ svd_r = mp.svd_r
172
+ svd_c = mp.svd_c
173
+ svd = mp.svd
174
+ gauss_quadrature = mp.gauss_quadrature
175
+
176
+ expm = mp.expm
177
+ sqrtm = mp.sqrtm
178
+ powm = mp.powm
179
+ logm = mp.logm
180
+ sinm = mp.sinm
181
+ cosm = mp.cosm
182
+
183
+ mpf = mp.mpf
184
+ j = mp.j
185
+ exp = mp.exp
186
+ expj = mp.expj
187
+ expjpi = mp.expjpi
188
+ ln = mp.ln
189
+ im = mp.im
190
+ re = mp.re
191
+ inf = mp.inf
192
+ ninf = mp.ninf
193
+ sign = mp.sign
194
+
195
+ eps = mp.eps
196
+ pi = mp.pi
197
+ ln2 = mp.ln2
198
+ ln10 = mp.ln10
199
+ phi = mp.phi
200
+ e = mp.e
201
+ euler = mp.euler
202
+ catalan = mp.catalan
203
+ khinchin = mp.khinchin
204
+ glaisher = mp.glaisher
205
+ apery = mp.apery
206
+ degree = mp.degree
207
+ twinprime = mp.twinprime
208
+ mertens = mp.mertens
209
+
210
+ ldexp = mp.ldexp
211
+ frexp = mp.frexp
212
+
213
+ fsum = mp.fsum
214
+ fdot = mp.fdot
215
+
216
+ sqrt = mp.sqrt
217
+ cbrt = mp.cbrt
218
+ exp = mp.exp
219
+ ln = mp.ln
220
+ log = mp.log
221
+ log10 = mp.log10
222
+ power = mp.power
223
+ cos = mp.cos
224
+ sin = mp.sin
225
+ tan = mp.tan
226
+ cosh = mp.cosh
227
+ sinh = mp.sinh
228
+ tanh = mp.tanh
229
+ acos = mp.acos
230
+ asin = mp.asin
231
+ atan = mp.atan
232
+ asinh = mp.asinh
233
+ acosh = mp.acosh
234
+ atanh = mp.atanh
235
+ sec = mp.sec
236
+ csc = mp.csc
237
+ cot = mp.cot
238
+ sech = mp.sech
239
+ csch = mp.csch
240
+ coth = mp.coth
241
+ asec = mp.asec
242
+ acsc = mp.acsc
243
+ acot = mp.acot
244
+ asech = mp.asech
245
+ acsch = mp.acsch
246
+ acoth = mp.acoth
247
+ cospi = mp.cospi
248
+ sinpi = mp.sinpi
249
+ sinc = mp.sinc
250
+ sincpi = mp.sincpi
251
+ cos_sin = mp.cos_sin
252
+ cospi_sinpi = mp.cospi_sinpi
253
+ fabs = mp.fabs
254
+ re = mp.re
255
+ im = mp.im
256
+ conj = mp.conj
257
+ floor = mp.floor
258
+ ceil = mp.ceil
259
+ nint = mp.nint
260
+ frac = mp.frac
261
+ root = mp.root
262
+ nthroot = mp.nthroot
263
+ hypot = mp.hypot
264
+ fmod = mp.fmod
265
+ ldexp = mp.ldexp
266
+ frexp = mp.frexp
267
+ sign = mp.sign
268
+ arg = mp.arg
269
+ phase = mp.phase
270
+ polar = mp.polar
271
+ rect = mp.rect
272
+ degrees = mp.degrees
273
+ radians = mp.radians
274
+ atan2 = mp.atan2
275
+ fib = mp.fib
276
+ fibonacci = mp.fibonacci
277
+ lambertw = mp.lambertw
278
+ zeta = mp.zeta
279
+ altzeta = mp.altzeta
280
+ gamma = mp.gamma
281
+ rgamma = mp.rgamma
282
+ factorial = mp.factorial
283
+ fac = mp.fac
284
+ fac2 = mp.fac2
285
+ beta = mp.beta
286
+ betainc = mp.betainc
287
+ psi = mp.psi
288
+ #psi0 = mp.psi0
289
+ #psi1 = mp.psi1
290
+ #psi2 = mp.psi2
291
+ #psi3 = mp.psi3
292
+ polygamma = mp.polygamma
293
+ digamma = mp.digamma
294
+ #trigamma = mp.trigamma
295
+ #tetragamma = mp.tetragamma
296
+ #pentagamma = mp.pentagamma
297
+ harmonic = mp.harmonic
298
+ bernoulli = mp.bernoulli
299
+ bernfrac = mp.bernfrac
300
+ stieltjes = mp.stieltjes
301
+ hurwitz = mp.hurwitz
302
+ dirichlet = mp.dirichlet
303
+ bernpoly = mp.bernpoly
304
+ eulerpoly = mp.eulerpoly
305
+ eulernum = mp.eulernum
306
+ polylog = mp.polylog
307
+ clsin = mp.clsin
308
+ clcos = mp.clcos
309
+ gammainc = mp.gammainc
310
+ gammaprod = mp.gammaprod
311
+ binomial = mp.binomial
312
+ rf = mp.rf
313
+ ff = mp.ff
314
+ hyper = mp.hyper
315
+ hyp0f1 = mp.hyp0f1
316
+ hyp1f1 = mp.hyp1f1
317
+ hyp1f2 = mp.hyp1f2
318
+ hyp2f1 = mp.hyp2f1
319
+ hyp2f2 = mp.hyp2f2
320
+ hyp2f0 = mp.hyp2f0
321
+ hyp2f3 = mp.hyp2f3
322
+ hyp3f2 = mp.hyp3f2
323
+ hyperu = mp.hyperu
324
+ hypercomb = mp.hypercomb
325
+ meijerg = mp.meijerg
326
+ appellf1 = mp.appellf1
327
+ appellf2 = mp.appellf2
328
+ appellf3 = mp.appellf3
329
+ appellf4 = mp.appellf4
330
+ hyper2d = mp.hyper2d
331
+ bihyper = mp.bihyper
332
+ erf = mp.erf
333
+ erfc = mp.erfc
334
+ erfi = mp.erfi
335
+ erfinv = mp.erfinv
336
+ npdf = mp.npdf
337
+ ncdf = mp.ncdf
338
+ expint = mp.expint
339
+ e1 = mp.e1
340
+ ei = mp.ei
341
+ li = mp.li
342
+ ci = mp.ci
343
+ si = mp.si
344
+ chi = mp.chi
345
+ shi = mp.shi
346
+ fresnels = mp.fresnels
347
+ fresnelc = mp.fresnelc
348
+ airyai = mp.airyai
349
+ airybi = mp.airybi
350
+ airyaizero = mp.airyaizero
351
+ airybizero = mp.airybizero
352
+ scorergi = mp.scorergi
353
+ scorerhi = mp.scorerhi
354
+ ellipk = mp.ellipk
355
+ ellipe = mp.ellipe
356
+ ellipf = mp.ellipf
357
+ ellippi = mp.ellippi
358
+ elliprc = mp.elliprc
359
+ elliprj = mp.elliprj
360
+ elliprf = mp.elliprf
361
+ elliprd = mp.elliprd
362
+ elliprg = mp.elliprg
363
+ agm = mp.agm
364
+ jacobi = mp.jacobi
365
+ chebyt = mp.chebyt
366
+ chebyu = mp.chebyu
367
+ legendre = mp.legendre
368
+ legenp = mp.legenp
369
+ legenq = mp.legenq
370
+ hermite = mp.hermite
371
+ pcfd = mp.pcfd
372
+ pcfu = mp.pcfu
373
+ pcfv = mp.pcfv
374
+ pcfw = mp.pcfw
375
+ gegenbauer = mp.gegenbauer
376
+ laguerre = mp.laguerre
377
+ spherharm = mp.spherharm
378
+ besselj = mp.besselj
379
+ j0 = mp.j0
380
+ j1 = mp.j1
381
+ besseli = mp.besseli
382
+ bessely = mp.bessely
383
+ besselk = mp.besselk
384
+ besseljzero = mp.besseljzero
385
+ besselyzero = mp.besselyzero
386
+ hankel1 = mp.hankel1
387
+ hankel2 = mp.hankel2
388
+ struveh = mp.struveh
389
+ struvel = mp.struvel
390
+ angerj = mp.angerj
391
+ webere = mp.webere
392
+ lommels1 = mp.lommels1
393
+ lommels2 = mp.lommels2
394
+ whitm = mp.whitm
395
+ whitw = mp.whitw
396
+ ber = mp.ber
397
+ bei = mp.bei
398
+ ker = mp.ker
399
+ kei = mp.kei
400
+ coulombc = mp.coulombc
401
+ coulombf = mp.coulombf
402
+ coulombg = mp.coulombg
403
+ barnesg = mp.barnesg
404
+ superfac = mp.superfac
405
+ hyperfac = mp.hyperfac
406
+ loggamma = mp.loggamma
407
+ siegeltheta = mp.siegeltheta
408
+ siegelz = mp.siegelz
409
+ grampoint = mp.grampoint
410
+ zetazero = mp.zetazero
411
+ riemannr = mp.riemannr
412
+ primepi = mp.primepi
413
+ primepi2 = mp.primepi2
414
+ primezeta = mp.primezeta
415
+ bell = mp.bell
416
+ polyexp = mp.polyexp
417
+ expm1 = mp.expm1
418
+ log1p = mp.log1p
419
+ powm1 = mp.powm1
420
+ unitroots = mp.unitroots
421
+ cyclotomic = mp.cyclotomic
422
+ mangoldt = mp.mangoldt
423
+ secondzeta = mp.secondzeta
424
+ nzeros = mp.nzeros
425
+ backlunds = mp.backlunds
426
+ lerchphi = mp.lerchphi
427
+ stirling1 = mp.stirling1
428
+ stirling2 = mp.stirling2
429
+ squarew = mp.squarew
430
+ trianglew = mp.trianglew
431
+ sawtoothw = mp.sawtoothw
432
+ unit_triangle = mp.unit_triangle
433
+ sigmoid = mp.sigmoid
434
+
435
+ # be careful when changing this name, don't use test*!
436
+ def runtests():
437
  """
438
+ Run all mpmath tests and print output.
439
  """
440
+ import os.path
441
+ from inspect import getsourcefile
442
+ from .tests import runtests as tests
443
+ testdir = os.path.dirname(os.path.abspath(getsourcefile(tests)))
444
+ importdir = os.path.abspath(testdir + '/../..')
445
+ tests.testit(importdir, testdir)
446
+
447
+ def doctests(filter=[]):
448
+ import sys
449
+ from timeit import default_timer as clock
450
+ for i, arg in enumerate(sys.argv):
451
+ if '__init__.py' in arg:
452
+ filter = [sn for sn in sys.argv[i+1:] if not sn.startswith("-")]
453
+ break
454
+ import doctest
455
+ globs = globals().copy()
456
+ for obj in globs: #sorted(globs.keys()):
457
+ if filter:
458
+ if not sum([pat in obj for pat in filter]):
459
+ continue
460
+ sys.stdout.write(str(obj) + " ")
461
+ sys.stdout.flush()
462
+ t1 = clock()
463
+ doctest.run_docstring_examples(globs[obj], {}, verbose=("-v" in sys.argv))
464
+ t2 = clock()
465
+ print(round(t2-t1, 3))
466
+
467
+ if __name__ == '__main__':
468
+ doctests()