You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemds.apache.org by ba...@apache.org on 2021/09/15 08:26:52 UTC
[systemds] branch master updated: [MINOR] PythonAPI add min and max
This is an automated email from the ASF dual-hosted git repository.
baunsgaard pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/systemds.git
The following commit(s) were added to refs/heads/master by this push:
new 3892780 [MINOR] PythonAPI add min and max
3892780 is described below
commit 389278094abff4a1135865e4dcd0870745d6f4bf
Author: baunsgaard <ba...@tugraz.at>
AuthorDate: Wed Sep 15 10:20:45 2021 +0200
[MINOR] PythonAPI add min and max
This also includ row and column means
---
src/main/python/systemds/operator/nodes/matrix.py | 30 +++++++++++++++++++++++
src/main/python/tests/matrix/test_aggregations.py | 23 +++++++++++++++++
2 files changed, 53 insertions(+)
diff --git a/src/main/python/systemds/operator/nodes/matrix.py b/src/main/python/systemds/operator/nodes/matrix.py
index 4f08735..9def246 100644
--- a/src/main/python/systemds/operator/nodes/matrix.py
+++ b/src/main/python/systemds/operator/nodes/matrix.py
@@ -188,6 +188,36 @@ class Matrix(OperationNode):
raise ValueError(
f"Axis has to be either 0, 1 or None, for column, row or complete {self.operation}")
+ def max(self, axis: int = None) -> 'OperationNode':
+ """Calculate max of matrix.
+
+ :param axis: can be 0 or 1 to do either row or column aggregation
+ :return: `Matrix` representing operation
+ """
+ if axis == 0:
+ return Matrix(self.sds_context, 'colMaxs', [self])
+ elif axis == 1:
+ return Matrix(self.sds_context, 'rowMaxs', [self])
+ elif axis is None:
+ return Scalar(self.sds_context, 'max', [self])
+ raise ValueError(
+ f"Axis has to be either 0, 1 or None, for column, row or complete {self.operation}")
+
+ def min(self, axis: int = None) -> 'OperationNode':
+ """Calculate max of matrix.
+
+ :param axis: can be 0 or 1 to do either row or column aggregation
+ :return: `Matrix` representing operation
+ """
+ if axis == 0:
+ return Matrix(self.sds_context, 'colMins', [self])
+ elif axis == 1:
+ return Matrix(self.sds_context, 'rowMins', [self])
+ elif axis is None:
+ return Scalar(self.sds_context, 'min', [self])
+ raise ValueError(
+ f"Axis has to be either 0, 1 or None, for column, row or complete {self.operation}")
+
def var(self, axis: int = None) -> 'OperationNode':
"""Calculate variance of matrix.
diff --git a/src/main/python/tests/matrix/test_aggregations.py b/src/main/python/tests/matrix/test_aggregations.py
index 2f88759..1d7172e 100644
--- a/src/main/python/tests/matrix/test_aggregations.py
+++ b/src/main/python/tests/matrix/test_aggregations.py
@@ -88,6 +88,29 @@ class TestMatrixAggFn(unittest.TestCase):
self.assertTrue(np.allclose(
self.sds.from_numpy(m1).var(axis=1).compute(), m1.var(axis=1, ddof=1).reshape(dim, 1)))
+ def test_min1(self):
+ self.assertTrue(np.allclose(
+ self.sds.from_numpy(m1).min().compute(), m1.min()))
+
+ def test_min2(self):
+ self.assertTrue(np.allclose(
+ self.sds.from_numpy(m1).min(axis=0).compute(), m1.min(axis=0)))
+
+ def test_min3(self):
+ self.assertTrue(np.allclose(
+ self.sds.from_numpy(m1).min(axis=1).compute(), m1.min(axis=1).reshape(dim, 1)))
+
+ def test_max1(self):
+ self.assertTrue(np.allclose(
+ self.sds.from_numpy(m1).max().compute(), m1.max()))
+
+ def test_max2(self):
+ self.assertTrue(np.allclose(
+ self.sds.from_numpy(m1).max(axis=0).compute(), m1.max(axis=0)))
+
+ def test_max3(self):
+ self.assertTrue(np.allclose(
+ self.sds.from_numpy(m1).max(axis=1).compute(), m1.max(axis=1).reshape(dim, 1)))
if __name__ == "__main__":
unittest.main(exit=False)