diff options
author | Edoardo Pasca <edo.paskino@gmail.com> | 2019-10-11 20:22:23 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-11 20:22:23 +0100 |
commit | 82ea0b9aa83affdac19ceaf6bf800b690934bb07 (patch) | |
tree | ea1bd17d8f98877ec295384a4b430785e2eb8800 /Wrappers/Python | |
parent | c7213fdfcd31e6ec780aab4afe1bd34374d784f5 (diff) | |
download | framework-82ea0b9aa83affdac19ceaf6bf800b690934bb07.tar.gz framework-82ea0b9aa83affdac19ceaf6bf800b690934bb07.tar.bz2 framework-82ea0b9aa83affdac19ceaf6bf800b690934bb07.tar.xz framework-82ea0b9aa83affdac19ceaf6bf800b690934bb07.zip |
Add log exp (#381)
* add test for algorithm
* fix conflict
* suppress warning
* pass kwargs to Algorithm class creator
* added unary operation exp and log
Diffstat (limited to 'Wrappers/Python')
-rwxr-xr-x | Wrappers/Python/ccpi/framework/framework.py | 8 | ||||
-rwxr-xr-x | Wrappers/Python/test/test_DataContainer.py | 11 |
2 files changed, 19 insertions, 0 deletions
diff --git a/Wrappers/Python/ccpi/framework/framework.py b/Wrappers/Python/ccpi/framework/framework.py index ed97862..c58088a 100755 --- a/Wrappers/Python/ccpi/framework/framework.py +++ b/Wrappers/Python/ccpi/framework/framework.py @@ -827,6 +827,14 @@ class DataContainer(object): def conjugate(self, *args, **kwargs): return self.pixel_wise_unary(numpy.conjugate, *args, **kwargs) + + def exp(self, *args, **kwargs): + '''Applies exp pixel-wise to the DataContainer''' + return self.pixel_wise_unary(numpy.exp, *args, **kwargs) + + def log(self, *args, **kwargs): + '''Applies log pixel-wise to the DataContainer''' + return self.pixel_wise_unary(numpy.log, *args, **kwargs) #def __abs__(self): # operation = FM.OPERATION.ABS # return self.callFieldMath(operation, None, self.mask, self.maskOnValue) diff --git a/Wrappers/Python/test/test_DataContainer.py b/Wrappers/Python/test/test_DataContainer.py index 675e150..9b9a8dd 100755 --- a/Wrappers/Python/test/test_DataContainer.py +++ b/Wrappers/Python/test/test_DataContainer.py @@ -478,6 +478,17 @@ class TestDataContainer(unittest.TestCase): n0 = (ds0 * ds1).sum() n1 = ds0.as_array().ravel().dot(ds1.as_array().ravel()) self.assertEqual(n0, n1) + + def test_exp_log(self): + a0 = numpy.asarray([1 for i in range(2*3*4)]) + + ds0 = DataContainer(numpy.reshape(a0,(2,3,4)), suppress_warning=True) + # ds1 = DataContainer(numpy.reshape(a1,(2,3,4)), suppress_warning=True) + b = ds0.exp().log() + self.assertNumpyArrayEqual(ds0.as_array(), b.as_array()) + + self.assertEqual(ds0.exp().as_array()[0][0][0], numpy.exp(1)) + self.assertEqual(ds0.log().as_array()[0][0][0], 0.) |