Skip to content

Commit 3ae8c82

Browse files
authored
bug: fix precomposition allowed types for b (#178)
All b to be of float and np.ndarray type
1 parent 0389c77 commit 3ae8c82

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

.readthedocs.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ build:
1010
os: ubuntu-20.04
1111
tools:
1212
python: "3.9"
13-
apt_packages:
14-
- libopenblas-dev
1513

1614
# Build documentation in the docs/ directory with Sphinx
1715
sphinx:

environment-dev.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ dependencies:
1717
- numba
1818
- icc_rt
1919
- pip:
20-
- bm3d
20+
- bm4d<4.2.4 # temporary as gclib problem arises in readthedocs
21+
- bm3d<4.0.2 # temporary as gclib problem arises in readthedocs
2122
- pytest-runner
2223
- setuptools_scm
2324
- pydata-sphinx-theme

pyproximal/ProxOperator.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,16 @@ def _proxdual_moreau(self, x, tau, **kwargs):
7373
def prox(self, x, tau, **kwargs):
7474
"""Proximal operator applied to a vector
7575
76-
The proximal operator can always be computed given its dual
76+
The proximal operator can always be computed given its dual
7777
proximal operator using the Moreau decomposition as defined in
78-
:func:`pyprox.moreau`. For this reason we can easily create a common
78+
:func:`pyproximal.moreau`. For this reason we can easily create a common
7979
method for all proximal operators that can be evaluated provided the
8080
dual proximal is implemented.
8181
8282
However, direct implementations are generally available. This can
8383
be done by simply implementing ``prox`` for a specific proximal
8484
operator, which will overwrite the general method.
8585
86-
8786
Parameters
8887
----------
8988
x : :obj:`np.ndarray`
@@ -100,9 +99,9 @@ def proxdual(self, x, tau, **kwargs):
10099
101100
The dual of a proximal operator can always be computed given its
102101
proximal operator using the Moreau decomposition as defined in
103-
:func:`pyprox.moreau`. For this reason we can easily create a common
102+
:func:`pyproximal.moreau`. For this reason we can easily create a common
104103
method for all dual proximal operators that can be evaluated provided
105-
he proximal is implemented.
104+
the proximal is implemented.
106105
107106
However, since the dual of a proximal operator of a function is
108107
equivalent to the proximal operator of the conjugate function, smarter
@@ -163,7 +162,7 @@ def affine_addition(self, v):
163162
if isinstance(v, np.ndarray):
164163
return _SumOperator(self, v)
165164
else:
166-
return NotImplemented
165+
raise NotImplementedError('v must be of type numpy.ndarray')
167166

168167
def postcomposition(self, sigma):
169168
r"""Postcomposition
@@ -191,7 +190,7 @@ def postcomposition(self, sigma):
191190
if isinstance(sigma, float):
192191
return _PostcompositionOperator(self, sigma)
193192
else:
194-
return NotImplemented
193+
raise NotImplementedError('sigma must be of type float')
195194

196195
def precomposition(self, a, b):
197196
r"""Precomposition
@@ -217,10 +216,12 @@ def precomposition(self, a, b):
217216
prox_{a^2 \tau f} (a \mathbf{x} + b) - b)
218217
219218
"""
220-
if isinstance(a, float) and isinstance(b, float):
219+
if isinstance(a, float) and isinstance(b, (float, np.ndarray)):
221220
return _PrecompositionOperator(self, a, b)
222221
else:
223-
return NotImplemented
222+
raise NotImplementedError('a must be of type float and b '
223+
'must be of type float or '
224+
'numpy.ndarray')
224225

225226
def chain(self, g):
226227
r"""Chain
@@ -347,7 +348,7 @@ def __init__(self, f, a, b):
347348
# raise ValueError('First input must be a ProxOperator')
348349
if not isinstance(a, float):
349350
raise ValueError('Second input must be a float')
350-
if not isinstance(b, float):
351+
if not isinstance(b, (float, np.ndarray)):
351352
raise ValueError('Second input must be a float')
352353
self.f, self.a, self.b = f, a, b
353354
super().__init__(None, True if f.grad else False)

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ numba
55
scikit-image
66
matplotlib
77
ipython
8-
bm3d
8+
bm4d<4.2.4 # temporary as gclib problem arises in readthedocs
9+
bm3d<4.0.2 # temporary as gclib problem arises in readthedocs
910
pytest
1011
pytest-runner
1112
setuptools_scm

0 commit comments

Comments
 (0)