Skip to content

Commit afb829b

Browse files
authored
Merge pull request #759 from skirpichev/misc
Misc fixes
2 parents 22859b0 + 0429f85 commit afb829b

18 files changed

Lines changed: 226 additions & 183 deletions

.github/workflows/test.yml

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,25 @@ jobs:
66
strategy:
77
fail-fast: false
88
matrix:
9-
python-version: [3.8, 3.9, '3.10', 3.11, 3.12, pypy3.8, pypy3.9, pypy3.10]
9+
python-version: [3.8, 3.9, '3.10', 3.11, 3.12, 3.13, pypy3.8, pypy3.9, pypy3.10]
10+
coverage: [false]
11+
nogmpy: [false]
12+
default: [false]
13+
include:
14+
- python-version: 3.11
15+
coverage: true
16+
nogmpy: true
17+
- python-version: 3.12
18+
coverage: true
19+
default: true
1020
env:
1121
PYTEST_ADDOPTS: -n auto
1222
steps:
1323
- uses: actions/checkout@v4
1424
with:
1525
fetch-depth: 0
1626
- name: Set up Python ${{ matrix.python-version }}
17-
uses: actions/setup-python@v4
27+
uses: actions/setup-python@v5
1828
with:
1929
python-version: ${{ matrix.python-version }}
2030
allow-prereleases: true
@@ -26,46 +36,43 @@ jobs:
2636
run: |
2737
pip install --upgrade setuptools pip
2838
pip install --upgrade .[develop,gmpy,docs,ci]
39+
- name: Remove gmpy (for coverage tests)
40+
if: matrix.nogmpy
41+
run: pip uninstall -y gmpy2
2942
- name: Linting with flake8, etc
30-
if: matrix.python-version >= 3.9
43+
if: matrix.default
3144
run: |
3245
python -We:invalid -m compileall -f mpmath -q
3346
flake518
3447
- name: Tests
35-
if: matrix.python-version != 3.10 && matrix.python-version != 3.11
36-
run: |
37-
pytest
38-
MPMATH_STRICT=Y pytest mpmath/tests/test_basic_ops.py
39-
- name: Remove gmpy on 3.10
40-
if: matrix.python-version == 3.10
41-
run: pip uninstall -y gmpy2
48+
if: ${{ ! matrix.coverage }}
49+
run: pytest
4250
- name: Run coverage tests
4351
env:
4452
PYTEST_ADDOPTS: --cov mpmath --cov-append -n auto
45-
if: matrix.python-version == 3.10 || matrix.python-version == 3.11
53+
if: matrix.coverage
4654
run: |
4755
pytest
48-
MPMATH_STRICT=Y pytest mpmath/tests/test_basic_ops.py
4956
coverage html
5057
coverage xml
5158
- name: Upload coverage data
52-
if: matrix.python-version == 3.10 || matrix.python-version == 3.11
59+
if: matrix.coverage
5360
uses: codecov/codecov-action@v3
5461
with:
5562
files: ./coverage.xml
5663
fail_ci_if_error: true
5764
- name: Building docs
58-
if: matrix.python-version == 3.11
65+
if: matrix.default
5966
run: |
6067
sphinx-build --color -W --keep-going -b html docs build/sphinx/html
6168
sphinx-build --color -W --keep-going -b latex docs build/sphinx/latex
6269
make -C build/sphinx/latex all-pdf
6370
- name: Make packages
64-
if: matrix.python-version == 3.11
71+
if: matrix.default
6572
run: python -m build
6673
- name: Archive production artifacts
67-
uses: actions/upload-artifact@v3
68-
if: matrix.python-version == 3.11
74+
uses: actions/upload-artifact@v4
75+
if: matrix.default
6976
with:
7077
path: |
7178
dist/
@@ -74,7 +81,7 @@ jobs:
7481
coverage.xml
7582
build/coverage/html/
7683
- name: Publish package on PyPI
77-
if: matrix.python-version == 3.11 && github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
84+
if: matrix.default && github.event_name == 'push' && startsWith(github.event.ref, 'refs/tags')
7885
uses: pypa/gh-action-pypi-publish@release/v1
7986
with:
8087
user: __token__

