From fab6cb17434e02d4652a25d334ca89d842f63846 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Apr 2024 16:22:32 +0000 Subject: [PATCH] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/pyoperators/__init__.py | 1 + src/pyoperators/core.py | 39 +++++++++++++-------- src/pyoperators/flags.py | 1 + src/pyoperators/iterative/algorithms.py | 1 + src/pyoperators/iterative/dli.py | 1 + src/pyoperators/iterative/linesearch.py | 1 + src/pyoperators/iterative/optimize.py | 1 + src/pyoperators/iterative/stopconditions.py | 1 - src/pyoperators/utils/fake_MPI.py | 1 + src/pyoperators/utils/misc.py | 10 +++--- 10 files changed, 36 insertions(+), 21 deletions(-) diff --git a/src/pyoperators/__init__.py b/src/pyoperators/__init__.py index b8a464df..1eb27202 100644 --- a/src/pyoperators/__init__.py +++ b/src/pyoperators/__init__.py @@ -10,6 +10,7 @@ - operators_pywt : (optional) loaded if PyWavelets is present. """ + from importlib.metadata import version as _version from .core import ( diff --git a/src/pyoperators/core.py b/src/pyoperators/core.py index d08acdcb..46b7f473 100644 --- a/src/pyoperators/core.py +++ b/src/pyoperators/core.py @@ -3,6 +3,7 @@ which can be added, composed or multiplied by a scalar. See the Operator docstring for more information. """ + from __future__ import annotations import inspect @@ -1233,16 +1234,20 @@ def _init_inout( flag_is = ( 'explicit' if self.shapein is not None - else 'implicit' - if self.reshapeout != Operator.reshapeout.__get__(self, type(self)) - else 'unconstrained' + else ( + 'implicit' + if self.reshapeout != Operator.reshapeout.__get__(self, type(self)) + else 'unconstrained' + ) ) flag_os = ( 'explicit' if self.shapeout is not None - else 'implicit' - if self.reshapein != Operator.reshapein.__get__(self, type(self)) - else 'unconstrained' + else ( + 'implicit' + if self.reshapein != Operator.reshapein.__get__(self, type(self)) + else 'unconstrained' + ) ) self._set_flags(shape_input=flag_is, shape_output=flag_os) @@ -1779,9 +1784,11 @@ def __str__(self): # parentheses for AdditionOperator and BlockDiagonalOperator operands = [ - f'({o})' - if isinstance(o, (AdditionOperator, BlockDiagonalOperator)) - else str(o) + ( + f'({o})' + if isinstance(o, (AdditionOperator, BlockDiagonalOperator)) + else str(o) + ) for o in self.operands ] @@ -2440,9 +2447,11 @@ def _apply_rule_homothety(self, operands): """ return sum( ( - self._apply_rule_homothety_linear(list(group)) - if islinear - else list(group) + ( + self._apply_rule_homothety_linear(list(group)) + if islinear + else list(group) + ) for islinear, group in groupby(operands, lambda o: o.flags.linear) ), [], @@ -3470,9 +3479,9 @@ def _validate_partition_composition(op1, op2): ) ) - return None if pout is None else merge_none( - op1.partitionout, pout - ), None if pin is None else merge_none(op2.partitionin, pin) + return None if pout is None else merge_none(op1.partitionout, pout), ( + None if pin is None else merge_none(op2.partitionin, pin) + ) @staticmethod def _rule_operator_commutative(self, op, cls): diff --git a/src/pyoperators/flags.py b/src/pyoperators/flags.py index 7db2a2cb..c681e0f7 100644 --- a/src/pyoperators/flags.py +++ b/src/pyoperators/flags.py @@ -4,6 +4,7 @@ linear, square etc. """ + from collections import namedtuple diff --git a/src/pyoperators/iterative/algorithms.py b/src/pyoperators/iterative/algorithms.py index fec0895c..33d8862a 100644 --- a/src/pyoperators/iterative/algorithms.py +++ b/src/pyoperators/iterative/algorithms.py @@ -1,6 +1,7 @@ """ Implements iterative algorithm class. """ + from copy import copy import numpy as np diff --git a/src/pyoperators/iterative/dli.py b/src/pyoperators/iterative/dli.py index 6926a646..1c17e4b1 100644 --- a/src/pyoperators/iterative/dli.py +++ b/src/pyoperators/iterative/dli.py @@ -10,6 +10,7 @@ http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.165.8284&rep=rep1&type=pdf """ + from copy import copy import numpy as np diff --git a/src/pyoperators/iterative/linesearch.py b/src/pyoperators/iterative/linesearch.py index c6c6f566..c2f35e3b 100644 --- a/src/pyoperators/iterative/linesearch.py +++ b/src/pyoperators/iterative/linesearch.py @@ -15,6 +15,7 @@ - LineSearch, LineSearchArmijo, LineSearchWolfe1; LineSearchWolfe2 """ + import numpy as np from .criterions import Norm2 diff --git a/src/pyoperators/iterative/optimize.py b/src/pyoperators/iterative/optimize.py index f37d9ea0..ed564a3d 100644 --- a/src/pyoperators/iterative/optimize.py +++ b/src/pyoperators/iterative/optimize.py @@ -1,6 +1,7 @@ """ Wraps scipy.optimize.fmin_* algorithms using Criterion instances. """ + import numpy as np import scipy.optimize as opt diff --git a/src/pyoperators/iterative/stopconditions.py b/src/pyoperators/iterative/stopconditions.py index bc07e077..d8eed45d 100644 --- a/src/pyoperators/iterative/stopconditions.py +++ b/src/pyoperators/iterative/stopconditions.py @@ -3,7 +3,6 @@ """ - __all__ = ['StopCondition', 'MaxErrorStopCondition', 'MaxIterationStopCondition'] diff --git a/src/pyoperators/utils/fake_MPI.py b/src/pyoperators/utils/fake_MPI.py index ebcde4aa..c88c2364 100644 --- a/src/pyoperators/utils/fake_MPI.py +++ b/src/pyoperators/utils/fake_MPI.py @@ -1,6 +1,7 @@ """ MPI-wrapper module for non-MPI enabled platforms. """ + import builtins as _builtins from itertools import count as _count diff --git a/src/pyoperators/utils/misc.py b/src/pyoperators/utils/misc.py index edd31f7c..8bef7e69 100644 --- a/src/pyoperators/utils/misc.py +++ b/src/pyoperators/utils/misc.py @@ -1208,11 +1208,11 @@ def zip_broadcast(*args, **keywords): raise TypeError('Invalid keyword(s).') iter_str = keywords.get('iter_str', True) n = max( - 1 - if not isinstance(_, Iterable) or isinstance(_, str) and not iter_str - else len(_) - if hasattr(_, '__len__') - else sys.maxsize + ( + 1 + if not isinstance(_, Iterable) or isinstance(_, str) and not iter_str + else len(_) if hasattr(_, '__len__') else sys.maxsize + ) for _ in args )