8000 Misc fixes by skirpichev · Pull Request #717 · mpmath/mpmath · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Misc fixes #717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mpmath/calculus/optimization.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def __iter__(self):
while True:
if x1 == x0:
if self.verbose:
print("canceled, won't get more excact")
print("canceled, won't get more exact")
cancel = True
break
fx = self.ctx.matrix(f(*x1))
Expand Down
2 changes: 1 addition & 1 deletion mpmath/functions/elliptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def nome(ctx, m):
return m
if ctx.isinf(m):
if m == ctx.ninf:
return type(m)(-1)
return -ctx.one
else:
return ctx.mpc(-1)
a = ctx.ellipk(ctx.one-m)
Expand Down
10 changes: 5 additions & 5 deletions mpmath/functions/expintegrals.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def erf(ctx, z):
pass
if ctx._is_complex_type(z) and not z.imag:
try:
return type(z)(ctx._erf(z.real))
return ctx.mpc(ctx._erf(z.real))
except NotImplementedError:
pass
return ctx._erf_complex(z)
Expand All @@ -46,7 +46,7 @@ def erfc(ctx, z):
pass
if ctx._is_complex_type(z) and not z.imag:
try:
return type(z)(ctx._erfc(z.real))
return ctx.mpc(ctx._erfc(z.real))
except NotImplementedError:
pass
return ctx._erfc_complex(z)
Expand Down Expand Up @@ -175,7 +175,7 @@ def gammainc(ctx, z, a=0, b=None, regularized=False):
def _lower_gamma(ctx, z, b, regularized=False):
# Pole
if ctx.isnpint(z):
return type(z)(ctx.inf)
return ctx.inf
G = [z] * regularized
negb = ctx.fneg(b, exact=True)
def h(z):
Expand All @@ -191,7 +191,7 @@ def _upper_gamma(ctx, z, a, regularized=False):
if regularized:
# Gamma pole
if ctx.isnpint(z):
return type(z)(ctx.zero)
return ctx.zero
orig = ctx.prec
try:
ctx.prec += 10
Expand Down Expand Up @@ -263,7 +263,7 @@ def expint(ctx, n, z):
# integral from 1 to infinity of t^n
if ctx.re(n) <= 1:
# TODO: reasonable sign of infinity
return type(z)(ctx.inf)
return ctx.inf
else:
return ctx.one/(n-1)
if n == 0:
Expand Down
2 changes: 1 addition & 1 deletion mpmath/functions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ def bell(ctx, n, x=1):
if not n:
if ctx.isnan(x):
return x
return type(x)(1)
return ctx.one
if ctx.isinf(x) or ctx.isinf(n) or ctx.isnan(x) or ctx.isnan(n):
return x**n
if n == 1: return x
Expand Down
2 changes: 2 additions & 0 deletions mpmath/tests/test_elliptic.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ def test_calculate_nome():
q = calculate_nome(sqrt(m))
assert q.ae(i[1])

assert qfrom(m=mp.ninf).ae(mpf('-1.0'))

def test_jtheta():
mp.dps = 25

Expand Down
8 changes: 7 additions & 1 deletion mpmath/tests/test_rootfinding.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,20 @@ def test_multiplicity():
assert multiplicity(lambda x: (x - 1)**i, 1) == i
assert multiplicity(lambda x: x**2, 1) == 0

def test_multidimensional():
def test_multidimensional(capsys):
def f(*x):
return [3*x[0]**2-2*x[1]**2-1, x[0]**2-2*x[0]+x[1]**2+2*x[1]-8]
assert mnorm(jacobian(f, (1,-2)) - matrix([[6,8],[0,-2]]),1) < 1.e-7
for x, error in MDNewton(mp, f, (1,-2), verbose=0,
norm=lambda x: norm(x, inf)):
pass
assert norm(f(*x), 2) < 1e-14
for x, error in MDNewton(mp, f, (1,-2), verbose=1,
norm=lambda x: norm(x, inf)):
pass
assert norm(f(*x), 2) < 1e-14
captured = capsys.readouterr()
assert captured.out.find("canceled, won't get more exact") >= 0
# The Chinese mathematician Zhu Shijie was the very first to solve this
# nonlinear system 700 years ago
f1 = lambda x, y: -x + 2*y
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Homepage = 'https://mpmath.org/'
'Bug Tracker' = 'https://github.com/mpmath/mpmath/issues'
Documentation = 'http://mpmath.org/doc/current/'
[project.optional-dependencies]
tests = ['pytest>=6', 'numpy; python_version<"3.12"']
tests = ['pytest>=6', 'numpy<=1.25.2; python_version<"3.12"']
develop = ['mpmath[tests]', 'flake518>=1.5; python_version>="3.9"',
'pytest-cov', 'wheel', 'build']
gmpy = ['gmpy2>=2.1.0a4; platform_python_implementation!="PyPy" and python_version<"3.12"']
Expand Down
0