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/14 12:40:02 UTC
[systemds] 02/03: [SYSTEMDS-3131] Python API node strings
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
commit 8aab7f5dc5dc125dce971978403428027e37dc60
Author: baunsgaard <ba...@tugraz.at>
AuthorDate: Tue Sep 14 14:39:14 2021 +0200
[SYSTEMDS-3131] Python API node strings
---
src/main/python/systemds/operator/nodes/frame.py | 3 +
src/main/python/systemds/operator/nodes/list.py | 2 +
.../python/systemds/operator/nodes/list_access.py | 5 +-
src/main/python/systemds/operator/nodes/matrix.py | 7 ++-
.../python/systemds/operator/nodes/multi_return.py | 5 +-
src/main/python/systemds/operator/nodes/scalar.py | 6 +-
src/main/python/systemds/operator/nodes/source.py | 3 +
src/main/python/tests/basics/__init__.py | 20 +++++++
src/main/python/tests/basics/test___str__.py | 66 ++++++++++++++++++++++
9 files changed, 112 insertions(+), 5 deletions(-)
diff --git a/src/main/python/systemds/operator/nodes/frame.py b/src/main/python/systemds/operator/nodes/frame.py
index 25f1b81..6551332 100644
--- a/src/main/python/systemds/operator/nodes/frame.py
+++ b/src/main/python/systemds/operator/nodes/frame.py
@@ -132,3 +132,6 @@ class Frame(OperationNode):
:return: The Frame containing the replaced values
"""
return Frame(self.sds_context, "replace", named_input_nodes={"target": self, "pattern": f"'{pattern}'", "replacement":f"'{replacement}'"})
+
+ def __str__(self):
+ return "FrameNode"
\ No newline at end of file
diff --git a/src/main/python/systemds/operator/nodes/list.py b/src/main/python/systemds/operator/nodes/list.py
index 90e2e90..09455a3 100644
--- a/src/main/python/systemds/operator/nodes/list.py
+++ b/src/main/python/systemds/operator/nodes/list.py
@@ -84,3 +84,5 @@ class List(OperationNode):
def compute(self, verbose: bool = False, lineage: bool = False) -> Union[np.array]:
return super().compute(verbose, lineage)
+ def __str__(self):
+ return "ListNode"
diff --git a/src/main/python/systemds/operator/nodes/list_access.py b/src/main/python/systemds/operator/nodes/list_access.py
index 869377f..10d51f5 100644
--- a/src/main/python/systemds/operator/nodes/list_access.py
+++ b/src/main/python/systemds/operator/nodes/list_access.py
@@ -60,4 +60,7 @@ class ListAccess(OperationNode):
ent = self._list_source[self._key]
res = Scalar(self.sds_context, "as.scalar", [ent])
self._list_source._outputs[self._key] = res
- return res
\ No newline at end of file
+ return res
+
+ def __str__(self):
+ return "ListAccessNode"
\ No newline at end of file
diff --git a/src/main/python/systemds/operator/nodes/matrix.py b/src/main/python/systemds/operator/nodes/matrix.py
index f205b4d..f90218b 100644
--- a/src/main/python/systemds/operator/nodes/matrix.py
+++ b/src/main/python/systemds/operator/nodes/matrix.py
@@ -335,7 +335,7 @@ class Matrix(OperationNode):
return Matrix(self.sds_context, 'order', [], named_input_nodes=named_input_nodes)
- def to_string(self, **kwargs: Dict[str, VALID_INPUT_TYPES]) -> 'Matrix':
+ def to_string(self, **kwargs: Dict[str, VALID_INPUT_TYPES]) -> 'Scalar':
""" Converts the input to a string representation.
:return: `Scalar` containing the string.
"""
@@ -359,4 +359,7 @@ class Matrix(OperationNode):
"""
Replace all values with replacement value
"""
- return Matrix(self.sds_context, "replace", named_input_nodes={"target": self, "pattern": pattern, "replacement":replacement})
\ No newline at end of file
+ return Matrix(self.sds_context, "replace", named_input_nodes={"target": self, "pattern": pattern, "replacement":replacement})
+
+ def __str__(self):
+ return "MatrixNode"
diff --git a/src/main/python/systemds/operator/nodes/multi_return.py b/src/main/python/systemds/operator/nodes/multi_return.py
index c14a7b0..90b2de5 100644
--- a/src/main/python/systemds/operator/nodes/multi_return.py
+++ b/src/main/python/systemds/operator/nodes/multi_return.py
@@ -82,4 +82,7 @@ class MultiReturn(OperationNode):
return result_var
def __iter__(self):
- return iter(self._outputs)
\ No newline at end of file
+ return iter(self._outputs)
+
+ def __str__(self):
+ return "MultiReturnNode"
diff --git a/src/main/python/systemds/operator/nodes/scalar.py b/src/main/python/systemds/operator/nodes/scalar.py
index cd27d30..5078ac0 100644
--- a/src/main/python/systemds/operator/nodes/scalar.py
+++ b/src/main/python/systemds/operator/nodes/scalar.py
@@ -218,8 +218,12 @@ class Scalar(OperationNode):
"""
return Scalar(self.sds_context, 'tanh', [self])
- def to_string(self, **kwargs: Dict[str, VALID_INPUT_TYPES]) -> 'OperationNode':
+ def to_string(self, **kwargs: Dict[str, VALID_INPUT_TYPES]) -> 'Scalar':
""" Converts the input to a string representation.
:return: `Scalar` containing the string.
"""
return Scalar(self.sds_context, 'toString', [self], named_input_nodes=kwargs, output_type=OutputType.STRING)
+
+ def __str__(self):
+ return "ScalarNode"
+
diff --git a/src/main/python/systemds/operator/nodes/source.py b/src/main/python/systemds/operator/nodes/source.py
index 8008c9b..d027209 100644
--- a/src/main/python/systemds/operator/nodes/source.py
+++ b/src/main/python/systemds/operator/nodes/source.py
@@ -197,3 +197,6 @@ class Source(OperationNode):
def compute(self, verbose: bool = False, lineage: bool = False):
raise Exception("Invalid invocation of source from script")
+
+ def __str__(self):
+ return "SourceNode"
diff --git a/src/main/python/tests/basics/__init__.py b/src/main/python/tests/basics/__init__.py
new file mode 100644
index 0000000..e66abb4
--- /dev/null
+++ b/src/main/python/tests/basics/__init__.py
@@ -0,0 +1,20 @@
+# -------------------------------------------------------------
+#
+# 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.
+#
+# -------------------------------------------------------------
diff --git a/src/main/python/tests/basics/test___str__.py b/src/main/python/tests/basics/test___str__.py
new file mode 100644
index 0000000..7e2010d
--- /dev/null
+++ b/src/main/python/tests/basics/test___str__.py
@@ -0,0 +1,66 @@
+# -------------------------------------------------------------
+#
+# 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
+
+from systemds.context import SystemDSContext
+
+
+class Test__str__(unittest.TestCase):
+
+ sds: SystemDSContext = None
+
+ @classmethod
+ def setUpClass(cls):
+ cls.sds = SystemDSContext()
+
+ @classmethod
+ def tearDownClass(cls):
+ cls.sds.close()
+
+ def test_1(self):
+ self.assertTrue("MatrixNode" in str(self.sds.full([1, 2], 3)))
+
+ def test_2(self):
+ self.assertTrue("ScalarNode" in str(self.sds.scalar(3)))
+
+ def test_3(self):
+ self.assertTrue("ScalarNode" in str(self.sds.scalar("Hi")))
+
+ def test_4(self):
+ self.assertTrue("ScalarNode" in str(
+ self.sds.full([1, 2], 3).to_string()))
+
+ def test_5(self):
+ self.assertTrue("ListNode" in str(self.sds.list(
+ self.sds.rand(1, 2, 3, 4), self.sds.scalar(4))))
+
+ def test_6(self):
+ self.assertTrue("MatrixNode" in str(self.sds.list(
+ self.sds.rand(1, 2, 3, 4), self.sds.scalar(4))[0]))
+
+ def test_7(self):
+ self.assertTrue("ScalarNode" in str(self.sds.list(
+ self.sds.rand(1, 2, 3, 4), self.sds.scalar(4))[1]))
+
+
+if __name__ == "__main__":
+ unittest.main(exit=False)