This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/main by this push:
new 170ad7d52d [SYSTEMDS-3735] Python API Builtin exp
170ad7d52d is described below
commit 170ad7d52d53e0fafabc8d0054df77c29a4783cd
Author: e-strauss <[email protected]>
AuthorDate: Fri Aug 30 23:48:00 2024 +0200
[SYSTEMDS-3735] Python API Builtin exp
Add missing non dml bodied exponential operator
Closes #2077
---
src/main/python/systemds/operator/nodes/matrix.py | 7 +++
src/main/python/systemds/operator/nodes/scalar.py | 7 +++
src/main/python/tests/matrix/test_exp.py | 62 +++++++++++++++++++++++
3 files changed, 76 insertions(+)
diff --git a/src/main/python/systemds/operator/nodes/matrix.py
b/src/main/python/systemds/operator/nodes/matrix.py
index 205bef4359..f06ce315e8 100644
--- a/src/main/python/systemds/operator/nodes/matrix.py
+++ b/src/main/python/systemds/operator/nodes/matrix.py
@@ -273,6 +273,13 @@ class Matrix(OperationNode):
"""
return Matrix(self.sds_context, 'sqrt', [self])
+ def exp(self) -> 'Matrix':
+ """Calculate exponential.
+
+ :return: `Matrix` representing operation
+ """
+ return Matrix(self.sds_context, 'exp', [self])
+
def sin(self) -> 'Matrix':
"""Calculate sin.
diff --git a/src/main/python/systemds/operator/nodes/scalar.py
b/src/main/python/systemds/operator/nodes/scalar.py
index 161708472d..a764ad3abb 100644
--- a/src/main/python/systemds/operator/nodes/scalar.py
+++ b/src/main/python/systemds/operator/nodes/scalar.py
@@ -170,6 +170,13 @@ class Scalar(OperationNode):
"""
return Scalar(self.sds_context, 'sin', [self])
+ def exp(self) -> 'Scalar':
+ """Calculate exponential.
+
+ :return: `Scalar` representing operation
+ """
+ return Scalar(self.sds_context, 'exp', [self])
+
def cos(self) -> 'Scalar':
"""Calculate cos.
diff --git a/src/main/python/tests/matrix/test_exp.py
b/src/main/python/tests/matrix/test_exp.py
new file mode 100644
index 0000000000..67f3377351
--- /dev/null
+++ b/src/main/python/tests/matrix/test_exp.py
@@ -0,0 +1,62 @@
+# -------------------------------------------------------------
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+# -------------------------------------------------------------
+
+import unittest
+import numpy as np
+from systemds.context import SystemDSContext
+
+class TestEXP(unittest.TestCase):
+ def setUp(self):
+ self.sds = SystemDSContext()
+
+ def tearDown(self):
+ self.sds.close()
+
+ def test_exp_basic(self):
+
+ input_matrix = np.array([[1, 2, 3, 4],
+ [5, 6, 7, 8],
+ [9, 10, 11, 12],
+ [13, 14, 15, 16]]) - 8
+
+ sds_input = self.sds.from_numpy(input_matrix)
+ sds_result = sds_input.exp().compute()
+ np_result_np = np.exp(input_matrix)
+ assert np.allclose(sds_result, np_result_np,1e-9)
+
+ def test_exp_random(self):
+
+ input_matrix = np.random.random((10,10))
+ sds_input = self.sds.from_numpy(input_matrix)
+ sds_result = sds_input.exp().compute()
+ np_result_np = np.exp(input_matrix)
+ assert np.allclose(sds_result, np_result_np,1e-9)
+
+ def test_exp_scalar(self):
+ for i in np.random.random(10):
+ sds_input = self.sds.scalar(i)
+ sds_result = sds_input.exp().compute()
+ np_result_np = np.exp(i)
+ assert np.isclose(sds_result, np_result_np,1e-9)
+
+
+if __name__ == '__main__':
+ unittest.main()
\ No newline at end of file