nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: mpmath/mpmath
Pull request #755 (2024-02-18 00:39:46)

Fix choleksy_solve for complex matrix


Patch:
diff --git a/mpmath/matrices/linalg.py b/mpmath/matrices/linalg.py
index ceb5f62..ff75780 100644
--- a/mpmath/matrices/linalg.py
+++ b/mpmath/matrices/linalg.py
@@ -529,7 +529,7 @@ def cholesky_solve(ctx, A, b, **kwargs):
             for i in range(n):
                 b[i] -= ctx.fsum(L[i,j] * b[j] for j in range(i))
                 b[i] /= L[i,i]
-            x = ctx.U_solve(L.T, b)
+            x = ctx.U_solve(L.H, b)
             return x
         finally:
             ctx.prec = prec


Test patch:
diff --git a/mpmath/tests/test_linalg.py b/mpmath/tests/test_linalg.py
index 3df3d36..cb24bb9 100644
--- a/mpmath/tests/test_linalg.py
+++ b/mpmath/tests/test_linalg.py
@@ -198,6 +198,11 @@ def test_cholesky():
     x = fp.cholesky_solve(A9, b9)
     assert fp.norm(fp.residual(A9, x, b9), fp.inf) == 0
 
+    a = fp.matrix([[1, 0.5j], [-0.5j, 0.5]])
+    b = fp.ones(2, 1)
+    x = fp.cholesky_solve(a, b)
+    assert fp.norm(fp.residual(a, x, b), fp.inf) == 0
+
 def test_det():
     assert det(A1) == 1
     assert round(det(A2), 14) == 8
Repository: mpmath/mpmath
Pull request #798 (2024-04-30 04:13:46)

Add fp.hypot
This partially address issue #355


Patch:
diff --git a/mpmath/ctx_fp.py b/mpmath/ctx_fp.py
index 96273e9..79cb6ba 100644
--- a/mpmath/ctx_fp.py
+++ b/mpmath/ctx_fp.py
@@ -156,6 +156,7 @@ def expjpi(ctx, x):
 
     ldexp = math.ldexp
     frexp = math.frexp
+    hypot = math.hypot
 
     def mag(ctx, z):
         if z:


Test patch:
diff --git a/mpmath/tests/test_eigen.py b/mpmath/tests/test_eigen.py
index c7c22f0..bcdc364 100644
--- a/mpmath/tests/test_eigen.py
+++ b/mpmath/tests/test_eigen.py
@@ -1,4 +1,4 @@
-from mpmath import mp
+from mpmath import fp, mp
 
 
 def run_hessenberg(A, verbose = 0):
@@ -162,7 +162,7 @@ def test_eig():
     AS.append(A)
     AS.append(A.transpose())
 
-    A=  mp.matrix([[0, 0, 1],  # cyclic
+    A = mp.matrix([[0, 0, 1],  # cyclic
                    [1, 0, 0],
                    [0, 1, 0]])
     AS.append(A)
@@ -175,3 +175,11 @@ def test_eig():
 
     A = mp.matrix(1)
     assert mp.eig(A, left=False, right=False) == [0]
+
+
+def test_fp_eig():
+    A = fp.matrix([[1, 2],
+                   [3, 4]])
+    E, ER = fp.eig(A)
+    assert all(_ == 0 for _ in fp.chop(A * ER[:,0] - E[0] * ER[:,0]))
+    assert all(_ == 0 for _ in fp.chop(A * ER[:,1] - E[1] * ER[:,1]))
Repository: mpmath/mpmath
Pull request #844 (2024-08-20 21:41:25)

BUG: polyval ignored 'asc=False'
I noticed this bug in 1.4.0a1 and the master branch, where `asc=False` is ignored by `polyval`:

```
In [1]: import mpmath

In [2]: mpmath.__version__
Out[2]: '1.4.0a2.dev79+gd5c8e0c.d20240820'

In [3]: from mpmath import mp

In [4]: c = [1, 2, 3]

In [5]: mp.polyval(c, 2.0, asc=True)
Out[5]: mpf('17.0')

In [6]: mp.polyval(c, 2.0, asc=False)
Out[6]: mpf('17.0')
```



Patch:
diff --git a/mpmath/calculus/polynomials.py b/mpmath/calculus/polynomials.py
index acfef7f..987da33 100644
--- a/mpmath/calculus/polynomials.py
+++ b/mpmath/calculus/polynomials.py
@@ -39,10 +39,11 @@ def polyval(ctx, coeffs, x, derivative=False, asc=None):
         return ctx.zero
     if asc is None:
         warnings.warn("Descending (wrt powers) order of polynomial "
-                      "coefficients is deprecated, please adapt you "
+                      "coefficients is deprecated, please adapt your "
                       "code to use ascending order, asc=True.",
                       DeprecationWarning)
         asc = False
+    if not asc:
         coeffs = coeffs[::-1]
     p = ctx.convert(coeffs[-1])
     q = ctx.zero


Test patch:
diff --git a/mpmath/tests/test_calculus.py b/mpmath/tests/test_calculus.py
index 7d62dd5..e9032c9 100644
--- a/mpmath/tests/test_calculus.py
+++ b/mpmath/tests/test_calculus.py
@@ -36,6 +36,9 @@ def test_polyval():
     assert polyval(p,4,asc=True) == 253
     assert polyval(p,4,derivative=True,asc=True) == (253, 190)
 
+def test_polyval_asc_false():
+    assert polyval([1, 2, 3], 2, asc=False) == 11
+
 def test_polyval_deprecated():
     with pytest.deprecated_call():
         p = [4, 0, -2, 5]
Repository: mpmath/mpmath
Pull request #923 (2025-03-03 01:44:36)

Misc fixes
* test on stable PyPy3.10
* test on PyPy3.11
* enable pretty-printing in CLI per default



Patch:
diff --git a/mpmath/__main__.py b/mpmath/__main__.py
index c0b710f..00bca86 100644
--- a/mpmath/__main__.py
+++ b/mpmath/__main__.py
@@ -38,7 +38,7 @@
                     action='store_true')
 parser.add_argument('--prec', type=int,
                     help='Set default mpmath precision')
-parser.add_argument('--pretty', help='Enable pretty-printing',
+parser.add_argument('--no-pretty', help='Disable pretty-printing',
                     action='store_true')
 
 
@@ -54,7 +54,7 @@ def main():
 
     if args.prec:
         lines.append(f'mp.prec = {args.prec}')
-    if args.pretty:
+    if not args.no_pretty:
         lines.append('mp.pretty = True')
 
     try:


Test patch:
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 98e1b02..28e0eb5 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -15,7 +15,7 @@ jobs:
     strategy:
       fail-fast: false
       matrix:
-        python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.14, pypy3.10-nightly]
+        python-version: [3.9, '3.10', 3.11, 3.12, 3.13, 3.14, 'pypy3.10', pypy3.11]
     env:
       PYTEST_ADDOPTS: -n auto
     steps:
diff --git a/mpmath/tests/test_cli.py b/mpmath/tests/test_cli.py
index e0ce649..8bfd0a5 100644
--- a/mpmath/tests/test_cli.py
+++ b/mpmath/tests/test_cli.py
@@ -85,7 +85,7 @@ def test_ipython_console_wrap_floats():
     pytest.importorskip('IPython')
 
     c = Console(f'{sys.executable} -m mpmath --simple-prompt --prec 100 '
-                "--colors 'NoColor'")
+                "--colors 'NoColor' --no-pretty")
 
     assert c.expect_exact('\r\nIn [1]: ') == 0
     assert c.send('10.9\r\n') == 6
