diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2019-03-06 11:18:10 -0500 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2019-03-06 11:18:10 -0500 |
commit | 604f5ce166838defe9d3df3b936830b5b96a1fe1 (patch) | |
tree | d86bc2732ae14e7310ddcf443df888c66768ccd3 /Wrappers | |
parent | d6d63f9f10f8eccee1a4cacf76d9d2de1ea93377 (diff) | |
download | framework-604f5ce166838defe9d3df3b936830b5b96a1fe1.tar.gz framework-604f5ce166838defe9d3df3b936830b5b96a1fe1.tar.bz2 framework-604f5ce166838defe9d3df3b936830b5b96a1fe1.tar.xz framework-604f5ce166838defe9d3df3b936830b5b96a1fe1.zip |
fixed tests and py27 quirks
Diffstat (limited to 'Wrappers')
4 files changed, 38 insertions, 18 deletions
diff --git a/Wrappers/Python/ccpi/framework/BlockDataContainer.py b/Wrappers/Python/ccpi/framework/BlockDataContainer.py index 5f24e5c..1bfc98c 100755 --- a/Wrappers/Python/ccpi/framework/BlockDataContainer.py +++ b/Wrappers/Python/ccpi/framework/BlockDataContainer.py @@ -23,7 +23,6 @@ class BlockDataContainer(object): self.containers = args
self.index = 0
shape = kwargs.get('shape', None)
- print (shape)
if shape is None:
shape = (len(args),1)
self.shape = shape
@@ -151,8 +150,7 @@ class BlockDataContainer(object): y = numpy.asarray([el.squared_norm() for el in self.containers])
return y.sum()
def norm(self):
- y = numpy.asarray([el.norm() for el in self.containers])
- return y.sum()
+ return numpy.sqrt(self.squared_norm())
def copy(self):
'''alias of clone'''
return self.clone()
@@ -299,4 +297,4 @@ class BlockDataContainer(object): def __itruediv__(self, other):
'''Inline truedivision'''
return self.__idiv__(other)
-
\ No newline at end of file +
diff --git a/Wrappers/Python/ccpi/framework/framework.py b/Wrappers/Python/ccpi/framework/framework.py index d77db4a..09fa320 100755 --- a/Wrappers/Python/ccpi/framework/framework.py +++ b/Wrappers/Python/ccpi/framework/framework.py @@ -652,7 +652,8 @@ class DataContainer(object): elif issubclass(type(out), DataContainer) and issubclass(type(x2), DataContainer): if self.check_dimensions(out) and self.check_dimensions(x2): - pwop(self.as_array(), x2.as_array(), out=out.as_array(), *args, **kwargs ) + kwargs['out'] = out.as_array() + pwop(self.as_array(), x2.as_array(), *args, **kwargs ) #return type(self)(out.as_array(), # deep_copy=False, # dimension_labels=self.dimension_labels, @@ -662,14 +663,15 @@ class DataContainer(object): raise ValueError(message(type(self),"Wrong size for data memory: ", out.shape,self.shape)) elif issubclass(type(out), DataContainer) and isinstance(x2, (int,float,complex)): if self.check_dimensions(out): - - pwop(self.as_array(), x2, out=out.as_array(), *args, **kwargs ) + kwargs['out']=out.as_array() + pwop(self.as_array(), x2, *args, **kwargs ) return out else: raise ValueError(message(type(self),"Wrong size for data memory: ", out.shape,self.shape)) elif issubclass(type(out), numpy.ndarray): if self.array.shape == out.shape and self.array.dtype == out.dtype: - pwop(self.as_array(), x2 , out=out, *args, **kwargs) + kwargs['out'] = out + pwop(self.as_array(), x2, *args, **kwargs) #return type(self)(out, # deep_copy=False, # dimension_labels=self.dimension_labels, @@ -693,7 +695,7 @@ class DataContainer(object): return self.pixel_wise_binary(numpy.power, other, *args, **kwargs) def maximum(self, x2, *args, **kwargs): - return self.pixel_wise_binary(numpy.maximum, x2=x2, *args, **kwargs) + return self.pixel_wise_binary(numpy.maximum, x2, *args, **kwargs) ## unary operations def pixel_wise_unary(self, pwop, *args, **kwargs): @@ -706,12 +708,14 @@ class DataContainer(object): geometry=self.geometry) elif issubclass(type(out), DataContainer): if self.check_dimensions(out): - pwop(self.as_array(), out=out.as_array(), *args, **kwargs ) + kwargs['out'] = out.as_array() + pwop(self.as_array(), *args, **kwargs ) else: raise ValueError(message(type(self),"Wrong size for data memory: ", out.shape,self.shape)) elif issubclass(type(out), numpy.ndarray): if self.array.shape == out.shape and self.array.dtype == out.dtype: - pwop(self.as_array(), out=out, *args, **kwargs) + kwargs['out'] = out + pwop(self.as_array(), *args, **kwargs) else: raise ValueError (message(type(self), "incompatible class:" , pwop.__name__, type(out))) diff --git a/Wrappers/Python/ccpi/optimisation/operators/BlockOperator.py b/Wrappers/Python/ccpi/optimisation/operators/BlockOperator.py index 145277f..4bbc536 100755 --- a/Wrappers/Python/ccpi/optimisation/operators/BlockOperator.py +++ b/Wrappers/Python/ccpi/optimisation/operators/BlockOperator.py @@ -14,9 +14,27 @@ from ccpi.optimisation.operators import Operator, LinearOperator class BlockOperator(Operator): - '''Class to hold a block operator''' - def __init__(self, *args, shape=None): + '''Class to hold a block operator + + Class to hold a number of Operators in a block. + User may specify the shape of the block, by default is a row vector + ''' + def __init__(self, *args, **kwargs): + ''' + Class creator + + Note: + Do not include the `self` parameter in the ``Args`` section. + + Args: + vararg (Operator): Operators in the block. varargs are passed in a + row-by-row fashion. + shape (:obj:`tuple`, optional): If passed the Operators listed + in the vararg are laid out as described. Shape and number + of Operators must match. + ''' self.operators = args + shape = kwargs.get('shape', None) if shape is None: shape = (len(args),1) self.shape = shape @@ -61,9 +79,9 @@ class BlockOperator(Operator): for row in range(self.shape[1]): for col in range(self.shape[0]): if col == 0: - prod = self.get_item(row,col).adjoint(x.get_item(col)) + prod = self.get_item(col,row).adjoint(x.get_item(row)) else: - prod += self.get_item(row,col).adjoint(x.get_item(col)) + prod += self.get_item(col,row).adjoint(x.get_item(row)) res.append(prod) return BlockDataContainer(*res, shape=shape) @@ -467,4 +485,4 @@ if __name__ == '__main__': plt.subplot(1,5,5) plt.imshow(cgsmall.get_output().get_item(0,0).subset(vertical=0).as_array()) plt.title('Composite CGLS\nsmall lambda') - plt.show()
\ No newline at end of file + plt.show() diff --git a/Wrappers/Python/test/test_DataContainer.py b/Wrappers/Python/test/test_DataContainer.py index 05f3fe8..3ce2dac 100755 --- a/Wrappers/Python/test/test_DataContainer.py +++ b/Wrappers/Python/test/test_DataContainer.py @@ -174,7 +174,7 @@ class TestDataContainer(unittest.TestCase): def binary_add(self): print("Test binary add") X, Y, Z = 512, 512, 512 - X, Y, Z = 256, 512, 512 + X, Y, Z = 1024, 512, 512 steps = [timer()] a = numpy.ones((X, Y, Z), dtype='float32') steps.append(timer()) @@ -496,4 +496,4 @@ class TestDataContainer(unittest.TestCase): if __name__ == '__main__': unittest.main() -
\ No newline at end of file + |