From 897858449be1b8488a2b6b2f7a94b21efd9d8c85 Mon Sep 17 00:00:00 2001 From: Rory Yorke Date: Sun, 19 Jan 2025 11:54:28 +0200 Subject: [PATCH] Make source `ruff check`-clean Removed unused imports. Removed unused variables in test: these were cut-and-paste from other tests, and not needed for the tests in questions. Other minor fixes. --- slycot/__init__.py | 11 +++++++++++ slycot/analysis.py | 4 ++-- slycot/examples.py | 5 ++--- slycot/exceptions.py | 4 ++-- slycot/tests/test_ab13bd.py | 2 +- slycot/tests/test_ab13md.py | 2 +- slycot/tests/test_mb.py | 28 ---------------------------- slycot/tests/test_sb.py | 2 +- slycot/tests/test_tb05ad.py | 2 -- slycot/tests/test_tg01ad.py | 2 +- slycot/tests/test_tg01fd.py | 4 ++-- slycot/transform.py | 4 ++-- 12 files changed, 25 insertions(+), 45 deletions(-) diff --git a/slycot/__init__.py b/slycot/__init__.py index c1243ea5..6cb415d0 100644 --- a/slycot/__init__.py +++ b/slycot/__init__.py @@ -79,6 +79,17 @@ from .version import __version__ + __all__ = [ + ab01nd, ab04md, ab05md, ab05nd, ab07nd, ab08nd, ab08nz, + ab09ad, ab09ax, ab09bd, ab09md, ab09nd, ab13bd, ab13dd, + ab13ed, ab13fd, ab13md, ag08bd, mb02ed, mb03rd, mb03vd, + mb03vy, mb03wd, mb05md, mb05nd, mc01td, sb01bd, sb02md, + sb02mt, sb02od, sb03md, sb03md57, sb03od, sb04md, sb04qd, + sb10ad, sb10dd, sb10fd, sb10hd, sb10jd, sb10yd, sg02ad, + sg03ad, sg03bd, tb01id, tb01pd, tb03ad, tb04ad, tb05ad, + tc01od, tc04ad, td04ad, tf01md, tf01rd, tg01ad, tg01fd, + __version__ + ] def test(): import pytest diff --git a/slycot/analysis.py b/slycot/analysis.py index 230eedb9..e4c7a6a0 100644 --- a/slycot/analysis.py +++ b/slycot/analysis.py @@ -1827,7 +1827,7 @@ def ab13md(Z, nblock, itype, x=None): else: fact='F' if len(x) != m+mr-1: - raise ValueError(f'Require len(x)==m+mr-1, but' + raise ValueError('Require len(x)==m+mr-1, but' + f' len(x)={len(x)}, m={m}, mr={mr}') x = np.concatenate([x,np.zeros(2*m-1-len(x))]) @@ -1838,7 +1838,7 @@ def ab13md(Z, nblock, itype, x=None): return bound, d, g, x[:m+mr-1] -def ag08bd(l,n,m,p,A,E,B,C,D,equil='N',tol=0.0,ldwork=None): +def ag08bd(l,n,m,p,A,E,B,C,D,equil='N',tol=0.0,ldwork=None): # noqa: E741 """ Af,Ef,nrank,niz,infz,kronr,infe,kronl = ag08bd(l,n,m,p,A,E,B,C,D,[equil,tol,ldwork]) To extract from the system pencil diff --git a/slycot/examples.py b/slycot/examples.py index cf306913..9e41a256 100644 --- a/slycot/examples.py +++ b/slycot/examples.py @@ -33,7 +33,6 @@ def sb02md_example(): print('rcond =', out[1]) def sb03md_example(): - from numpy import zeros A = array([ [3, 1, 1], [1, 3, 0], [0, 0, 3]]) @@ -47,7 +46,7 @@ def sb03md_example(): print('scaling factor:', out[3]) def ab08nd_example(): - from numpy import zeros, size + from numpy import zeros from scipy.linalg import eigvals A = array([ [1, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0], @@ -153,7 +152,7 @@ def mc01td_example(): print('The polynomial has', out[2], 'unstable zeros') def sb02od_example(): - from numpy import zeros, shape, dot, ones + from numpy import dot, ones A = array([ [0, 1], [0, 0]]) B = array([ [0], diff --git a/slycot/exceptions.py b/slycot/exceptions.py index f08bb3f6..a91a8390 100644 --- a/slycot/exceptions.py +++ b/slycot/exceptions.py @@ -77,7 +77,7 @@ def _parse_docsection(section_name, docstring, checkvars): continue section_indent = next(docline).index("-") - for l in docline: + for l in docline: # noqa: E741 # ignore blank lines if not l.strip(): continue @@ -121,7 +121,7 @@ def _parse_docsection(section_name, docstring, checkvars): break # docstring body_indent = len(mmatch.group(1)) message += mmatch.group(2) + '\n' - for l in docline: + for l in docline: # noqa: E741 if l and not l[:body_indent].isspace(): break # message body message += l[body_indent:] + '\n' diff --git a/slycot/tests/test_ab13bd.py b/slycot/tests/test_ab13bd.py index dd2a735a..ed4f6b92 100644 --- a/slycot/tests/test_ab13bd.py +++ b/slycot/tests/test_ab13bd.py @@ -2,7 +2,7 @@ # ab08n* tests import numpy as np -from numpy.testing import assert_allclose, assert_array_equal, assert_equal +from numpy.testing import assert_allclose, assert_array_equal from scipy import linalg, signal from slycot import analysis diff --git a/slycot/tests/test_ab13md.py b/slycot/tests/test_ab13md.py index 5a30f5ba..ac933e1f 100644 --- a/slycot/tests/test_ab13md.py +++ b/slycot/tests/test_ab13md.py @@ -1,6 +1,6 @@ import numpy as np import pytest -from numpy.testing import assert_allclose, assert_array_less +from numpy.testing import assert_allclose from slycot import ab13md diff --git a/slycot/tests/test_mb.py b/slycot/tests/test_mb.py index 5dc5dcd5..745d382a 100644 --- a/slycot/tests/test_mb.py +++ b/slycot/tests/test_mb.py @@ -2,8 +2,6 @@ # test_mb.py - test suite for linear algebra commands # bnavigator , Aug 2019 -import sys - import numpy as np import pytest from numpy.testing import assert_allclose @@ -96,19 +94,6 @@ def test_mb02ed_parameter_errors(): [1.0000, 2.0000], ] ) - X = np.array( - [ - [0.2408, 0.4816], - [0.1558, 0.3116], - [0.1534, 0.3068], - [0.2302, 0.4603], - [0.1467, 0.2934], - [0.1537, 0.3075], - [0.2349, 0.4698], - [0.1498, 0.2995], - [0.1653, 0.3307], - ] - ) # Test for wrong parameter typet with pytest.raises(expected_exception=SlycotParameterError, match='typet must be either "R" or "C"') as cm: @@ -162,19 +147,6 @@ def test_mb02ed_matrix_error(): [1.0000, 2.0000], ] ) - X = np.array( - [ - [0.2408, 0.4816], - [0.1558, 0.3116], - [0.1534, 0.3068], - [0.2302, 0.4603], - [0.1467, 0.2934], - [0.1537, 0.3075], - [0.2349, 0.4698], - [0.1498, 0.2995], - [0.1653, 0.3307], - ] - ) with pytest.raises(SlycotArithmeticError, match = "The reduction algorithm failed. " diff --git a/slycot/tests/test_sb.py b/slycot/tests/test_sb.py index e6f97a07..ceccad3b 100644 --- a/slycot/tests/test_sb.py +++ b/slycot/tests/test_sb.py @@ -7,7 +7,7 @@ from slycot import synthesis from slycot.exceptions import (SlycotArithmeticError, SlycotParameterError, - SlycotResultWarning, raise_if_slycot_error) + SlycotResultWarning) from .test_exceptions import assert_docstring_parse diff --git a/slycot/tests/test_tb05ad.py b/slycot/tests/test_tb05ad.py index 900a49a2..e940c45f 100644 --- a/slycot/tests/test_tb05ad.py +++ b/slycot/tests/test_tb05ad.py @@ -1,8 +1,6 @@ # =================================================== # tb05ad tests -import sys - import numpy as np import pytest from numpy.testing import assert_almost_equal diff --git a/slycot/tests/test_tg01ad.py b/slycot/tests/test_tg01ad.py index 864d41be..885f4c1c 100644 --- a/slycot/tests/test_tg01ad.py +++ b/slycot/tests/test_tg01ad.py @@ -2,7 +2,7 @@ # tg01ad tests import numpy as np -from numpy.testing import assert_almost_equal, assert_equal, assert_raises +from numpy.testing import assert_almost_equal from slycot import transform diff --git a/slycot/tests/test_tg01fd.py b/slycot/tests/test_tg01fd.py index 902d1ef2..5b960362 100644 --- a/slycot/tests/test_tg01fd.py +++ b/slycot/tests/test_tg01fd.py @@ -2,7 +2,7 @@ # tg01fd tests import numpy as np -from numpy.testing import assert_almost_equal, assert_equal, assert_raises +from numpy.testing import assert_almost_equal, assert_equal from slycot import transform @@ -76,7 +76,7 @@ def test1_tg01fd(): def test2_tg01fd(): """ verify that Q and Z output with compq and compz set to 'U' equals the dot product of Q and Z input and Q and Z output with compq and compz set to 'I' """ - l = 30 + l = 30 # noqa: E741 n = 30 m = 70 p = 44 diff --git a/slycot/transform.py b/slycot/transform.py index 43762b5a..660e90ec 100644 --- a/slycot/transform.py +++ b/slycot/transform.py @@ -969,7 +969,7 @@ def tf01rd(n,m,p,N,A,B,C,ldwork=None): raise_if_slycot_error(out[-1], arg_list) return out[0] -def tg01ad(l,n,m,p,A,E,B,C,thresh=0.0,job='A'): +def tg01ad(l,n,m,p,A,E,B,C,thresh=0.0,job='A'): # noqa: E741 """ A,E,B,C,lscale,rscale = tg01ad(l,n,m,p,A,E,B,C,[thresh,job]) To balance the matrices of the system pencil @@ -1069,7 +1069,7 @@ def tg01ad(l,n,m,p,A,E,B,C,thresh=0.0,job='A'): raise_if_slycot_error(info, arg_list) return A,E,B,C,lscale,rscale -def tg01fd(l,n,m,p,A,E,B,C,Q=None,Z=None,compq='N',compz='N',joba='N',tol=0.0,ldwork=None): +def tg01fd(l,n,m,p,A,E,B,C,Q=None,Z=None,compq='N',compz='N',joba='N',tol=0.0,ldwork=None): # noqa: E741 """ A,E,B,C,ranke,rnka22,Q,Z = tg01fd(l,n,m,p,A,E,B,C,[Q,Z,compq,compz,joba,tol,ldwork]) To compute for the descriptor system (A-lambda E,B,C)