demo/mandelbrot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"""
66

77
import mpmath
8-
import cmath
98

109
ctx = mpmath.fp
1110
# ctx = mpmath.mp

demo/pidigits.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def interactive():
7373
if tofile:
7474
tofile = open(tofile, "w")
7575

76-
calculateit(base, digits, tofile)
76+
calculateit(int(base), int(digits), tofile)
7777
input("\nPress enter to close this script.")
7878

7979
if __name__ == "__main__":

docs/setup.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,6 @@ Developers may run tests from the source tree with::
127127
If any test fails, please send a detailed bug report to the `mpmath issue
128128
tracker <https://github.com/mpmath/mpmath/issues>`_.
129129

130-
To enable extra diagnostics, use, set ``MPMATH_STRICT`` environment variable.
131-
132130
Compiling the documentation
133131
---------------------------
134132

mpmath/ctx_iv.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,9 @@ def rop_complex(s, t):
274274
ivmpf.__add__, ivmpf.__radd__, ivmpc.__add__, ivmpc.__radd__ = _binary_op(mpi_add, mpci_add)
275275
ivmpf.__sub__, ivmpf.__rsub__, ivmpc.__sub__, ivmpc.__rsub__ = _binary_op(mpi_sub, mpci_sub)
276276
ivmpf.__mul__, ivmpf.__rmul__, ivmpc.__mul__, ivmpc.__rmul__ = _binary_op(mpi_mul, mpci_mul)
277-
ivmpf.__div__, ivmpf.__rdiv__, ivmpc.__div__, ivmpc.__rdiv__ = _binary_op(mpi_div, mpci_div)
278277
ivmpf.__pow__, ivmpf.__rpow__, ivmpc.__pow__, ivmpc.__rpow__ = _binary_op(mpi_pow, mpci_pow)
279278

280-
ivmpf.__truediv__ = ivmpf.__div__; ivmpf.__rtruediv__ = ivmpf.__rdiv__
281-
ivmpc.__truediv__ = ivmpc.__div__; ivmpc.__rtruediv__ = ivmpc.__rdiv__
279+
ivmpf.__truediv__, ivmpf.__rtruediv__, ivmpc.__truediv__, ivmpc.__rtruediv__ = _binary_op(mpi_div, mpci_div)
282280

283281
class ivmpf_constant(ivmpf):
284282
def __new__(cls, f):

mpmath/functions/zeta.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ def polylog_general(ctx, s, z):
458458
k = 0
459459
while 1:
460460
term = ctx.zeta(s-k) * t
461-
if abs(term) < ctx.eps:
461+
if not abs(term) >= ctx.eps:
462462
break
463463
v += term
464464
k += 1

mpmath/libmp/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
from .backend import (BACKEND, HASH_BITS, HASH_MODULUS, MPQ, MPZ, MPZ_FIVE,
2-
MPZ_ONE, MPZ_THREE, MPZ_TWO, MPZ_ZERO, STRICT, gmpy,
3-
int_types)
2+
MPZ_ONE, MPZ_THREE, MPZ_TWO, MPZ_ZERO, gmpy, int_types)
43
from .gammazeta import (apery_fixed, bernfrac, catalan_fixed, euler_fixed,
54
glaisher_fixed, khinchin_fixed, mertens_fixed,
65
mpc_altzeta, mpc_factorial, mpc_gamma, mpc_harmonic,

mpmath/libmp/backend.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
from fractions import Fraction
21
import os
32
import sys
3+
from fractions import Fraction
4+
45

56
#----------------------------------------------------------------------------#
67
# Support GMPY for high-speed large integer arithmetic. #
@@ -36,11 +37,6 @@
3637
except ImportError:
3738
pass
3839

39-
if 'MPMATH_STRICT' in os.environ:
40-
STRICT = True
41-
else:
42-
STRICT = False
43-
4440
MPZ_ZERO = MPZ(0)
4541
MPZ_ONE = MPZ(1)
4642
MPZ_TWO = MPZ(2)

mpmath/libmp/libmpf.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
getrandbits = None
1313

1414
from .backend import (BACKEND, HASH_BITS, HASH_MODULUS, MPZ, MPZ_FIVE, MPZ_ONE,
15-
MPZ_TWO, MPZ_ZERO, STRICT, gmpy)
15+
MPZ_TWO, MPZ_ZERO, gmpy)
1616
from .libintmath import (bctable, bin_to_radix, giant_steps, isqrt, isqrt_fast,
1717
lshift, numeral, rshift, sqrt_fixed, sqrtrem,
1818
stddigits, trailing, trailtable)
@@ -179,24 +179,17 @@ def _normalize(sign, man, exp, bc, prec, rnd):
179179

180180
_exp_types = (int,)
181181

182-
def strict_normalize(sign, man, exp, bc, prec, rnd):
183-
"""Additional checks on the components of an mpf. Enable tests by setting
184-
the environment variable MPMATH_STRICT to Y."""
182+
if BACKEND == 'gmpy':
183+
_normalize = gmpy._mpmath_normalize
184+
185+
def normalize(sign, man, exp, bc, prec, rnd):
185186
assert type(man) == MPZ
186187
assert type(bc) in _exp_types
187188
assert type(exp) in _exp_types
188189
assert bc == man.bit_length()
189190
assert man >= 0
190191
return _normalize(sign, man, exp, bc, prec, rnd)
191192

192-
if BACKEND == 'gmpy':
193-
_normalize = gmpy._mpmath_normalize
194-
195-
if STRICT:
196-
normalize = strict_normalize
197-
else:
198-
normalize = _normalize
199-
200193
#----------------------------------------------------------------------------#
201194
# Conversion functions #
202195
#----------------------------------------------------------------------------#

mpmath/matrices/linalg.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def LU_decomp(ctx, A, overwrite=False, use_cache=True):
146146
A[i,j] /= A[j,j]
147147
for k in range(j + 1, n):
148148
A[i,k] -= A[i,j]*A[j,k]
149-
if ctx.absmin(A[n - 1,n - 1]) <= tol:
149+
if p and ctx.absmin(A[n - 1,n - 1]) <= tol:
150150
raise ZeroDivisionError('matrix is numerically singular')
151151
# cache decomposition
152152
if not overwrite and isinstance(orig, ctx.matrix):
@@ -197,9 +197,6 @@ def lu_solve(ctx, A, b, **kwargs):
197197
(especially for overdetermined systems), but it's twice as efficient.
198198
Use qr_solve if you want more precision or have to solve a very ill-
199199
conditioned system.
200-
201-
If you specify real=True, it does not check for overdeterminded complex
202-
systems.
203200
"""
204201
prec = ctx.prec
205202
try:
@@ -214,12 +211,7 @@ def lu_solve(ctx, A, b, **kwargs):
214211
AH = A.H
215212
A = AH * A
216213
b = AH * b
217-
if (kwargs.get('real', False) or
218-
not sum(type(i) is ctx.mpc for i in A)):
219-
# TODO: necessary to check also b?
220-
x = ctx.cholesky_solve(A, b)
221-
else:
222-
x = ctx.lu_solve(A, b)
214+
x = ctx.cholesky_solve(A, b)
223215
else:
224216
# LU factorization
225217
A, p = ctx.LU_decomp(A)
@@ -551,6 +543,12 @@ def det(ctx, A):
551543
>>> print(det(A))
552544
1.0
553545
546+
The determinant of a 0 by 0 matrix is 1 as the product of no factors
547+
is by convention the multiplicative identity.
548+
>>> A = matrix(0, 0)
549+
>>> print(det(A))
550+
1
551+
554552
But in general a matrix can have any number as its determinant.
555553
556554
>>> A = matrix([[2, 6, 4],[3, 8, 6],[1, 1, 2]])

0 commit comments

Comments
 (0)