You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemds.apache.org by mb...@apache.org on 2021/05/13 14:01:27 UTC

[systemds] branch master updated: [SYSTEMDS-2924] Support for namespaces in eval 2nd-order function calls

This is an automated email from the ASF dual-hosted git repository.

mboehm7 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 05b872e  [SYSTEMDS-2924] Support for namespaces in eval 2nd-order function calls
05b872e is described below

commit 05b872ecb44a18499d53d63cfe157ef928501805
Author: Matthias Boehm <mb...@gmail.com>
AuthorDate: Thu May 13 15:35:20 2021 +0200

    [SYSTEMDS-2924] Support for namespaces in eval 2nd-order function calls
    
    So far, we only supported eval function calls of functions in default or
    builtin namespaces. This patch now extends that to all user namespacesm
    but similar to paramserv only by the physical namespace name.
---
 .../sysds/parser/dml/DmlSyntacticValidator.java    |  4 +++-
 .../instructions/cp/EvalNaryCPInstruction.java     |  8 ++++---
 .../test/functions/misc/FunctionPotpourriTest.java |  6 +++++
 .../functions/misc/FunPotpourriEvalNamespace.dml   | 27 ++++++++++++++++++++++
 .../misc/FunPotpourriEvalNamespaceFuns.dml         | 27 ++++++++++++++++++++++
 5 files changed, 68 insertions(+), 4 deletions(-)

diff --git a/src/main/java/org/apache/sysds/parser/dml/DmlSyntacticValidator.java b/src/main/java/org/apache/sysds/parser/dml/DmlSyntacticValidator.java
index 0d0e41a..3c91244 100644
--- a/src/main/java/org/apache/sysds/parser/dml/DmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysds/parser/dml/DmlSyntacticValidator.java
@@ -1116,7 +1116,9 @@ public class DmlSyntacticValidator implements DmlListener {
 		//NOTE: the use of File.separator would lead to OS-specific inconsistencies,
 		//which is problematic for second order functions such as eval or paramserv.
 		//Since this is unnecessary, we now use "/" independent of the use OS.
-		return !new File(filePath).isAbsolute() ? workingDir + "/" + filePath : filePath;
+		String prefix = workingDir + "/";
+		return new File(filePath).isAbsolute() | filePath.startsWith(prefix) ?
+			filePath : prefix + filePath;
 	}
 	
 	public String getNamespaceSafe(Token ns) {
diff --git a/src/main/java/org/apache/sysds/runtime/instructions/cp/EvalNaryCPInstruction.java b/src/main/java/org/apache/sysds/runtime/instructions/cp/EvalNaryCPInstruction.java
index 8fd7867..d200bea 100644
--- a/src/main/java/org/apache/sysds/runtime/instructions/cp/EvalNaryCPInstruction.java
+++ b/src/main/java/org/apache/sysds/runtime/instructions/cp/EvalNaryCPInstruction.java
@@ -62,9 +62,11 @@ public class EvalNaryCPInstruction extends BuiltinNaryCPInstruction {
 		//1. get the namespace and func
 		String funcName = ec.getScalarInput(inputs[0]).getStringValue();
 		String nsName = null; //default namespace
-		if( funcName.contains(Program.KEY_DELIM) )
-			throw new DMLRuntimeException("Eval calls to '"+funcName+"', i.e., a function outside "
-				+ "the default "+ "namespace, are not supported yet. Please call the function directly.");
+		if( funcName.contains(Program.KEY_DELIM) ) {
+			String[] parts = DMLProgram.splitFunctionKey(funcName);
+			funcName = parts[1];
+			nsName = parts[0];
+		}
 		
 		// bound the inputs to avoiding being deleted after the function call
 		CPOperand[] boundInputs = Arrays.copyOfRange(inputs, 1, inputs.length);
diff --git a/src/test/java/org/apache/sysds/test/functions/misc/FunctionPotpourriTest.java b/src/test/java/org/apache/sysds/test/functions/misc/FunctionPotpourriTest.java
index 3b4b666..b174dbb 100644
--- a/src/test/java/org/apache/sysds/test/functions/misc/FunctionPotpourriTest.java
+++ b/src/test/java/org/apache/sysds/test/functions/misc/FunctionPotpourriTest.java
@@ -54,6 +54,7 @@ public class FunctionPotpourriTest extends AutomatedTestBase
 		"FunPotpourriEvalPred",
 		"FunPotpourriEvalList1Arg",
 		"FunPotpourriEvalList2Arg",
+		"FunPotpourriEvalNamespace",
 	};
 	
 	private final static String TEST_DIR = "functions/misc/";
@@ -186,6 +187,11 @@ public class FunctionPotpourriTest extends AutomatedTestBase
 		runFunctionTest( TEST_NAMES[23], null );
 	}
 	
+	@Test
+	public void testFunctionEvalNamespace() {
+		runFunctionTest( TEST_NAMES[24], null );
+	}
+	
 	private void runFunctionTest(String testName, Class<?> error) {
 		TestConfiguration config = getTestConfiguration(testName);
 		loadTestConfiguration(config);
diff --git a/src/test/scripts/functions/misc/FunPotpourriEvalNamespace.dml b/src/test/scripts/functions/misc/FunPotpourriEvalNamespace.dml
new file mode 100644
index 0000000..7baed57
--- /dev/null
+++ b/src/test/scripts/functions/misc/FunPotpourriEvalNamespace.dml
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+source("./src/test/scripts/functions/misc/FunPotpourriEvalNamespaceFuns.dml") as fns1
+
+ns = "./src/test/scripts/functions/misc/FunPotpourriEvalNamespaceFuns.dml"
+X = rand(rows=100, cols=100)
+s = eval(ns+"::foo", list(X, TRUE))
+print(toString(s))
diff --git a/src/test/scripts/functions/misc/FunPotpourriEvalNamespaceFuns.dml b/src/test/scripts/functions/misc/FunPotpourriEvalNamespaceFuns.dml
new file mode 100644
index 0000000..dbbd2ea
--- /dev/null
+++ b/src/test/scripts/functions/misc/FunPotpourriEvalNamespaceFuns.dml
@@ -0,0 +1,27 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+foo = function(Matrix[Double] X, Boolean verbose) return (Matrix[Double] s) {
+  s = as.matrix(5)
+  for(i in 1:ncol(X))
+    if(verbose)
+      print("this is i " +i)
+}