diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2019-04-12 14:54:09 +0100 |
---|---|---|
committer | Edoardo Pasca <edo.paskino@gmail.com> | 2019-04-12 14:54:09 +0100 |
commit | 9ede79fb417bdbbb21e94045af16d62c366e35ee (patch) | |
tree | 76316c4960336f405754a3e883ad0fa76e568740 | |
parent | f801c708fe73ce68cdeabac86f9dddfab309279f (diff) | |
download | framework-9ede79fb417bdbbb21e94045af16d62c366e35ee.tar.gz framework-9ede79fb417bdbbb21e94045af16d62c366e35ee.tar.bz2 framework-9ede79fb417bdbbb21e94045af16d62c366e35ee.tar.xz framework-9ede79fb417bdbbb21e94045af16d62c366e35ee.zip |
added docstrings
-rwxr-xr-x | Wrappers/Python/ccpi/framework/BlockDataContainer.py | 95 |
1 files changed, 28 insertions, 67 deletions
diff --git a/Wrappers/Python/ccpi/framework/BlockDataContainer.py b/Wrappers/Python/ccpi/framework/BlockDataContainer.py index 060b130..20efbc3 100755 --- a/Wrappers/Python/ccpi/framework/BlockDataContainer.py +++ b/Wrappers/Python/ccpi/framework/BlockDataContainer.py @@ -112,92 +112,45 @@ class BlockDataContainer(object): def __getitem__(self, row): return self.get_item(row) -# def add(self, other, *args, **kwargs): -# if not self.is_compatible(other): -# raise ValueError('Incompatible for add') -# out = kwargs.get('out', None) -# #print ("args" , *args) -# if isinstance(other, Number): -# return type(self)(*[ el.add(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# elif isinstance(other, list) or isinstance(other, numpy.ndarray): -# return type(self)(*[ el.add(ot, *args, **kwargs) for el,ot in zip(self.containers,other)], shape=self.shape) -# elif issubclass(other.__class__, DataContainer): -# # try to do algebra with one DataContainer. Will raise error if not compatible -# return type(self)(*[ el.add(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# -# return type(self)( -# *[ el.add(ot, *args, **kwargs) for el,ot in zip(self.containers,other.containers)], -# shape=self.shape) -# -# def subtract(self, other, *args, **kwargs): -# if not self.is_compatible(other): -# raise ValueError('Incompatible for subtract') -# out = kwargs.get('out', None) -# if isinstance(other, Number): -# return type(self)(*[ el.subtract(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# elif isinstance(other, list) or isinstance(other, numpy.ndarray): -# return type(self)(*[ el.subtract(ot, *args, **kwargs) for el,ot in zip(self.containers,other)], shape=self.shape) -# elif issubclass(other.__class__, DataContainer): -# # try to do algebra with one DataContainer. Will raise error if not compatible -# return type(self)(*[ el.subtract(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# return type(self)(*[ el.subtract(ot, *args, **kwargs) for el,ot in zip(self.containers,other.containers)], -# shape=self.shape) -# -# def multiply(self, other, *args, **kwargs): -# if not self.is_compatible(other): -# raise ValueError('{} Incompatible for multiply'.format(other)) -# out = kwargs.get('out', None) -# if isinstance(other, Number): -# return type(self)(*[ el.multiply(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# elif isinstance(other, list): -# return type(self)(*[ el.multiply(ot, *args, **kwargs) for el,ot in zip(self.containers,other)], shape=self.shape) -# elif isinstance(other, numpy.ndarray): -# return type(self)(*[ el.multiply(ot, *args, **kwargs) for el,ot in zip(self.containers,other)], shape=self.shape) -# elif issubclass(other.__class__, DataContainer): -# # try to do algebra with one DataContainer. Will raise error if not compatible -# return type(self)(*[ el.multiply(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# return type(self)(*[ el.multiply(ot, *args, **kwargs) for el,ot in zip(self.containers,other.containers)], -# shape=self.shape) -# -# def divide_old(self, other, *args, **kwargs): -# if not self.is_compatible(other): -# raise ValueError('Incompatible for divide') -# out = kwargs.get('out', None) -# if isinstance(other, Number): -# return type(self)(*[ el.divide(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# elif isinstance(other, list) or isinstance(other, numpy.ndarray): -# return type(self)(*[ el.divide(ot, *args, **kwargs) for el,ot in zip(self.containers,other)], shape=self.shape) -# elif issubclass(other.__class__, DataContainer): -# # try to do algebra with one DataContainer. Will raise error if not compatible -# if out is not None: -# kw = kwargs.copy() -# for i,el in enumerate(self.containers): -# kw['out'] = out.get_item(i) -# el.divide(other, *args, **kw) -# return -# else: -# return type(self)(*[ el.divide(other, *args, **kwargs) for el in self.containers], shape=self.shape) -# return type(self)(*[ el.divide(ot, *args, **kwargs) for el,ot in zip(self.containers,other.containers)], -# shape=self.shape) def add(self, other, *args, **kwargs): + '''Algebra: add method of BlockDataContainer with number/DataContainer or BlockDataContainer + + :param: other (number, DataContainer or subclasses or BlockDataContainer + :param: out (optional): provides a placehold for the resul. + ''' out = kwargs.get('out', None) if out is not None: self.binary_operations(BlockDataContainer.ADD, other, *args, **kwargs) else: return self.binary_operations(BlockDataContainer.ADD, other, *args, **kwargs) def subtract(self, other, *args, **kwargs): + '''Algebra: subtract method of BlockDataContainer with number/DataContainer or BlockDataContainer + + :param: other (number, DataContainer or subclasses or BlockDataContainer + :param: out (optional): provides a placehold for the resul. + ''' out = kwargs.get('out', None) if out is not None: self.binary_operations(BlockDataContainer.SUBTRACT, other, *args, **kwargs) else: return self.binary_operations(BlockDataContainer.SUBTRACT, other, *args, **kwargs) def multiply(self, other, *args, **kwargs): + '''Algebra: multiply method of BlockDataContainer with number/DataContainer or BlockDataContainer + + :param: other (number, DataContainer or subclasses or BlockDataContainer + :param: out (optional): provides a placehold for the resul. + ''' out = kwargs.get('out', None) if out is not None: self.binary_operations(BlockDataContainer.MULTIPLY, other, *args, **kwargs) else: return self.binary_operations(BlockDataContainer.MULTIPLY, other, *args, **kwargs) def divide(self, other, *args, **kwargs): + '''Algebra: divide method of BlockDataContainer with number/DataContainer or BlockDataContainer + + :param: other (number, DataContainer or subclasses or BlockDataContainer + :param: out (optional): provides a placehold for the resul. + ''' out = kwargs.get('out', None) if out is not None: self.binary_operations(BlockDataContainer.DIVIDE, other, *args, **kwargs) @@ -206,6 +159,14 @@ class BlockDataContainer(object): def binary_operations(self, operation, other, *args, **kwargs): + '''Algebra: generic method of algebric operation with BlockDataContainer with number/DataContainer or BlockDataContainer + + Provides commutativity with DataContainer and subclasses, i.e. this + class's reverse algebric methods take precedence w.r.t. direct algebric + methods of DataContainer and subclasses. + + This method is not to be used directly + ''' if not self.is_compatible(other): raise ValueError('Incompatible for divide') out = kwargs.get('out', None) |