Skip to content

Commit

Permalink
MAINT: lint: enable line-length check (package-wide) (scipy#19609)
Browse files Browse the repository at this point in the history
* MAINT: `noqa` for awkward UP007 violation

I tried to fix but `mypy` complains along the lines of python/mypy#12393

* MAINT: lint: enable line-length check in `cluster`

* MAINT: lint: enable line-length check in `integrate`
[lint only]

* MAINT: lint: enable line-length check in `interpolate`
[lint only]

* MAINT: lint: enable line-length check in `io`
[lint only]

* MAINT: lint: enable line-length check in `ndimage`
[lint only]

* MAINT: lint: enable line-length check in `signal`
[lint only]

* MAINT: lint: enable line-length check in `linalg`
[lint only]

* MAINT: lint: enable line-length check in `spatial`
[lint only]

* MAINT: lint: enable line-length check in `sparse`
[lint only]

* MAINT: lint: enable line-length check in `_lib`
[lint only]

* MAINT: lint: enable line-length check in `stats`
[lint only]

* MAINT: lint: enable line-length check in `special`
[lint only]

* MAINT: lint: enable line-length check in `optimize`
[lint only]

* MAINT: lint: enable line-length check in `benchmarks`
[lint only]

* MAINT: lint: enable line-length check in `tools`

* MAINT: lint: `per-file-ignores` clean-up

* MAINT: PR 19609 revisions
  • Loading branch information
lucascolley committed Dec 8, 2023
1 parent 8166222 commit fa9f13e
Show file tree
Hide file tree
Showing 177 changed files with 3,320 additions and 1,860 deletions.
3 changes: 2 additions & 1 deletion benchmarks/benchmarks/go_benchmark_functions/go_funcs_C.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,8 @@ class Cube(Benchmark):
f_{\text{Cube}}(x) = 100(x_2 - x_1^3)^2 + (1 - x1)^2
Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-10, 10]` for :math:`i=1,...,N`.
Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-10, 10]`
for :math:`i=1,...,N`.
*Global optimum*: :math:`f(x_i) = 0.0` for :math:`x = [1, 1]`
Expand Down
4 changes: 2 additions & 2 deletions benchmarks/benchmarks/go_benchmark_functions/go_funcs_D.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,8 @@ class DeVilliersGlasser02(Benchmark):
r"""
DeVilliers-Glasser 2 objective function.
This class defines the DeVilliers-Glasser 2 [1]_ function global optimization problem. This
is a multimodal minimization problem defined as follows:
This class defines the DeVilliers-Glasser 2 [1]_ function global optimization
problem. This is a multimodal minimization problem defined as follows:
.. math::
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmarks/go_benchmark_functions/go_funcs_E.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class Easom(Benchmark):
For Global Optimization Problems Int. Journal of Mathematical Modelling
and Numerical Optimisation, 2013, 4, 150-194.
TODO Gavana website disagrees with Jamil, etc. Gavana equation in docstring is totally wrong.
TODO Gavana website disagrees with Jamil, etc.
Gavana equation in docstring is totally wrong.
"""

