Repository: mpmath/mpmath
Pull request #717 (2023-09-22 09:05:39)

Misc fixes
* fix typo
* change type(foo)(bar) -> aproppriate ctx.mpf/ctx.mpc(bar) calls


Patch:
diff --git a/mpmath/calculus/optimization.py b/mpmath/calculus/optimization.py
index dc391bf..d282ff3 100644
--- a/mpmath/calculus/optimization.py
+++ b/mpmath/calculus/optimization.py
@@ -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))
diff --git a/mpmath/functions/elliptic.py b/mpmath/functions/elliptic.py
index e0318d6..6e7e906 100644
--- a/mpmath/functions/elliptic.py
+++ b/mpmath/functions/elliptic.py
@@ -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)
diff --git a/mpmath/functions/expintegrals.py b/mpmath/functions/expintegrals.py
index e44cfe0..c096ed7 100644
--- a/mpmath/functions/expintegrals.py
+++ b/mpmath/functions/expintegrals.py
@@ -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)
@@ -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)
@@ -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):
@@ -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
@@ -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:
diff --git a/mpmath/functions/functions.py b/mpmath/functions/functions.py
index 972f5b9..2bbb63d 100644
--- a/mpmath/functions/functions.py
+++ b/mpmath/functions/functions.py
@@ -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
diff --git a/pyproject.toml b/pyproject.toml
index e683a6d..d17a19e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -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"']


Test patch:
diff --git a/mpmath/tests/test_elliptic.py b/mpmath/tests/test_elliptic.py
index 90d8cd4..b63c30c 100644
--- a/mpmath/tests/test_elliptic.py
+++ b/mpmath/tests/test_elliptic.py
@@ -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
 
diff --git a/mpmath/tests/test_rootfinding.py b/mpmath/tests/test_rootfinding.py
index 1723d96..1689e34 100644
--- a/mpmath/tests/test_rootfinding.py
+++ b/mpmath/tests/test_rootfinding.py
@@ -70,7 +70,7 @@ 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
@@ -78,6 +78,12 @@ def f(*x):
                              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