diff options
author | epapoutsellis <epapoutsellis@gmail.com> | 2019-04-12 12:49:06 +0100 |
---|---|---|
committer | epapoutsellis <epapoutsellis@gmail.com> | 2019-04-12 12:49:06 +0100 |
commit | 7a019f3ccf4d19181ffb5dc5a92d3096cab4b12b (patch) | |
tree | f2071d93cc883e2c26d4924aa7b70b7a974b83dd /Wrappers | |
parent | 3c83e80c7a22817c49ad39da07e061f25dd3ac70 (diff) | |
download | framework-7a019f3ccf4d19181ffb5dc5a92d3096cab4b12b.tar.gz framework-7a019f3ccf4d19181ffb5dc5a92d3096cab4b12b.tar.bz2 framework-7a019f3ccf4d19181ffb5dc5a92d3096cab4b12b.tar.xz framework-7a019f3ccf4d19181ffb5dc5a92d3096cab4b12b.zip |
memopt fixes
Diffstat (limited to 'Wrappers')
5 files changed, 28 insertions, 56 deletions
diff --git a/Wrappers/Python/ccpi/framework/BlockDataContainer.py b/Wrappers/Python/ccpi/framework/BlockDataContainer.py index 9bec1fe..f1d6d9a 100755 --- a/Wrappers/Python/ccpi/framework/BlockDataContainer.py +++ b/Wrappers/Python/ccpi/framework/BlockDataContainer.py @@ -78,9 +78,13 @@ class BlockDataContainer(object): a = el.is_compatible(other)
else:
a = el.shape == other.shape
+# print ("current element" , el.shape, "other ", other.shape, "same shape" , a)
ret = ret and a
return ret
-
+
+
+# elif issubclass(other.__class__, DataContainer):
+# return self.get_item(0).shape == other.shape
return len(self.containers) == len(other.containers)
def get_item(self, row):
@@ -350,32 +354,3 @@ class BlockDataContainer(object): '''Inline truedivision'''
return self.__idiv__(other)
-if __name__ == '__main__':
-
- M, N, K = 2,3,5
- from ccpi.framework import ImageGeometry, BlockGeometry
-
- ig = ImageGeometry(N, M)
- u = ig.allocate('random_int')
-
- BG = BlockGeometry(ig, ig)
- U = BG.allocate('random_int')
-
- U_nested = BlockDataContainer(BlockDataContainer(u, u), u)
-
-
- res1 = U + u
- res2 = U_nested + u
-# res2 = u + U
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file diff --git a/Wrappers/Python/ccpi/optimisation/functions/BlockFunction.py b/Wrappers/Python/ccpi/optimisation/functions/BlockFunction.py index 9917d99..8cce290 100644 --- a/Wrappers/Python/ccpi/optimisation/functions/BlockFunction.py +++ b/Wrappers/Python/ccpi/optimisation/functions/BlockFunction.py @@ -7,7 +7,7 @@ Created on Fri Mar 8 10:01:31 2019 """ import numpy as np -#from ccpi.optimisation.funcs import Function + from ccpi.optimisation.functions import Function from ccpi.framework import BlockDataContainer from numbers import Number diff --git a/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py b/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py index 9e0e424..9508c13 100644 --- a/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py +++ b/Wrappers/Python/ccpi/optimisation/functions/L2NormSquared.py @@ -20,38 +20,36 @@ import numpy from ccpi.optimisation.functions import Function from ccpi.optimisation.functions.ScaledFunction import ScaledFunction -from ccpi.framework import DataContainer, ImageData, ImageGeometry -############################ L2NORM FUNCTION ############################# class L2NormSquared(Function): - def __init__(self, **kwargs): - - ''' L2NormSquared class - f : ImageGeometry --> R - - Cases: f(x) = ||x||^{2}_{2} - f(x) = || x - b ||^{2}_{2} - - ''' + ''' + + Class: L2NormSquared - #TODO need x, b to live in the same geometry if b is not None - + Cases: a) f(x) = ||x||^{2} + + b) f(x) = ||x - b||^{2}, b + + ''' + + def __init__(self, **kwargs): + super(L2NormSquared, self).__init__() self.b = kwargs.get('b',None) def __call__(self, x): - ''' Evaluates L2NormSq at point x''' + """ + + Evaluate L2NormSquared at x: f(x) + + + """ + y = x if self.b is not None: -# x.subtract(self.b, out = x) y = x - self.b -# else: -# y -# if out is None: -# return x.squared_norm() -# else: try: return y.squared_norm() except AttributeError as ae: @@ -61,6 +59,8 @@ class L2NormSquared(Function): def gradient(self, x, out=None): + + ''' Evaluates gradient of L2NormSq at point x''' if out is not None: out.fill(x) diff --git a/Wrappers/Python/ccpi/optimisation/functions/MixedL21Norm.py b/Wrappers/Python/ccpi/optimisation/functions/MixedL21Norm.py index 0c658a4..0c7eb85 100755 --- a/Wrappers/Python/ccpi/optimisation/functions/MixedL21Norm.py +++ b/Wrappers/Python/ccpi/optimisation/functions/MixedL21Norm.py @@ -102,9 +102,6 @@ class MixedL21Norm(Function): res = (sum(x**2).sqrt()).maximum(1.0) out.fill(x/res) - - - def __rmul__(self, scalar): return ScaledFunction(self, scalar) diff --git a/Wrappers/Python/wip/pdhg_TV_denoising.py b/Wrappers/Python/wip/pdhg_TV_denoising.py index 22fee90..f276b46 100755 --- a/Wrappers/Python/wip/pdhg_TV_denoising.py +++ b/Wrappers/Python/wip/pdhg_TV_denoising.py @@ -90,8 +90,8 @@ print ("normK", normK) sigma = 1 tau = 1/(sigma*normK**2) -opt = {'niter':100} -opt1 = {'niter':100, 'memopt': True} +opt = {'niter':1000} +opt1 = {'niter':1000, 'memopt': True} t1 = timer() res, time, primal, dual, pdgap = PDHG_old(f, g, operator, tau = tau, sigma = sigma, opt = opt) |