diff --git a/src/pyoperators/__init__.py b/src/pyoperators/__init__.py index b8a464d..1eb2720 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 d08acdc..46b7f47 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 7db2a2c..c681e0f 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 fec0895..33d8862 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 6926a64..1c17e4b 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 c6c6f56..c2f35e3 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 f37d9ea..ed564a3 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 bc07e07..d8eed45 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 ebcde4a..c88c236 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 edd31f7..8bef7e6 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 )