From 476178fdbe98af7463ee3a90b22cad20169099ad Mon Sep 17 00:00:00 2001 From: Pierre-antoine Comby Date: Fri, 16 Feb 2024 21:22:47 +0100 Subject: [PATCH] run ruff --fix --unsafe-fixes . --- docs/source/conf.py | 23 +++++++++---------- modopt/__init__.py | 1 - modopt/base/__init__.py | 1 - modopt/base/backend.py | 1 - modopt/base/np_adjust.py | 1 - modopt/base/observable.py | 7 +++--- modopt/base/transform.py | 5 ++-- modopt/base/types.py | 3 +-- modopt/base/wrappers.py | 1 - .../example_lasso_forward_backward.py | 1 - modopt/interface/__init__.py | 1 - modopt/interface/errors.py | 13 +++++------ modopt/interface/log.py | 3 +-- modopt/math/__init__.py | 1 - modopt/math/convolve.py | 1 - modopt/math/matrix.py | 3 +-- modopt/math/metrics.py | 3 +-- modopt/math/stats.py | 1 - modopt/opt/__init__.py | 1 - modopt/opt/algorithms/__init__.py | 19 --------------- modopt/opt/algorithms/base.py | 3 +-- modopt/opt/algorithms/forward_backward.py | 9 ++++---- modopt/opt/algorithms/gradient_descent.py | 1 - modopt/opt/algorithms/primal_dual.py | 1 - modopt/opt/gradient.py | 5 ++-- modopt/opt/linear/base.py | 2 +- modopt/opt/proximity.py | 21 ++++++++--------- modopt/opt/reweight.py | 5 ++-- modopt/plot/__init__.py | 1 - modopt/plot/cost_plot.py | 3 +-- modopt/signal/__init__.py | 1 - modopt/signal/filter.py | 1 - modopt/signal/noise.py | 2 -- modopt/signal/positivity.py | 1 - modopt/signal/svd.py | 1 - modopt/signal/wavelet.py | 9 ++++---- modopt/tests/test_algorithms.py | 8 +------ modopt/tests/test_helpers/__init__.py | 1 - modopt/tests/test_opt.py | 12 ++++++---- modopt/tests/test_signal.py | 2 +- 40 files changed, 61 insertions(+), 118 deletions(-) diff --git a/docs/source/conf.py b/docs/source/conf.py index 987576a9..cd39ee08 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- # Python Template sphinx config # Import relevant modules @@ -19,7 +18,7 @@ mdata = metadata(project) author = mdata["Author"] version = mdata["Version"] -copyright = "2020, {}".format(author) +copyright = f"2020, {author}" gh_user = "sfarrens" # If your documentation needs a minimal Sphinx version, state it here. @@ -117,7 +116,7 @@ ) # The name for this set of Sphinx documents. If None, it defaults to # " v documentation". -html_title = "{0} v{1}".format(project, version) +html_title = f"{project} v{version}" # A shorter title for the navigation bar. Default is the same as html_title. # html_short_title = None @@ -174,20 +173,20 @@ def add_notebooks(nb_path="../../notebooks"): nb_name = nb.rstrip(nb_ext) nb_link_file_name = nb_name + ".nblink" - print("Writing {0}".format(nb_link_file_name)) + print(f"Writing {nb_link_file_name}") with open(nb_link_file_name, "w") as nb_link_file: nb_link_file.write(nb_link_format.format(nb_path, nb)) - print("Looking for {0} in {1}".format(nb_name, nb_rst_file_name)) - with open(nb_rst_file_name, "r") as nb_rst_file: + print(f"Looking for {nb_name} in {nb_rst_file_name}") + with open(nb_rst_file_name) as nb_rst_file: check_name = nb_name not in nb_rst_file.read() if check_name: - print("Adding {0} to {1}".format(nb_name, nb_rst_file_name)) + print(f"Adding {nb_name} to {nb_rst_file_name}") with open(nb_rst_file_name, "a") as nb_rst_file: if list_pos == 0: nb_rst_file.write("\n") - nb_rst_file.write(" {0}\n".format(nb_name)) + nb_rst_file.write(f" {nb_name}\n") return nbs @@ -220,14 +219,14 @@ def add_notebooks(nb_path="../../notebooks"): """ nb_header_pt2 = ( r"""

""" - r"""""" - + r"""Binder badge
""" r"""

