Skip to content

Add build/pkgs/mpmath/spkg-check.in#36447

Closed
skirpichev wants to merge 4 commits intosagemath:developfrom
skirpichev:mpmath-tests
Closed

Add build/pkgs/mpmath/spkg-check.in#36447
skirpichev wants to merge 4 commits intosagemath:developfrom
skirpichev:mpmath-tests

Conversation

@skirpichev
Copy link
Copy Markdown

Run mpmath's test suite. (as suggested by @mkoeppe in mpmath/mpmath#727)

@mkoeppe
Copy link
Copy Markdown
Contributor

mkoeppe commented Oct 12, 2023

I'm getting

[mpmath-1.3.0] Running the test suite for mpmath-1.3.0...
[mpmath-1.3.0] ============================= test session starts ==============================
[mpmath-1.3.0] platform darwin -- Python 3.11.5, pytest-7.4.2, pluggy-1.3.0
[mpmath-1.3.0] rootdir: /Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/var/lib/sage/venv-python3.11/var/tmp/sage/build/mpmath-1.3.0
[mpmath-1.3.0] plugins: anyio-3.7.1
[mpmath-1.3.0] collected 341 items
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_basic_ops.py .......................               [  6%]
[mpmath-1.3.0] src/mpmath/tests/test_bitwise.py .............                           [ 10%]
[mpmath-1.3.0] src/mpmath/tests/test_calculus.py ..........                             [ 13%]
[mpmath-1.3.0] src/mpmath/tests/test_compatibility.py ...                               [ 14%]
[mpmath-1.3.0] src/mpmath/tests/test_convert.py ...........F..F                         [ 18%]
[mpmath-1.3.0] src/mpmath/tests/test_diff.py ....                                       [ 19%]
[mpmath-1.3.0] src/mpmath/tests/test_division.py .......                                [ 21%]
[mpmath-1.3.0] src/mpmath/tests/test_eigen.py ..                                        [ 22%]
[mpmath-1.3.0] src/mpmath/tests/test_eigen_symmetric.py ..........                      [ 25%]
[mpmath-1.3.0] src/mpmath/tests/test_elliptic.py ..............                         [ 29%]
[mpmath-1.3.0] src/mpmath/tests/test_fp.py ............                                 [ 33%]
[mpmath-1.3.0] src/mpmath/tests/test_functions.py ..................................... [ 43%]
[mpmath-1.3.0] .........                                                                [ 46%]
[mpmath-1.3.0] src/mpmath/tests/test_functions2.py .................................... [ 57%]
[mpmath-1.3.0] ..........                                                               [ 60%]
[mpmath-1.3.0] src/mpmath/tests/test_gammazeta.py ..............................        [ 68%]
[mpmath-1.3.0] src/mpmath/tests/test_hp.py ...                                          [ 69%]
[mpmath-1.3.0] src/mpmath/tests/test_identify.py ..                                     [ 70%]
[mpmath-1.3.0] src/mpmath/tests/test_interval.py ...............                        [ 74%]
[mpmath-1.3.0] src/mpmath/tests/test_levin.py .......                                   [ 76%]
[mpmath-1.3.0] src/mpmath/tests/test_linalg.py F.F.....F.......                         [ 81%]
[mpmath-1.3.0] src/mpmath/tests/test_matrices.py .......F....x..                        [ 85%]
[mpmath-1.3.0] src/mpmath/tests/test_mpmath.py .                                        [ 86%]
[mpmath-1.3.0] src/mpmath/tests/test_ode.py ...                                         [ 87%]
[mpmath-1.3.0] src/mpmath/tests/test_pickle.py .                                        [ 87%]
[mpmath-1.3.0] src/mpmath/tests/test_power.py ...                                       [ 88%]
[mpmath-1.3.0] src/mpmath/tests/test_quad.py ................x                          [ 93%]
[mpmath-1.3.0] src/mpmath/tests/test_rootfinding.py ......F.                            [ 95%]
[mpmath-1.3.0] src/mpmath/tests/test_special.py .....                                   [ 97%]
[mpmath-1.3.0] src/mpmath/tests/test_str.py .                                           [ 97%]
[mpmath-1.3.0] src/mpmath/tests/test_summation.py .....                                 [ 98%]
[mpmath-1.3.0] src/mpmath/tests/test_trig.py ...                                        [ 99%]
[mpmath-1.3.0] src/mpmath/tests/test_visualization.py .                                 [100%]
[mpmath-1.3.0] 
[mpmath-1.3.0] =================================== FAILURES ===================================
[mpmath-1.3.0] ___________________________ test_conversion_methods ____________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_conversion_methods():
[mpmath-1.3.0]         class SomethingRandom:
[mpmath-1.3.0]             pass
[mpmath-1.3.0]         class SomethingReal:
[mpmath-1.3.0]             def _mpmath_(self, prec, rounding):
[mpmath-1.3.0]                 return mp.make_mpf(from_str('1.3', prec, rounding))
[mpmath-1.3.0]         class SomethingComplex:
[mpmath-1.3.0]             def _mpmath_(self, prec, rounding):
[mpmath-1.3.0]                 return mp.make_mpc((from_str('1.3', prec, rounding), \
[mpmath-1.3.0]                     from_str('1.7', prec, rounding)))
[mpmath-1.3.0]         x = mpf(3)
[mpmath-1.3.0]         z = mpc(3)
[mpmath-1.3.0]         a = SomethingRandom()
[mpmath-1.3.0]         y = SomethingReal()
[mpmath-1.3.0]         w = SomethingComplex()
[mpmath-1.3.0]         for d in [15, 45]:
[mpmath-1.3.0]             mp.dps = d
[mpmath-1.3.0]             assert (x+y).ae(mpf('4.3'))
[mpmath-1.3.0]             assert (y+x).ae(mpf('4.3'))
[mpmath-1.3.0]             assert (x+w).ae(mpc('4.3', '1.7'))
[mpmath-1.3.0]             assert (w+x).ae(mpc('4.3', '1.7'))
[mpmath-1.3.0]             assert (z+y).ae(mpc('4.3'))
[mpmath-1.3.0]             assert (y+z).ae(mpc('4.3'))
[mpmath-1.3.0]             assert (z+w).ae(mpc('4.3', '1.7'))
[mpmath-1.3.0]             assert (w+z).ae(mpc('4.3', '1.7'))
[mpmath-1.3.0]             x-y; y-x; x-w; w-x; z-y; y-z; z-w; w-z
[mpmath-1.3.0]             x*y; y*x; x*w; w*x; z*y; y*z; z*w; w*z
[mpmath-1.3.0]             x/y; y/x; x/w; w/x; z/y; y/z; z/w; w/z
[mpmath-1.3.0]             x**y; y**x; x**w; w**x; z**y; y**z; z**w; w**z
[mpmath-1.3.0]             x==y; y==x; x==w; w==x; z==y; y==z; z==w; w==z
[mpmath-1.3.0]         mp.dps = 15
[mpmath-1.3.0]         assert x.__add__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__radd__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__lt__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__gt__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__le__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__ge__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__eq__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__ne__(a) is NotImplemented
[mpmath-1.3.0]         # implementation detail
[mpmath-1.3.0]         if hasattr(x, "__cmp__"):
[mpmath-1.3.0]             assert x.__cmp__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__sub__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__rsub__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__mul__(a) is NotImplemented
[mpmath-1.3.0]         assert x.__rmul__(a) is NotImplemented
[mpmath-1.3.0] >       assert x.__div__(a) is NotImplemented
[mpmath-1.3.0] E       AttributeError: 'sage.libs.mpmath.ext_main.mpf' object has no attribute '__div__'
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_convert.py:172: AttributeError
[mpmath-1.3.0] ______________________________ test_compatibility ______________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_compatibility():
[mpmath-1.3.0]         try:
[mpmath-1.3.0]             import numpy as np
[mpmath-1.3.0]             from fractions import Fraction
[mpmath-1.3.0]             from decimal import Decimal
[mpmath-1.3.0]             import decimal
[mpmath-1.3.0]         except ImportError:
[mpmath-1.3.0]             return
[mpmath-1.3.0]         # numpy types
[mpmath-1.3.0]         for nptype in np.core.numerictypes.typeDict.values():
[mpmath-1.3.0]             if issubclass(nptype, np.complexfloating):
[mpmath-1.3.0]                 x = nptype(complex(0.5, -0.5))
[mpmath-1.3.0]             elif issubclass(nptype, np.floating):
[mpmath-1.3.0]                 x = nptype(0.5)
[mpmath-1.3.0]             elif issubclass(nptype, np.integer):
[mpmath-1.3.0]                 x = nptype(2)
[mpmath-1.3.0]             # Handle the weird types
[mpmath-1.3.0]             try: diff = np.abs(type(np.sqrt(x))(sqrt(x)) - np.sqrt(x))
[mpmath-1.3.0]             except: continue
[mpmath-1.3.0]             assert diff < 2.0**-53
[mpmath-1.3.0]         #Fraction and Decimal
[mpmath-1.3.0]         oldprec = mp.prec
[mpmath-1.3.0]         mp.prec = 1000
[mpmath-1.3.0]         decimal.getcontext().prec = mp.dps
[mpmath-1.3.0] >       assert sqrt(Fraction(2, 3)).ae(sqrt(mpf('2/3')))
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_convert.py:231: 
[mpmath-1.3.0] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[mpmath-1.3.0] 
[mpmath-1.3.0] >   ???
[mpmath-1.3.0] E   NotImplementedError: unknown argument
[mpmath-1.3.0] 
[mpmath-1.3.0] sage/libs/mpmath/ext_main.pyx:1227: NotImplementedError
[mpmath-1.3.0] ________________________________ test_LU_decomp ________________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_LU_decomp():
[mpmath-1.3.0]         A = A3.copy()
[mpmath-1.3.0]         b = b3
[mpmath-1.3.0]         A, p = LU_decomp(A)
[mpmath-1.3.0]         y = L_solve(A, b, p)
[mpmath-1.3.0]         x = U_solve(A, y)
[mpmath-1.3.0]         assert p == [2, 1, 2, 3]
[mpmath-1.3.0] >       assert [round(i, 14) for i in x] == [3.78953107960742, 2.9989094874591098,
[mpmath-1.3.0]                 -0.081788440567070006, 3.8713195201744801, 2.9171210468920399]
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_linalg.py:79: 
[mpmath-1.3.0] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[mpmath-1.3.0] 
[mpmath-1.3.0] .0 = <list_iterator object at 0x18d47cbb0>
[mpmath-1.3.0] 
[mpmath-1.3.0] >   assert [round(i, 14) for i in x] == [3.78953107960742, 2.9989094874591098,
[mpmath-1.3.0]             -0.081788440567070006, 3.8713195201744801, 2.9171210468920399]
[mpmath-1.3.0] E   TypeError: type sage.libs.mpmath.ext_main.mpf doesn't define __round__ method
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_linalg.py:79: TypeError
[mpmath-1.3.0] _______________________________ test_householder _______________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_householder():
[mpmath-1.3.0]         mp.dps = 15
[mpmath-1.3.0]         A, b = A8, b8
[mpmath-1.3.0]         H, p, x, r = householder(extend(A, b))
[mpmath-1.3.0]         assert H == matrix(
[mpmath-1.3.0]         [[mpf('3.0'), mpf('-2.0'), mpf('-1.0'), 0],
[mpmath-1.3.0]          [-1.0,mpf('3.333333333333333'),mpf('-2.9999999999999991'),mpf('2.0')],
[mpmath-1.3.0]          [-1.0, mpf('-0.66666666666666674'),mpf('2.8142135623730948'),
[mpmath-1.3.0]           mpf('-2.8284271247461898')],
[mpmath-1.3.0]          [1.0, mpf('-1.3333333333333333'),mpf('-0.20000000000000018'),
[mpmath-1.3.0]           mpf('4.2426406871192857')]])
[mpmath-1.3.0]         assert p == [-2, -2, mpf('-1.4142135623730949')]
[mpmath-1.3.0] >       assert round(norm(r, 2), 10) == 4.2426406870999998
[mpmath-1.3.0] E       TypeError: type sage.libs.mpmath.ext_main.mpf doesn't define __round__ method
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_linalg.py:111: TypeError
[mpmath-1.3.0] ___________________________________ test_det ___________________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_det():
[mpmath-1.3.0]         assert det(A1) == 1
[mpmath-1.3.0] >       assert round(det(A2), 14) == 8
[mpmath-1.3.0] E       TypeError: type sage.libs.mpmath.ext_main.mpf doesn't define __round__ method
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_linalg.py:190: TypeError
[mpmath-1.3.0] __________________________________ test_norms __________________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_norms():
[mpmath-1.3.0]         # matrix norms
[mpmath-1.3.0]         A = matrix([[1, -2], [-3, -1], [2, 1]])
[mpmath-1.3.0]         assert mnorm(A,1) == 6
[mpmath-1.3.0]         assert mnorm(A,inf) == 4
[mpmath-1.3.0]         assert mnorm(A,'F') == sqrt(20)
[mpmath-1.3.0]         # vector norms
[mpmath-1.3.0]         assert norm(-3) == 3
[mpmath-1.3.0]         x = [1, -2, 7, -12]
[mpmath-1.3.0]         assert norm(x, 1) == 22
[mpmath-1.3.0] >       assert round(norm(x, 2), 10) == 14.0712472795
[mpmath-1.3.0] E       TypeError: type sage.libs.mpmath.ext_main.mpf doesn't define __round__ method
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_matrices.py:164: TypeError
[mpmath-1.3.0] ____________________________ test_multidimensional _____________________________
[mpmath-1.3.0] 
[mpmath-1.3.0]     def test_multidimensional():
[mpmath-1.3.0]         def f(*x):
[mpmath-1.3.0]             return [3*x[0]**2-2*x[1]**2-1, x[0]**2-2*x[0]+x[1]**2+2*x[1]-8]
[mpmath-1.3.0]         assert mnorm(jacobian(f, (1,-2)) - matrix([[6,8],[0,-2]]),1) < 1.e-7
[mpmath-1.3.0]         for x, error in MDNewton(mp, f, (1,-2), verbose=0,
[mpmath-1.3.0]                                  norm=lambda x: norm(x, inf)):
[mpmath-1.3.0]             pass
[mpmath-1.3.0]         assert norm(f(*x), 2) < 1e-14
[mpmath-1.3.0]         # The Chinese mathematician Zhu Shijie was the very first to solve this
[mpmath-1.3.0]         # nonlinear system 700 years ago
[mpmath-1.3.0]         f1 = lambda x, y: -x + 2*y
[mpmath-1.3.0]         f2 = lambda x, y: (x**2 + x*(y**2 - 2) - 4*y)  /  (x + 4)
[mpmath-1.3.0]         f3 = lambda x, y: sqrt(x**2 + y**2)
[mpmath-1.3.0]         def f(x, y):
[mpmath-1.3.0]             f1x = f1(x, y)
[mpmath-1.3.0]             return (f2(x, y) - f1x, f3(x, y) - f1x)
[mpmath-1.3.0]         x = findroot(f, (10, 10))
[mpmath-1.3.0] >       assert [int(round(i)) for i in x] == [3, 4]
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_rootfinding.py:86: 
[mpmath-1.3.0] _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
[mpmath-1.3.0] 
[mpmath-1.3.0] .0 = <generator object _matrix.__iter__ at 0x18d513c40>
[mpmath-1.3.0] 
[mpmath-1.3.0] >   assert [int(round(i)) for i in x] == [3, 4]
[mpmath-1.3.0] E   TypeError: type sage.libs.mpmath.ext_main.mpf doesn't define __round__ method
[mpmath-1.3.0] 
[mpmath-1.3.0] src/mpmath/tests/test_rootfinding.py:86: TypeError
[mpmath-1.3.0] =============================== warnings summary ===============================
[mpmath-1.3.0] src/mpmath/tests/test_functions2.py:2370
[mpmath-1.3.0]   /Users/mkoeppe/s/sage/sage-rebasing/worktree-algebraic-2018-spring/local/var/lib/sage/venv-python3.11/var/tmp/sage/build/mpmath-1.3.0/src/mpmath/tests/test_functions2.py:2370: PytestUnknownMarkWarning: Unknown pytest.mark.slow - is this a typo?  You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/how-to/mark.html
[mpmath-1.3.0]     @pytest.mark.slow
[mpmath-1.3.0] 
[mpmath-1.3.0] -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
[mpmath-1.3.0] =========================== short test summary info ============================
[mpmath-1.3.0] FAILED src/mpmath/tests/test_convert.py::test_conversion_methods - AttributeE...
[mpmath-1.3.0] FAILED src/mpmath/tests/test_convert.py::test_compatibility - NotImplementedE...
[mpmath-1.3.0] FAILED src/mpmath/tests/test_linalg.py::test_LU_decomp - TypeError: type sage...
[mpmath-1.3.0] FAILED src/mpmath/tests/test_linalg.py::test_householder - TypeError: type sa...
[mpmath-1.3.0] FAILED src/mpmath/tests/test_linalg.py::test_det - TypeError: type sage.libs....
[mpmath-1.3.0] FAILED src/mpmath/tests/test_matrices.py::test_norms - TypeError: type sage.l...
[mpmath-1.3.0] FAILED src/mpmath/tests/test_rootfinding.py::test_multidimensional - TypeErro...
[mpmath-1.3.0] ============= 7 failed, 332 passed, 2 xfailed, 1 warning in 36.62s =============
[mpmath-1.3.0] 
[mpmath-1.3.0] real	0m37.680s
[mpmath-1.3.0] user	0m32.794s
[mpmath-1.3.0] sys	0m1.508s
[mpmath-1.3.0] ************************************************************************
[mpmath-1.3.0] Error testing package mpmath-1.3.0
[mpmath-1.3.0] ************************************************************************

@skirpichev
Copy link
Copy Markdown
Author

The problem is that sage come with own (and outdated) implementation of mpmath types (mpf/mpc). Lets see if above commits fix tests.

@skirpichev
Copy link
Copy Markdown
Author

@mkoeppe

@skirpichev
Copy link
Copy Markdown
Author

Hmm, tests are finished, but I don't see mpmath-related tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants