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 2020/08/31 21:15:19 UTC

[systemds] branch master updated: [SYSTEMDS-2653] Fix eval function call list expansion logic

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 1eb5bdc  [SYSTEMDS-2653] Fix eval function call list expansion logic
1eb5bdc is described below

commit 1eb5bdc4b01df23440687c591c6c31a6994daeb1
Author: Matthias Boehm <mb...@gmail.com>
AuthorDate: Mon Aug 31 23:14:56 2020 +0200

    [SYSTEMDS-2653] Fix eval function call list expansion logic
    
    The second-order function eval (for executing functions by names) takes
    either multiple matrix/frame/scalar inputs or a single list of inputs.
    This requires a list expansion on demand. Unfortunately, the existing
    logic had issues which caused a missing expansion if a list with a
    single input argument was passed.
---
 .../instructions/cp/EvalNaryCPInstruction.java     |  2 +-
 .../test/functions/misc/FunctionPotpourriTest.java | 17 +++++++-----
 .../functions/misc/FunPotpourriEvalList1Arg.dml    | 30 +++++++++++++++++++++
 .../functions/misc/FunPotpourriEvalList2Arg.dml    | 31 ++++++++++++++++++++++
 4 files changed, 73 insertions(+), 7 deletions(-)

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 2cfd804..eb75f71 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
@@ -89,7 +89,7 @@ public class EvalNaryCPInstruction extends BuiltinNaryCPInstruction {
 		//4. expand list arguments if needed
 		CPOperand[] boundInputs2 = null;
 		if( boundInputs.length == 1 && boundInputs[0].getDataType().isList()
-			&& fpb.getInputParams().size() > 1 && !fpb.getInputParams().get(0).getDataType().isList()) 
+			&& !(fpb.getInputParams().size() == 1 && fpb.getInputParams().get(0).getDataType().isList()))
 		{
 			ListObject lo = ec.getListObject(boundInputs[0]);
 			checkValidArguments(lo.getData(), lo.getNames(), fpb.getInputParamNames());
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 814d116..3b4b666 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
@@ -52,7 +52,8 @@ public class FunctionPotpourriTest extends AutomatedTestBase
 		"FunPotpourriNestedParforEval",
 		"FunPotpourriMultiEval",
 		"FunPotpourriEvalPred",
-		"FunPotpourriEvalListArg",
+		"FunPotpourriEvalList1Arg",
+		"FunPotpourriEvalList2Arg",
 	};
 	
 	private final static String TEST_DIR = "functions/misc/";
@@ -175,15 +176,19 @@ public class FunctionPotpourriTest extends AutomatedTestBase
 		runFunctionTest( TEST_NAMES[21], null );
 	}
 	
-//	@Test
-//	public void testFunctionEvalListArg() {
-//		runFunctionTest( TEST_NAMES[22], null );
-//	}
+	@Test
+	public void testFunctionEvalList1Arg() {
+		runFunctionTest( TEST_NAMES[22], null );
+	}
+	
+	@Test
+	public void testFunctionEvalList2Arg() {
+		runFunctionTest( TEST_NAMES[23], null );
+	}
 	
 	private void runFunctionTest(String testName, Class<?> error) {
 		TestConfiguration config = getTestConfiguration(testName);
 		loadTestConfiguration(config);
-		setOutputBuffering(false);
 		
 		String HOME = SCRIPT_DIR + TEST_DIR;
 		fullDMLScriptName = HOME + testName + ".dml";
diff --git a/src/test/scripts/functions/misc/FunPotpourriEvalList1Arg.dml b/src/test/scripts/functions/misc/FunPotpourriEvalList1Arg.dml
new file mode 100644
index 0000000..56c3ef2
--- /dev/null
+++ b/src/test/scripts/functions/misc/FunPotpourriEvalList1Arg.dml
@@ -0,0 +1,30 @@
+#-------------------------------------------------------------
+#
+# 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) return (Matrix[Double] s){
+  s = as.matrix(5)
+  for(i in 1:ncol(X))
+    print("this is i " +i)
+}
+
+X = rand(rows=100, cols=100)
+s = eval("foo", list(X))
+print(toString(s))
diff --git a/src/test/scripts/functions/misc/FunPotpourriEvalList2Arg.dml b/src/test/scripts/functions/misc/FunPotpourriEvalList2Arg.dml
new file mode 100644
index 0000000..e5f4889
--- /dev/null
+++ b/src/test/scripts/functions/misc/FunPotpourriEvalList2Arg.dml
@@ -0,0 +1,31 @@
+#-------------------------------------------------------------
+#
+# 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)
+}
+
+X = rand(rows=100, cols=100)
+s = eval("foo", list(X, TRUE))
+print(toString(s))