def __init__(self, dimensions=2):
Expand Down
16 changes: 11 additions & 5 deletions benchmarks/benchmarks/go_benchmark_functions/go_funcs_L.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class Levy03(Benchmark):
.. math::
f_{\text{Levy03}}(\mathbf{x}) = \sin^2(\pi y_1)+\sum_{i=1}^{n-1}(y_i-1)^2[1+10\sin^2(\pi y_{i+1})]+(y_n-1)^2
f_{\text{Levy03}}(\mathbf{x}) =
\sin^2(\pi y_1)+\sum_{i=1}^{n-1}(y_i-1)^2[1+10\sin^2(\pi y_{i+1})]+(y_n-1)^2
Where, in this exercise:
Expand All @@ -212,7 +213,8 @@ class Levy03(Benchmark):
y_i=1+\frac{x_i-1}{4}
Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-10, 10]` for :math:`i=1,...,n`.
Here, :math:`n` represents the number of dimensions and
:math:`x_i \in [-10, 10]` for :math:`i=1,...,n`.
*Global optimum*: :math:`f(x_i) = 0` for :math:`x_i = 1` for :math:`i=1,...,n`
Expand Down Expand Up @@ -254,11 +256,15 @@ class Levy05(Benchmark):
.. math::
f_{\text{Levy05}}(\mathbf{x}) = \sum_{i=1}^{5} i \cos \left[(i-1)x_1 + i \right] \times \sum_{j=1}^{5} j \cos \left[(j+1)x_2 + j \right] + (x_1 + 1.42513)^2 + (x_2 + 0.80032)^2
f_{\text{Levy05}}(\mathbf{x}) =
\sum_{i=1}^{5} i \cos \left[(i-1)x_1 + i \right] \times \sum_{j=1}^{5} j
\cos \left[(j+1)x_2 + j \right] + (x_1 + 1.42513)^2 + (x_2 + 0.80032)^2
Here, :math:`n` represents the number of dimensions and :math:`x_i \in [-10, 10]` for :math:`i=1,...,n`.
Here, :math:`n` represents the number of dimensions and
:math:`x_i \in [-10, 10]` for :math:`i=1,...,n`.
*Global optimum*: :math:`f(x_i) = -176.1375779` for :math:`\mathbf{x} = [-1.30685, -1.42485]`.
*Global optimum*: :math:`f(x_i) = -176.1375779` for
:math:`\mathbf{x} = [-1.30685, -1.42485]`.
.. [1] Mishra, S. Global Optimization by Differential Evolution and
Particle Swarm Methods: Evaluation on Some Benchmark Functions.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ class Problem07(Benchmark):
.. math::
f_{\\text{Problem07}}(x) = \\sin(x) + \\sin \\left(\\frac{10}{3}x \\right) + \\log(x) - 0.84x + 3
f_{\\text{Problem07}}(x) = \\sin(x) + \\sin \\left(\\frac{10}{3}x
\\right) + \\log(x) - 0.84x + 3
Bound constraints: :math:`x \\in [2.7, 7.5]`
Expand Down Expand Up @@ -571,8 +572,9 @@ class Problem18(Benchmark):
.. math::
f_{\\text{Problem18}}(x) = \\begin{cases}(x-2)^2 & \\textrm{if} \\hspace{5pt} x \\leq 3 \\\\
2\\log(x-2)+1&\\textrm{otherwise}\\end{cases}
f_{\\text{Problem18}}(x)
= \\begin{cases}(x-2)^2 & \\textrm{if} \\hspace{5pt} x
\\leq 3 \\\\ 2\\log(x-2)+1&\\textrm{otherwise}\\end{cases}
Bound constraints: :math:`x \\in [0, 6]`
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmarks/integrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def setup(self):
voidp = ctypes.cast(self.f_ctypes, ctypes.c_void_p)
address = voidp.value
ffi = cffi.FFI()
self.f_cffi = LowLevelCallable(ffi.cast("double (*)(int, double *)", address))
self.f_cffi = LowLevelCallable(ffi.cast("double (*)(int, double *)",
address))

def time_quad_python(self):
quad(self.f_python, 0, np.pi)
Expand Down
20 changes: 14 additions & 6 deletions benchmarks/benchmarks/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def setup(self, n_grids, method):
self.values = self.func(self.points[:, 0], self.points[:, 1])

def time_evaluation(self, n_grids, method):
interpolate.griddata(self.points, self.values, (self.grid_x, self.grid_y), method=method)
interpolate.griddata(self.points, self.values, (self.grid_x, self.grid_y),
method=method)


class Interpolate1d(Benchmark):
Expand Down Expand Up @@ -128,7 +129,8 @@ class Rbf(Benchmark):
param_names = ['n_samples', 'function']
params = [
[10, 50, 100],
['multiquadric', 'inverse', 'gaussian', 'linear', 'cubic', 'quintic', 'thin_plate']
['multiquadric', 'inverse', 'gaussian', 'linear',
'cubic', 'quintic', 'thin_plate']
]

def setup(self, n_samples, function):
Expand Down Expand Up @@ -220,7 +222,8 @@ def time_smooth_bivariate_spline(self, n_samples):
interpolate.SmoothBivariateSpline(self.x, self.y, self.z)

def time_lsq_bivariate_spline(self, n_samples):
interpolate.LSQBivariateSpline(self.x, self.y, self.z, self.xknots.flat, self.yknots.flat)
interpolate.LSQBivariateSpline(self.x, self.y, self.z,
self.xknots.flat, self.yknots.flat)


class Interpolate(Benchmark):
Expand Down Expand Up @@ -376,14 +379,19 @@ class CloughTocherInterpolatorValues(interpolate.CloughTocher2DInterpolator):
https://github.com/scipy/scipy/pull/18376 for discussion
"""
def __init__(self, points, xi, tol=1e-6, maxiter=400, **kwargs):
interpolate.CloughTocher2DInterpolator.__init__(self, points, None, tol=tol, maxiter=maxiter)
interpolate.CloughTocher2DInterpolator.__init__(self, points, None,
tol=tol, maxiter=maxiter)
self.xi = None
self._preprocess_xi(*xi)
self.simplices, self.c = interpolate.CloughTocher2DInterpolator._find_simplicies(self, self.xi)
self.simplices, self.c = (
interpolate.CloughTocher2DInterpolator._find_simplicies(self, self.xi)
)

def _preprocess_xi(self, *args):
if self.xi is None:
self.xi, self.interpolation_points_shape = interpolate.CloughTocher2DInterpolator._preprocess_xi(self, *args)
self.xi, self.interpolation_points_shape = (
interpolate.CloughTocher2DInterpolator._preprocess_xi(self, *args)
)
return self.xi, self.interpolation_points_shape

def _find_simplicies(self, xi):
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/benchmarks/io_mm.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def generate_dense(size):
a = generate_{matrix_type}({size})
mmwrite('{self.filename}', a, symmetry='general')
"""
""" # noqa: E501
time, peak_mem = run_monitored(code)
return peak_mem / size

Expand Down
24 changes: 18 additions & 6 deletions benchmarks/benchmarks/linalg.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,21 @@ def time_svd(self, size, contig, module):
sl.svd(self.a)

# Retain old benchmark results (remove this if changing the benchmark)
time_det.version = "87e530ee50eb6b6c06c7a8abe51c2168e133d5cbd486f4c1c2b9cedc5a078325"
time_eigvals.version = "9d68d3a6b473df9bdda3d3fd25c7f9aeea7d5cee869eec730fb2a2bcd1dfb907"
time_inv.version = "20beee193c84a5713da9749246a7c40ef21590186c35ed00a4fe854cce9e153b"
time_solve.version = "1fe788070f1c9132cbe78a47fdb4cce58266427fc636d2aa9450e3c7d92c644c"
time_svd.version = "0ccbda456d096e459d4a6eefc6c674a815179e215f83931a81cfa8c18e39d6e3"
time_det.version = (
"87e530ee50eb6b6c06c7a8abe51c2168e133d5cbd486f4c1c2b9cedc5a078325"
)
time_eigvals.version = (
"9d68d3a6b473df9bdda3d3fd25c7f9aeea7d5cee869eec730fb2a2bcd1dfb907"
)
time_inv.version = (
"20beee193c84a5713da9749246a7c40ef21590186c35ed00a4fe854cce9e153b"
)
time_solve.version = (
"1fe788070f1c9132cbe78a47fdb4cce58266427fc636d2aa9450e3c7d92c644c"
)
time_svd.version = (
"0ccbda456d096e459d4a6eefc6c674a815179e215f83931a81cfa8c18e39d6e3"
)


class Norm(Benchmark):
Expand Down Expand Up @@ -178,7 +188,9 @@ def time_lstsq(self, dtype, size, lapack_driver):
lapack_driver=lapack_driver)

# Retain old benchmark results (remove this if changing the benchmark)
time_lstsq.version = "15ee0be14a0a597c7d1c9a3dab2c39e15c8ac623484410ffefa406bf6b596ebe"
time_lstsq.version = (
"15ee0be14a0a597c7d1c9a3dab2c39e15c8ac623484410ffefa406bf6b596ebe"
)


class SpecialMatrices(Benchmark):
Expand Down
33 changes: 22 additions & 11 deletions benchmarks/benchmarks/optimize.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,15 @@ def print_results(self):
print("")
print("=========================================================")
print("Optimizer benchmark: %s" % (self.function_name))
print("dimensions: %d, extra kwargs: %s" % (results[0].ndim, str(self.minimizer_kwargs)))
print("dimensions: %d, extra kwargs: %s" %
(results[0].ndim, str(self.minimizer_kwargs)))
print("averaged over %d starting configurations" % (results[0].ntrials))
print(" Optimizer nfail nfev njev nhev time")
print("---------------------------------------------------------")
for res in results:
print("%11s | %4d | %4d | %4d | %4d | %.6g" %
(res.name, res.nfail, res.mean_nfev, res.mean_njev, res.mean_nhev, res.mean_time))
(res.name, res.nfail, res.mean_nfev,
res.mean_njev, res.mean_nhev, res.mean_time))

def average_results(self):
"""group the results by minimizer and average over the runs"""
Expand Down Expand Up @@ -370,7 +372,8 @@ def run_rosenbrock_tight(self, methods=None):

def run_simple_quadratic(self, methods=None):
s = funcs.SimpleQuadratic()
# print "checking gradient", scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
# print "checking gradient",
# scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
b = _BenchOptimizers("simple quadratic function",
fun=s.fun, der=s.der, hess=s.hess)
for i in range(10):
Expand All @@ -379,7 +382,8 @@ def run_simple_quadratic(self, methods=None):

def run_asymmetric_quadratic(self, methods=None):
s = funcs.AsymmetricQuadratic()
# print "checking gradient", scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
# print "checking gradient",
# scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
b = _BenchOptimizers("function sum(x**2) + x[0]",
fun=s.fun, der=s.der, hess=s.hess)
for i in range(10):
Expand All @@ -401,7 +405,8 @@ def der(x):

def run_booth(self, methods=None):
s = funcs.Booth()
# print "checking gradient", scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
# print "checking gradient",
# scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
b = _BenchOptimizers("Booth's function",
fun=s.fun, der=s.der, hess=None)
for i in range(10):
Expand All @@ -410,7 +415,8 @@ def run_booth(self, methods=None):

def run_beale(self, methods=None):
s = funcs.Beale()
# print "checking gradient", scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
# print "checking gradient",
# scipy.optimize.check_grad(s.fun, s.der, np.array([1.1, -2.3]))
b = _BenchOptimizers("Beale's function",
fun=s.fun, der=s.der, hess=None)
for i in range(10):
Expand All @@ -419,8 +425,9 @@ def run_beale(self, methods=None):

def run_LJ(self, methods=None):
s = funcs.LJ()
# print "checking gradient", scipy.optimize.check_grad(s.get_energy, s.get_gradient,
# np.random.uniform(-2,2,3*4))
# print "checking gradient",
# scipy.optimize.check_grad(s.get_energy, s.get_gradient,
# np.random.uniform(-2,2,3*4))
natoms = 4
b = _BenchOptimizers("%d atom Lennard Jones potential" % (natoms),
fun=s.fun, der=s.der, hess=None)
Expand Down Expand Up @@ -512,7 +519,9 @@ def __init__(self):
except (KeyError, ValueError):
self.numtrials = 100

self.dump_fn = os.path.join(os.path.dirname(__file__), '..', 'global-bench-results.json')
self.dump_fn = os.path.join(os.path.dirname(__file__),
'..',
'global-bench-results.json',)
self.results = {}

def setup(self, name, ret_value, solver):
Expand All @@ -536,7 +545,8 @@ def track_all(self, name, ret_value, solver):
# if so, then just return the ret_value
av_results = self.results[name]
if ret_value == 'success%':
return 100 * av_results[solver]['nsuccess'] / av_results[solver]['ntrials']
return (100 * av_results[solver]['nsuccess']
/ av_results[solver]['ntrials'])
elif ret_value == '<nfev>':
return av_results[solver]['mean_nfev']
else:
Expand All @@ -557,7 +567,8 @@ def track_all(self, name, ret_value, solver):
self.results[name][solver] = av_results[solver]

if ret_value == 'success%':
return 100 * av_results[solver]['nsuccess'] / av_results[solver]['ntrials']
return (100 * av_results[solver]['nsuccess']
/ av_results[solver]['ntrials'])
elif ret_value == '<nfev>':
return av_results[solver]['mean_nfev']
else:
Expand Down
48 changes: 36 additions & 12 deletions benchmarks/benchmarks/sparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ def time_large(self):
self.matrix1 * self.matrix2

# Retain old benchmark results (remove this if changing the benchmark)
time_large.version = "33aee08539377a7cb0fabaf0d9ff9d6d80079a428873f451b378c39f6ead48cb"
time_large.version = (
"33aee08539377a7cb0fabaf0d9ff9d6d80079a428873f451b378c39f6ead48cb"
)


class Construction(Benchmark):
Expand Down Expand Up @@ -379,12 +381,24 @@ def time_100_cols(self, density, format):
self.X[:, np.arange(100)]

# Retain old benchmark results (remove this if changing the benchmark)
time_10000_rows.version = "dc19210b894d5fd41d4563f85b7459ef5836cddaf77154b539df3ea91c5d5c1c"
time_100_cols.version = "8d43ed52084cdab150018eedb289a749a39f35d4dfa31f53280f1ef286a23046"
time_3_cols.version = "93e5123910772d62b3f72abff56c2732f83d217221bce409b70e77b89c311d26"
time_3_rows.version = "a9eac80863a0b2f4b510269955041930e5fdd15607238257eb78244f891ebfe6"
time_getcol.version = "291388763b355f0f3935db9272a29965d14fa3f305d3306059381e15300e638b"
time_getrow.version = "edb9e4291560d6ba8dd58ef371b3a343a333bc10744496adb3ff964762d33c68"
time_10000_rows.version = (
"dc19210b894d5fd41d4563f85b7459ef5836cddaf77154b539df3ea91c5d5c1c"
)
time_100_cols.version = (
"8d43ed52084cdab150018eedb289a749a39f35d4dfa31f53280f1ef286a23046"
)
time_3_cols.version = (
"93e5123910772d62b3f72abff56c2732f83d217221bce409b70e77b89c311d26"
)
time_3_rows.version = (
"a9eac80863a0b2f4b510269955041930e5fdd15607238257eb78244f891ebfe6"
)
time_getcol.version = (
"291388763b355f0f3935db9272a29965d14fa3f305d3306059381e15300e638b"
)
time_getrow.version = (
"edb9e4291560d6ba8dd58ef371b3a343a333bc10744496adb3ff964762d33c68"
)


class Diagonal(Benchmark):
Expand All @@ -404,7 +418,9 @@ def time_diagonal(self, density, format):
self.X.diagonal()

# Retain old benchmark results (remove this if changing the benchmark)
time_diagonal.version = "d84f53fdc6abc208136c8ce48ca156370f6803562f6908eb6bd1424f50310cf1"
time_diagonal.version = (
"d84f53fdc6abc208136c8ce48ca156370f6803562f6908eb6bd1424f50310cf1"
)


class Sum(Benchmark):
Expand All @@ -429,9 +445,15 @@ def time_sum_axis1(self, density, format):
self.X.sum(axis=1)

# Retain old benchmark results (remove this if changing the benchmark)
time_sum.version = "05c305857e771024535e546360203b17f5aca2b39b023a49ab296bd746d6cdd3"
time_sum_axis0.version = "8aca682fd69aa140c69c028679826bdf43c717589b1961b4702d744ed72effc6"
time_sum_axis1.version = "1a6e05244b77f857c61f8ee09ca3abd006a10ba07eff10b1c5f9e0ac20f331b2"
time_sum.version = (
"05c305857e771024535e546360203b17f5aca2b39b023a49ab296bd746d6cdd3"
)
time_sum_axis0.version = (
"8aca682fd69aa140c69c028679826bdf43c717589b1961b4702d744ed72effc6"
)
time_sum_axis1.version = (
"1a6e05244b77f857c61f8ee09ca3abd006a10ba07eff10b1c5f9e0ac20f331b2"
)


class Iteration(Benchmark):
Expand Down Expand Up @@ -463,7 +485,9 @@ def time_toarray(self, format, order):
self.X.toarray(order=order)

# Retain old benchmark results (remove this if changing the benchmark)
time_toarray.version = "2fbf492ec800b982946a62785beda803460b913cc80080043a5d407025893b2b"
time_toarray.version = (
"2fbf492ec800b982946a62785beda803460b913cc80080043a5d407025893b2b"
)


class Random(Benchmark):
Expand Down
3 changes: 2 additions & 1 deletion benchmarks/benchmarks/sparse_csgraph_matching.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ def random_uniform(shape, rng):


def random_uniform_sparse(shape, rng):
return scipy.sparse.random(shape[0], shape[1], density=0.1, format='csr', random_state=rng)
return scipy.sparse.random(shape[0], shape[1],
density=0.1, format='csr', random_state=rng)


def random_uniform_integer(shape, rng):
Expand Down

0 comments on commit fa9f13e

Please sign in to comment.