[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.
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 @@
//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 @@
"FunPotpourriNestedParforEval",
"FunPotpourriMultiEval",
"FunPotpourriEvalPred",
- "FunPotpourriEvalListArg",
+ "FunPotpourriEvalList1Arg",
+ "FunPotpourriEvalList2Arg",
};
private final static String TEST_DIR = "functions/misc/";
@@ -175,15 +176,19 @@
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))