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 4bd2b36 [SYSTEMDS-3046] Python Split Tests
4bd2b36 is described below
commit 4bd2b3645b7e61422d3c07707dd83282c0c09798
Author: baunsgaard <[email protected]>
AuthorDate: Wed Jun 30 13:44:05 2021 +0200
[SYSTEMDS-3046] Python Split Tests
---
.../python/systemds/operator/algorithm/__init__.py | 4 +
.../algorithm/builtin/hospitalResidencyMatch.py | 58 ++++++++++
.../systemds/operator/algorithm/builtin/softmax.py | 37 +++++++
src/main/python/tests/matrix/test_split.py | 117 +++++++++++++++++++++
4 files changed, 216 insertions(+)
diff --git a/src/main/python/systemds/operator/algorithm/__init__.py
b/src/main/python/systemds/operator/algorithm/__init__.py
index 9658832..172e12b 100644
--- a/src/main/python/systemds/operator/algorithm/__init__.py
+++ b/src/main/python/systemds/operator/algorithm/__init__.py
@@ -48,6 +48,7 @@ from .builtin.glm import glm
from .builtin.gmm import gmm
from .builtin.gmmPredict import gmmPredict
from .builtin.gnmf import gnmf
+from .builtin.hospitalResidencyMatch import hospitalResidencyMatch
from .builtin.hyperband import hyperband
from .builtin.img_brightness import img_brightness
from .builtin.img_crop import img_crop
@@ -100,6 +101,7 @@ from .builtin.sherlockPredict import sherlockPredict
from .builtin.sigmoid import sigmoid
from .builtin.slicefinder import slicefinder
from .builtin.smote import smote
+from .builtin.softmax import softmax
from .builtin.split import split
from .builtin.splitBalanced import splitBalanced
from .builtin.stableMarriage import stableMarriage
@@ -140,6 +142,7 @@ __all__ = ['abstain',
'gmm',
'gmmPredict',
'gnmf',
+ 'hospitalResidencyMatch',
'hyperband',
'img_brightness',
'img_crop',
@@ -192,6 +195,7 @@ __all__ = ['abstain',
'sigmoid',
'slicefinder',
'smote',
+ 'softmax',
'split',
'splitBalanced',
'stableMarriage',
diff --git
a/src/main/python/systemds/operator/algorithm/builtin/hospitalResidencyMatch.py
b/src/main/python/systemds/operator/algorithm/builtin/hospitalResidencyMatch.py
new file mode 100644
index 0000000..6012871
--- /dev/null
+++
b/src/main/python/systemds/operator/algorithm/builtin/hospitalResidencyMatch.py
@@ -0,0 +1,58 @@
+# -------------------------------------------------------------
+#
+# 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.
+#
+# -------------------------------------------------------------
+
+# Autogenerated By : src/main/python/generator/generator.py
+# Autogenerated From : scripts/builtin/hospitalResidencyMatch.dml
+
+from typing import Dict, Iterable
+
+from systemds.operator import OperationNode, Matrix, Frame, List, MultiReturn,
Scalar
+from systemds.script_building.dag import OutputType
+from systemds.utils.consts import VALID_INPUT_TYPES
+
+
+def hospitalResidencyMatch(R: Matrix,
+ H: Matrix,
+ capacity: Matrix,
+ **kwargs: Dict[str, VALID_INPUT_TYPES]):
+ """
+ :param R: Residents matrix R.
+ :param It: an ORDERED matrix.
+ :param H: Hospitals matrix H.
+ :param It: an UNORDRED matrix.
+ :param capacity: capacity of Hospitals matrix C.
+ :param It: a [n*1] matrix with non zero values.
+ :param with: and vice-versa (higher is better).
+ :return: 'OperationNode' containing result matrix & result matrix & an
ordered matrix, this means that resident 1 (row 1) likes hospital 2 the most,
followed by hospital 1 and hospital 3. & unordered, this would mean that
resident 1 (row 1) likes hospital 3 the most (since the value at [1,3] is the
row max), & 1 (2.0 preference value) and hospital 2 (1.0 preference value). &
an unordered matrix this means that hospital 1 (row 1) likes resident 1 the
most (since the value at [1,1] is [...]
+ """
+ params_dict = {'R': R, 'H': H, 'capacity': capacity}
+ params_dict.update(kwargs)
+
+ vX_0 = Matrix(R.sds_context, '')
+ vX_1 = Matrix(R.sds_context, '')
+ output_nodes = [vX_0, vX_1, ]
+
+ op = MultiReturn(R.sds_context, 'hospitalResidencyMatch', output_nodes,
named_input_nodes=params_dict)
+
+ vX_0._unnamed_input_nodes = [op]
+ vX_1._unnamed_input_nodes = [op]
+
+ return op
diff --git a/src/main/python/systemds/operator/algorithm/builtin/softmax.py
b/src/main/python/systemds/operator/algorithm/builtin/softmax.py
new file mode 100644
index 0000000..4e4a1e2
--- /dev/null
+++ b/src/main/python/systemds/operator/algorithm/builtin/softmax.py
@@ -0,0 +1,37 @@
+# -------------------------------------------------------------
+#
+# 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.
+#
+# -------------------------------------------------------------
+
+# Autogenerated By : src/main/python/generator/generator.py
+# Autogenerated From : scripts/builtin/softmax.dml
+
+from typing import Dict, Iterable
+
+from systemds.operator import OperationNode, Matrix, Frame, List, MultiReturn,
Scalar
+from systemds.script_building.dag import OutputType
+from systemds.utils.consts import VALID_INPUT_TYPES
+
+
+def softmax(S: Matrix):
+
+ params_dict = {'S': S}
+ return Matrix(S.sds_context,
+ 'softmax',
+ named_input_nodes=params_dict)
diff --git a/src/main/python/tests/matrix/test_split.py
b/src/main/python/tests/matrix/test_split.py
new file mode 100644
index 0000000..7c92353
--- /dev/null
+++ b/src/main/python/tests/matrix/test_split.py
@@ -0,0 +1,117 @@
+# -------------------------------------------------------------
+#
+# 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 random
+
+import numpy as np
+from systemds.context import SystemDSContext
+from systemds.operator.algorithm import split
+
+# Seed the random ness.
+np.random.seed(7)
+
+class TestOrder(unittest.TestCase):
+
+ sds: SystemDSContext = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.sds = SystemDSContext()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.sds.close()
+
+ def test_basic(self):
+ m = self.make_matrix()
+
+ o = self.sds.from_numpy(m).compute()
+ s = m
+ self.assertTrue(np.allclose(o, s))
+
+ def test_split(self):
+ X = self.make_matrix()
+ Y = self.make_matrix(cols = 2)
+
+ [p1,p2,p3,p4] = split(self.sds.from_numpy(X),
self.sds.from_numpy(Y)).compute()
+ exp1 = X[:2]
+ exp2 = X[2:]
+ exp3 = Y[:2]
+ exp4 = Y[2:]
+ self.assertTrue(np.allclose(p1, exp1))
+ self.assertTrue(np.allclose(p2, exp2))
+ self.assertTrue(np.allclose(p3, exp3))
+ self.assertTrue(np.allclose(p4, exp4))
+
+ def test_split_2(self):
+ rows = 10
+ X = self.make_matrix(rows = rows)
+ Y = self.make_matrix(rows = rows, cols = 2)
+
+ [p1,p2,p3,p4] = split(self.sds.from_numpy(X),
self.sds.from_numpy(Y)).compute()
+ exp1 = X[:7]
+ exp2 = X[7:]
+ exp3 = Y[:7]
+ exp4 = Y[7:]
+ self.assertTrue(np.allclose(p1, exp1))
+ self.assertTrue(np.allclose(p2, exp2))
+ self.assertTrue(np.allclose(p3, exp3))
+ self.assertTrue(np.allclose(p4, exp4))
+
+ def test_split_3(self):
+ rows = 100
+ X = self.make_matrix(rows = rows)
+ Y = self.make_matrix(rows = rows, cols = 2)
+
+ [p1,p2,p3,p4] = split(self.sds.from_numpy(X),
self.sds.from_numpy(Y)).compute()
+ exp1 = X[:70]
+ exp2 = X[70:]
+ exp3 = Y[:70]
+ exp4 = Y[70:]
+ self.assertTrue(np.allclose(p1, exp1))
+ self.assertTrue(np.allclose(p2, exp2))
+ self.assertTrue(np.allclose(p3, exp3))
+ self.assertTrue(np.allclose(p4, exp4))
+
+
+ def test_split_4(self):
+ rows = 100
+ X = self.make_matrix(rows = rows)
+ Y = self.make_matrix(rows = rows, cols = 2)
+
+ [p1,p2,p3,p4] = split(self.sds.from_numpy(X), self.sds.from_numpy(Y),
f=0.2).compute()
+ exp1 = X[:20]
+ exp2 = X[20:]
+ exp3 = Y[:20]
+ exp4 = Y[20:]
+ self.assertTrue(np.allclose(p1, exp1))
+ self.assertTrue(np.allclose(p2, exp2))
+ self.assertTrue(np.allclose(p3, exp3))
+ self.assertTrue(np.allclose(p4, exp4))
+
+
+ def make_matrix(self, rows = 4, cols = 4):
+ return np.random.rand(rows,cols)
+
+
+if __name__ == "__main__":
+ unittest.main(exit=False)