summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdoardo Pasca <edo.paskino@gmail.com>2019-10-11 20:22:23 +0100
committerGitHub <noreply@github.com>2019-10-11 20:22:23 +0100
commit82ea0b9aa83affdac19ceaf6bf800b690934bb07 (patch)
treeea1bd17d8f98877ec295384a4b430785e2eb8800
parentc7213fdfcd31e6ec780aab4afe1bd34374d784f5 (diff)
downloadframework-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
-rwxr-xr-xWrappers/Python/ccpi/framework/framework.py8
-rwxr-xr-xWrappers/Python/test/test_DataContainer.py11
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.)