@@ -94,7 +94,7 @@ def test_ipython_console_wrap_floats():
 
 def test_bare_console_wrap_floats():
     c = Console(f'{sys.executable} -m mpmath --simple-prompt --no-ipython --prec 100 '
-                "--colors 'NoColor'")
+                "--colors 'NoColor' --no-pretty")
 
     assert c.expect_exact('>>> ') == 0
     assert c.send("10.9\r\n") == 6
@@ -107,7 +107,7 @@ def test_bare_console_wrap_floats():
 
 def test_bare_console_pretty():
     c = Console(f'{sys.executable} -m mpmath --simple-prompt --no-ipython --prec 100 '
-                "--colors 'NoColor' --pretty")
+                "--colors 'NoColor'")
 
     assert c.expect_exact('>>> ') == 0
     assert c.send("10.9\r\n") == 6
Repository: mpmath/mpmath
Pull request #931 (2025-03-18 07:45:37)

Fix runsource() for incomplete input


Patch:
diff --git a/mpmath/__main__.py b/mpmath/__main__.py
index 00bca86..a0506ee 100644
--- a/mpmath/__main__.py
+++ b/mpmath/__main__.py
@@ -14,6 +14,7 @@
 import readline
 import rlcompleter
 import sys
+import tokenize
 
 from mpmath import __version__
 from mpmath._interactive import (IntegerDivisionWrapper,
@@ -114,26 +115,29 @@ def __init__(self, ast_transformers=[],
                 self.source_transformers = source_transformers
 
             def runsource(self, source, filename='<input>', symbol='single'):
-                if not source:
+                try:
+                    code = self.compile(source, filename, symbol)
+                except (OverflowError, SyntaxError, ValueError):
+                    if sys.version_info >= (3, 13):
+                        self.showsyntaxerror(filename, source=source)
+                    else:  # pragma: no cover
+                        self.showsyntaxerror(filename)
+                    return False
+
+                if code is None:
                     return True
 
                 for t in self.source_transformers:
                     source = '\n'.join(t(source.splitlines()))
 
-                if self.ast_transformers:
-                    tree = ast.parse(source, mode=symbol)
-
-                    for t in self.ast_transformers:
-                        tree = t.visit(tree)
-                    ast.fix_missing_locations(tree)
-
-                    code_obj = compile(tree, filename, mode=symbol)
-                    try:
-                        self.runcode(code_obj)
-                    except SystemExit:
-                        os.exit(0)
-                    return False
+                tree = ast.parse(source)
+                for t in self.ast_transformers:
+                    tree = t.visit(tree)
+                ast.fix_missing_locations(tree)
+                source = ast.unparse(tree)
 
+                source = source.split('\n')
+                source = ';'.join(source)
                 return super().runsource(source, filename=filename, symbol=symbol)
 
         c = MpmathConsole(ast_transformers=ast_transformers,


Test patch:
diff --git a/mpmath/tests/test_cli.py b/mpmath/tests/test_cli.py
index 8bfd0a5..2d7a8eb 100644
--- a/mpmath/tests/test_cli.py
+++ b/mpmath/tests/test_cli.py
@@ -112,6 +112,8 @@ def test_bare_console_pretty():
     assert c.expect_exact('>>> ') == 0
     assert c.send("10.9\r\n") == 6
     assert c.expect_exact("10.9\r\n>>> ") == 0
+    assert c.send("def f():\r\n  x = ?\r\n\r\n") == 21
+    assert c.expect('SyntaxError:') == 0
 
 
 def test_mpmath_version():