""" ) diff --git a/modopt/__init__.py b/modopt/__init__.py index d446e15d..958f3ace 100644 --- a/modopt/__init__.py +++ b/modopt/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """MODOPT PACKAGE. diff --git a/modopt/base/__init__.py b/modopt/base/__init__.py index 3946e04c..8ffa13e4 100644 --- a/modopt/base/__init__.py +++ b/modopt/base/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """BASE ROUTINES. diff --git a/modopt/base/backend.py b/modopt/base/backend.py index fd933ebb..b4987942 100644 --- a/modopt/base/backend.py +++ b/modopt/base/backend.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """BACKEND MODULE. diff --git a/modopt/base/np_adjust.py b/modopt/base/np_adjust.py index 31a785f5..586a1ee0 100644 --- a/modopt/base/np_adjust.py +++ b/modopt/base/np_adjust.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """NUMPY ADJUSTMENT ROUTINES. diff --git a/modopt/base/observable.py b/modopt/base/observable.py index 2f69a1a7..69c6b238 100644 --- a/modopt/base/observable.py +++ b/modopt/base/observable.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Observable. @@ -13,13 +12,13 @@ import numpy as np -class SignalObject(object): +class SignalObject: """Dummy class for signals.""" pass -class Observable(object): +class Observable: """Base class for observable classes. This class defines a simple interface to add or remove observers @@ -177,7 +176,7 @@ def _remove_observer(self, signal, observer): self._observers[signal].remove(observer) -class MetricObserver(object): +class MetricObserver: """Metric observer. Wrapper of the metric to the observer object notify by the Observable diff --git a/modopt/base/transform.py b/modopt/base/transform.py index fedd5efb..1dc9039a 100644 --- a/modopt/base/transform.py +++ b/modopt/base/transform.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """DATA TRANSFORM ROUTINES. @@ -288,7 +287,7 @@ def cube2matrix(data_cube): """ return data_cube.reshape( - [data_cube.shape[0]] + [np.prod(data_cube.shape[1:])], + [data_cube.shape[0], np.prod(data_cube.shape[1:])], ).T @@ -333,4 +332,4 @@ def matrix2cube(data_matrix, im_shape): cube2matrix : complimentary function """ - return data_matrix.T.reshape([data_matrix.shape[1]] + list(im_shape)) + return data_matrix.T.reshape([data_matrix.shape[1], *list(im_shape)]) diff --git a/modopt/base/types.py b/modopt/base/types.py index af2184f5..ae2b6830 100644 --- a/modopt/base/types.py +++ b/modopt/base/types.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """TYPE HANDLING ROUTINES. @@ -183,7 +182,7 @@ def check_npndarray(input_obj, dtype=None, writeable=True, verbose=True): ): raise ( TypeError( - "The numpy array elements are not of type: {0}".format(dtype), + f"The numpy array elements are not of type: {dtype}", ), ) diff --git a/modopt/base/wrappers.py b/modopt/base/wrappers.py index bec71c39..df8a4d07 100644 --- a/modopt/base/wrappers.py +++ b/modopt/base/wrappers.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """WRAPPERS. diff --git a/modopt/examples/example_lasso_forward_backward.py b/modopt/examples/example_lasso_forward_backward.py index c28b0499..7e650e05 100644 --- a/modopt/examples/example_lasso_forward_backward.py +++ b/modopt/examples/example_lasso_forward_backward.py @@ -1,4 +1,3 @@ -# noqa: D205 """ Solving the LASSO Problem with the Forward Backward Algorithm. ============================================================== diff --git a/modopt/interface/__init__.py b/modopt/interface/__init__.py index 55904ca1..529816ee 100644 --- a/modopt/interface/__init__.py +++ b/modopt/interface/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """INTERFACE ROUTINES. diff --git a/modopt/interface/errors.py b/modopt/interface/errors.py index eb4aa4ca..5c84ad0e 100644 --- a/modopt/interface/errors.py +++ b/modopt/interface/errors.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """ERROR HANDLING ROUTINES. @@ -39,7 +38,7 @@ def warn(warn_string, log=None): warn_txt = colored("WARNING", "yellow") # Print warning to stdout. - sys.stderr.write("{0}: {1}\n".format(warn_txt, warn_string)) + sys.stderr.write(f"{warn_txt}: {warn_string}\n") # Check if a logging structure is provided. if not isinstance(log, type(None)): @@ -66,12 +65,12 @@ def catch_error(exception, log=None): err_txt = colored("ERROR", "red") # Print exception to stdout. - stream_txt = "{0}: {1}\n".format(err_txt, exception) + stream_txt = f"{err_txt}: {exception}\n" sys.stderr.write(stream_txt) # Check if a logging structure is provided. if not isinstance(log, type(None)): - log_txt = "ERROR: {0}\n".format(exception) + log_txt = f"ERROR: {exception}\n" log.exception(log_txt) @@ -92,10 +91,10 @@ def file_name_error(file_name): """ if file_name == "" or file_name[0][0] == "-": - raise IOError("Input file name not specified.") + raise OSError("Input file name not specified.") elif not os.path.isfile(file_name): - raise IOError("Input file name {0} not found!".format(file_name)) + raise OSError(f"Input file name {file_name} not found!") def is_exe(fpath): @@ -151,4 +150,4 @@ def is_executable(exe_name): if not res: message = "{0} does not appear to be a valid executable on this system." - raise IOError(message.format(exe_name)) + raise OSError(message.format(exe_name)) diff --git a/modopt/interface/log.py b/modopt/interface/log.py index a02428d9..d3e0d8e9 100644 --- a/modopt/interface/log.py +++ b/modopt/interface/log.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """LOGGING ROUTINES. @@ -30,7 +29,7 @@ def set_up_log(filename, verbose=True): """ # Add file extension. - filename = "{0}.log".format(filename) + filename = f"{filename}.log" if verbose: print("Preparing log file:", filename) diff --git a/modopt/math/__init__.py b/modopt/math/__init__.py index 8e92aa50..0423a333 100644 --- a/modopt/math/__init__.py +++ b/modopt/math/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """MATHEMATICS ROUTINES. diff --git a/modopt/math/convolve.py b/modopt/math/convolve.py index 528b2338..ac1cf84c 100644 --- a/modopt/math/convolve.py +++ b/modopt/math/convolve.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """CONVOLUTION ROUTINES. diff --git a/modopt/math/matrix.py b/modopt/math/matrix.py index 6ddb3f2f..a2419a6c 100644 --- a/modopt/math/matrix.py +++ b/modopt/math/matrix.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """MATRIX ROUTINES. @@ -257,7 +256,7 @@ def rotate(matrix, angle): return matrix[tuple(zip(new_index.T))].reshape(shape.T) -class PowerMethod(object): +class PowerMethod: """Power method class. This method performs implements power method to calculate the spectral diff --git a/modopt/math/metrics.py b/modopt/math/metrics.py index 93f7ce06..8f797f02 100644 --- a/modopt/math/metrics.py +++ b/modopt/math/metrics.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """METRICS. @@ -268,6 +267,6 @@ def nrmse(test, ref, mask=None): ref = mask * ref num = np.sqrt(mse(test, ref)) - deno = np.sqrt(np.mean((np.square(test)))) + deno = np.sqrt(np.mean(np.square(test))) return num / deno diff --git a/modopt/math/stats.py b/modopt/math/stats.py index 59bf6759..b3ee0d8b 100644 --- a/modopt/math/stats.py +++ b/modopt/math/stats.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """STATISTICS ROUTINES. diff --git a/modopt/opt/__init__.py b/modopt/opt/__init__.py index 8b285bee..86564f90 100644 --- a/modopt/opt/__init__.py +++ b/modopt/opt/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """OPTIMISATION PROBLEM MODULES. diff --git a/modopt/opt/algorithms/__init__.py b/modopt/opt/algorithms/__init__.py index 6a29325a..ce6c5e56 100644 --- a/modopt/opt/algorithms/__init__.py +++ b/modopt/opt/algorithms/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- r"""OPTIMISATION ALGORITHMS. This module contains class implementations of various optimisation algoritms. @@ -45,21 +44,3 @@ """ -from modopt.opt.algorithms.base import SetUp -from modopt.opt.algorithms.forward_backward import ( - FISTA, - POGM, - ForwardBackward, - GenForwardBackward, -) -from modopt.opt.algorithms.gradient_descent import ( - AdaGenericGradOpt, - ADAMGradOpt, - GenericGradOpt, - MomentumGradOpt, - RMSpropGradOpt, - SAGAOptGradOpt, - VanillaGenericGradOpt, -) -from modopt.opt.algorithms.primal_dual import Condat -from modopt.opt.algorithms.admm import ADMM, FastADMM diff --git a/modopt/opt/algorithms/base.py b/modopt/opt/algorithms/base.py index e2b9017d..dbb73be0 100644 --- a/modopt/opt/algorithms/base.py +++ b/modopt/opt/algorithms/base.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Base SetUp for optimisation algorithms.""" from inspect import getmro @@ -118,7 +117,7 @@ def metrics(self, metrics): self._metrics = metrics else: raise TypeError( - "Metrics must be a dictionary, not {0}.".format(type(metrics)), + f"Metrics must be a dictionary, not {type(metrics)}.", ) def any_convergence_flag(self): diff --git a/modopt/opt/algorithms/forward_backward.py b/modopt/opt/algorithms/forward_backward.py index d34125fa..4c1cb35c 100644 --- a/modopt/opt/algorithms/forward_backward.py +++ b/modopt/opt/algorithms/forward_backward.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Forward-Backward Algorithms.""" import numpy as np @@ -9,7 +8,7 @@ from modopt.opt.linear import Identity -class FISTA(object): +class FISTA: r"""FISTA. This class is inherited by optimisation classes to speed up convergence @@ -602,7 +601,7 @@ def __init__( self._x_old = self.xp.copy(x) # Set the algorithm operators - for operator in [grad, cost] + prox_list: + for operator in [grad, cost, *prox_list]: self._check_operator(operator) self._grad = grad @@ -610,7 +609,7 @@ def __init__( self._linear = linear if cost == "auto": - self._cost_func = costObj([self._grad] + prox_list) + self._cost_func = costObj([self._grad, *prox_list]) else: self._cost_func = cost @@ -689,7 +688,7 @@ def _set_weights(self, weights): if self.xp.sum(weights) != expected_weight_sum: raise ValueError( "Proximity operator weights must sum to 1.0. Current sum of " - + "weights = {0}".format(self.xp.sum(weights)), + + f"weights = {self.xp.sum(weights)}", ) self._weights = weights diff --git a/modopt/opt/algorithms/gradient_descent.py b/modopt/opt/algorithms/gradient_descent.py index d3af1686..0960be5a 100644 --- a/modopt/opt/algorithms/gradient_descent.py +++ b/modopt/opt/algorithms/gradient_descent.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Gradient Descent Algorithms.""" import numpy as np diff --git a/modopt/opt/algorithms/primal_dual.py b/modopt/opt/algorithms/primal_dual.py index 179ddf95..24908993 100644 --- a/modopt/opt/algorithms/primal_dual.py +++ b/modopt/opt/algorithms/primal_dual.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """Primal-Dual Algorithms.""" from modopt.opt.algorithms.base import SetUp diff --git a/modopt/opt/gradient.py b/modopt/opt/gradient.py index 8d7bacc7..bd214f21 100644 --- a/modopt/opt/gradient.py +++ b/modopt/opt/gradient.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """GRADIENT CLASSES. @@ -14,7 +13,7 @@ from modopt.base.types import check_callable, check_float, check_npndarray -class GradParent(object): +class GradParent: """Gradient Parent Class. This class defines the basic methods that will be inherited by specific @@ -289,7 +288,7 @@ def _cost_method(self, *args, **kwargs): """ cost_val = 0.5 * np.linalg.norm(self.obs_data - self.op(args[0])) ** 2 - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - DATA FIDELITY (X):", cost_val) return cost_val diff --git a/modopt/opt/linear/base.py b/modopt/opt/linear/base.py index 79f05d85..9fa35187 100644 --- a/modopt/opt/linear/base.py +++ b/modopt/opt/linear/base.py @@ -6,7 +6,7 @@ from modopt.base.backend import get_array_module -class LinearParent(object): +class LinearParent: """Linear Operator Parent Class. This class sets the structure for defining linear operator instances. diff --git a/modopt/opt/proximity.py b/modopt/opt/proximity.py index b562f77a..91a99f2a 100644 --- a/modopt/opt/proximity.py +++ b/modopt/opt/proximity.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """PROXIMITY OPERATORS. @@ -32,7 +31,7 @@ from modopt.signal.svd import svd_thresh, svd_thresh_coef, svd_thresh_coef_fast -class ProximityParent(object): +class ProximityParent: """Proximity Operator Parent Class. This class sets the structure for defining proximity operator instances. @@ -140,7 +139,7 @@ def _cost_method(self, *args, **kwargs): ``0.0`` """ - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - Min (X):", np.min(args[0])) return 0 @@ -221,7 +220,7 @@ def _cost_method(self, *args, **kwargs): if isinstance(cost_val, xp.ndarray): cost_val = cost_val.item() - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - L1 NORM (X):", cost_val) return cost_val @@ -365,7 +364,7 @@ def _cost_method(self, *args, **kwargs): """ cost_val = self.thresh * nuclear_norm(cube2matrix(args[0])) - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - NUCLEAR NORM (X):", cost_val) return cost_val @@ -706,7 +705,7 @@ def _cost_method(self, *args, **kwargs): self.weights * np.sort(np.squeeze(np.abs(args[0]))[::-1]), ) - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - OWL NORM (X):", cost_val) return cost_val @@ -790,7 +789,7 @@ def _cost_method(self, *args, **kwargs): np.abs(self.weights * self._linear.op(args[0]) ** 2), ) - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - L2 NORM (X):", cost_val) return cost_val @@ -879,7 +878,7 @@ def _cost_method(self, *args, **kwargs): + np.abs(self.beta * self._linear.op(args[0])), ) - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - ELASTIC NET (X):", cost_val) return cost_val @@ -1183,7 +1182,7 @@ def _find_alpha(self, input_data, extra_factor=1.0): data_size = input_data.shape[0] # Computes the alpha^i points line 1 in Algorithm 1. - alpha = np.zeros((data_size * 2)) + alpha = np.zeros(data_size * 2) data_abs = np.abs(input_data) alpha[:data_size] = (self.beta * extra_factor) / ( data_abs + sys.float_info.epsilon @@ -1227,7 +1226,7 @@ def _op_method(self, input_data, extra_factor=1.0): if self._k_value > k_max: warn( "K value of the K-support norm is greater than the input " - + "dimension, its value will be set to {0}".format(k_max), + + f"dimension, its value will be set to {k_max}", ) self._k_value = k_max @@ -1333,7 +1332,7 @@ def _cost_method(self, *args, **kwargs): + np.sum(data_abs[q_val:]) ** 2 / (self._k_value - q_val) ) * self.beta - if "verbose" in kwargs and kwargs["verbose"]: + if kwargs.get("verbose"): print(" - K-SUPPORT NORM (X):", cost_val) return cost_val diff --git a/modopt/opt/reweight.py b/modopt/opt/reweight.py index 7ff9aac4..8d120101 100644 --- a/modopt/opt/reweight.py +++ b/modopt/opt/reweight.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """REWEIGHTING CLASSES. @@ -13,7 +12,7 @@ from modopt.base.types import check_float -class cwbReweight(object): +class cwbReweight: """Candes, Wakin and Boyd reweighting class. This class implements the reweighting scheme described in @@ -81,7 +80,7 @@ def reweight(self, input_data): """ if self.verbose: - print(" - Reweighting: {0}".format(self._rw_num)) + print(f" - Reweighting: {self._rw_num}") self._rw_num += 1 diff --git a/modopt/plot/__init__.py b/modopt/plot/__init__.py index da6e096c..f6b39978 100644 --- a/modopt/plot/__init__.py +++ b/modopt/plot/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """PLOTTING ROUTINES. diff --git a/modopt/plot/cost_plot.py b/modopt/plot/cost_plot.py index 36958450..2274f35d 100644 --- a/modopt/plot/cost_plot.py +++ b/modopt/plot/cost_plot.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """PLOTTING ROUTINES. @@ -43,7 +42,7 @@ def plotCost(cost_list, output=None): if isinstance(output, type(None)): file_name = "cost_function.png" else: - file_name = "{0}_cost_function.png".format(output) + file_name = f"{output}_cost_function.png" plt.figure() plt.plot(np.log10(cost_list), "r-") diff --git a/modopt/signal/__init__.py b/modopt/signal/__init__.py index 09b2d2c4..2aee1987 100644 --- a/modopt/signal/__init__.py +++ b/modopt/signal/__init__.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """SIGNAL PROCESSING ROUTINES. diff --git a/modopt/signal/filter.py b/modopt/signal/filter.py index 2c7d8626..0e50d28f 100644 --- a/modopt/signal/filter.py +++ b/modopt/signal/filter.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """FILTER ROUTINES. diff --git a/modopt/signal/noise.py b/modopt/signal/noise.py index fadf5308..b43a0b61 100644 --- a/modopt/signal/noise.py +++ b/modopt/signal/noise.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """NOISE ROUTINES. @@ -8,7 +7,6 @@ """ -from builtins import zip import numpy as np diff --git a/modopt/signal/positivity.py b/modopt/signal/positivity.py index 5c4b795b..f3f312d3 100644 --- a/modopt/signal/positivity.py +++ b/modopt/signal/positivity.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """POSITIVITY. diff --git a/modopt/signal/svd.py b/modopt/signal/svd.py index cc204817..dd080306 100644 --- a/modopt/signal/svd.py +++ b/modopt/signal/svd.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """SVD ROUTINES. diff --git a/modopt/signal/wavelet.py b/modopt/signal/wavelet.py index 72d608e7..d624db3a 100644 --- a/modopt/signal/wavelet.py +++ b/modopt/signal/wavelet.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """WAVELET MODULE. @@ -141,9 +140,9 @@ def call_mr_transform( unique_string = datetime.now().strftime("%Y.%m.%d_%H.%M.%S") + str(getrandbits(128)) # Set the ouput file names. - file_name = "{0}mr_temp_{1}".format(path, unique_string) - file_fits = "{0}.fits".format(file_name) - file_mr = "{0}.mr".format(file_name) + file_name = f"{path}mr_temp_{unique_string}" + file_fits = f"{file_name}.fits" + file_mr = f"{file_name}.mr" # Write the input data to a fits file. fits.writeto(file_fits, input_data) @@ -152,7 +151,7 @@ def call_mr_transform( opt = opt.split() # Prepare command and execute it - command_line = " ".join([executable] + opt + [file_fits, file_mr]) + command_line = " ".join([executable, *opt, file_fits, file_mr]) stdout, _ = execute(command_line) # Check for errors diff --git a/modopt/tests/test_algorithms.py b/modopt/tests/test_algorithms.py index ca0cd666..c1e676a5 100644 --- a/modopt/tests/test_algorithms.py +++ b/modopt/tests/test_algorithms.py @@ -1,4 +1,3 @@ -# -*- coding: utf-8 -*- """UNIT TESTS FOR Algorithms. @@ -11,18 +10,13 @@ import numpy as np import numpy.testing as npt -import pytest from modopt.opt import algorithms, cost, gradient, linear, proximity, reweight from pytest_cases import ( - case, fixture, - fixture_ref, - lazy_value, parametrize, parametrize_with_cases, ) -from test_helpers import Dummy SKLEARN_AVAILABLE = True try: @@ -80,7 +74,7 @@ def build_kwargs(kwargs, use_metrics): @parametrize(use_metrics=[True, False]) class AlgoCases: - """Cases for algorithms. + r"""Cases for algorithms. Most of the test solves the trivial problem diff --git a/modopt/tests/test_helpers/__init__.py b/modopt/tests/test_helpers/__init__.py index 3886b877..e69de29b 100644 --- a/modopt/tests/test_helpers/__init__.py +++ b/modopt/tests/test_helpers/__init__.py @@ -1 +0,0 @@ -from .utils import failparam, skipparam, Dummy diff --git a/modopt/tests/test_opt.py b/modopt/tests/test_opt.py index e77074ab..7dc27871 100644 --- a/modopt/tests/test_opt.py +++ b/modopt/tests/test_opt.py @@ -37,10 +37,14 @@ PYWT_AVAILABLE = False # Basic functions to be used as operators or as dummy functions -func_identity = lambda x_val: x_val -func_double = lambda x_val: x_val * 2 -func_sq = lambda x_val: x_val**2 -func_cube = lambda x_val: x_val**3 +def func_identity(x_val): + return x_val +def func_double(x_val): + return x_val * 2 +def func_sq(x_val): + return x_val ** 2 +def func_cube(x_val): + return x_val ** 3 @case(tags="cost") diff --git a/modopt/tests/test_signal.py b/modopt/tests/test_signal.py index b3787fc6..cdd95277 100644 --- a/modopt/tests/test_signal.py +++ b/modopt/tests/test_signal.py @@ -16,7 +16,7 @@ class TestFilter: - """Test filter module""" + """Test filter module.""" @pytest.mark.parametrize( ("norm", "result"), [(True, 0.24197072451914337), (False, 0.60653065971263342)]