You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by gw...@apache.org on 2016/09/28 19:25:24 UTC
incubator-systemml git commit: [SYSTEMML-954] Support PyDML range for
two arguments
Repository: incubator-systemml
Updated Branches:
refs/heads/master eda3516f5 -> c5f3e71a3
[SYSTEMML-954] Support PyDML range for two arguments
Range() can accept two arguments instead of three.
Added tests for range and extended SequenceTest to test range.
Closes #256.
Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/c5f3e71a
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/c5f3e71a
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/c5f3e71a
Branch: refs/heads/master
Commit: c5f3e71a3faa6734a99ead8918bc022744edded5
Parents: eda3516
Author: Sandeep Narayanaswami <sa...@capitalone.com>
Authored: Wed Sep 28 12:19:30 2016 -0700
Committer: Glenn Weidner <gw...@us.ibm.com>
Committed: Wed Sep 28 12:19:30 2016 -0700
----------------------------------------------------------------------
.../parser/pydml/PydmlSyntacticValidator.java | 26 +++---
.../functions/data/SequenceTest.java | 91 +++++++++++++-------
src/test/scripts/functions/data/Range.pydml | 23 +++++
.../scripts/functions/data/Range2inputs.pydml | 23 +++++
4 files changed, 120 insertions(+), 43 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/c5f3e71a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
index 7068589..65a0d97 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
@@ -19,14 +19,6 @@
package org.apache.sysml.parser.pydml;
-import java.io.File;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.Token;
import org.antlr.v4.runtime.tree.ErrorNode;
@@ -50,8 +42,8 @@ import org.apache.sysml.parser.FunctionCallIdentifier;
import org.apache.sysml.parser.FunctionStatement;
import org.apache.sysml.parser.IfStatement;
import org.apache.sysml.parser.ImportStatement;
-import org.apache.sysml.parser.IntIdentifier;
import org.apache.sysml.parser.IndexedIdentifier;
+import org.apache.sysml.parser.IntIdentifier;
import org.apache.sysml.parser.IterablePredicate;
import org.apache.sysml.parser.LanguageException;
import org.apache.sysml.parser.ParForStatement;
@@ -84,6 +76,7 @@ import org.apache.sysml.parser.pydml.PydmlParser.ConstStringIdExpressionContext;
import org.apache.sysml.parser.pydml.PydmlParser.ConstTrueExpressionContext;
import org.apache.sysml.parser.pydml.PydmlParser.DataIdExpressionContext;
import org.apache.sysml.parser.pydml.PydmlParser.DataIdentifierContext;
+import org.apache.sysml.parser.pydml.PydmlParser.ElifBranchContext;
import org.apache.sysml.parser.pydml.PydmlParser.ExpressionContext;
import org.apache.sysml.parser.pydml.PydmlParser.ExternalFunctionDefExpressionContext;
import org.apache.sysml.parser.pydml.PydmlParser.ForStatementContext;
@@ -91,7 +84,6 @@ import org.apache.sysml.parser.pydml.PydmlParser.FunctionCallAssignmentStatement
import org.apache.sysml.parser.pydml.PydmlParser.FunctionCallMultiAssignmentStatementContext;
import org.apache.sysml.parser.pydml.PydmlParser.FunctionStatementContext;
import org.apache.sysml.parser.pydml.PydmlParser.IfStatementContext;
-import org.apache.sysml.parser.pydml.PydmlParser.ElifBranchContext;
import org.apache.sysml.parser.pydml.PydmlParser.IfdefAssignmentStatementContext;
import org.apache.sysml.parser.pydml.PydmlParser.IgnoreNewLineContext;
import org.apache.sysml.parser.pydml.PydmlParser.ImportStatementContext;
@@ -118,6 +110,14 @@ import org.apache.sysml.parser.pydml.PydmlParser.UnaryExpressionContext;
import org.apache.sysml.parser.pydml.PydmlParser.ValueDataTypeCheckContext;
import org.apache.sysml.parser.pydml.PydmlParser.WhileStatementContext;
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
/**
* TODO: Refactor duplicated parser code dml/pydml (entire package).
*
@@ -959,9 +959,11 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
namespace = DMLProgram.DEFAULT_NAMESPACE;
}
else if(namespace.equals(DMLProgram.DEFAULT_NAMESPACE) && functionName.equals("range")) {
- if(paramExpression.size() != 3) {
- notifyErrorListeners("The builtin function \'" + functionName + "\' accepts exactly 3 arguments (from, to, increment)", fnName);
+ if (paramExpression.size() < 2) {
+ notifyErrorListeners("The builtin function \'" + functionName + "\' accepts 3 arguments (from, to, increment), with the first 2 lacking default values", fnName);
return null;
+ } else if (paramExpression.size() > 3) {
+ notifyErrorListeners("The builtin function \'" + functionName + "\' accepts 3 arguments (from, to, increment)", fnName);
}
functionName = "seq";
namespace = DMLProgram.DEFAULT_NAMESPACE;
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/c5f3e71a/src/test/java/org/apache/sysml/test/integration/functions/data/SequenceTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/data/SequenceTest.java b/src/test/java/org/apache/sysml/test/integration/functions/data/SequenceTest.java
index 8e98e4f..c703f4a 100644
--- a/src/test/java/org/apache/sysml/test/integration/functions/data/SequenceTest.java
+++ b/src/test/java/org/apache/sysml/test/integration/functions/data/SequenceTest.java
@@ -19,25 +19,25 @@
package org.apache.sysml.test.integration.functions.data;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.junit.runners.Parameterized.Parameters;
-
import org.apache.sysml.api.DMLScript;
import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
import org.apache.sysml.runtime.matrix.data.MatrixValue.CellIndex;
import org.apache.sysml.test.integration.AutomatedTestBase;
import org.apache.sysml.test.integration.TestConfiguration;
import org.apache.sysml.test.utils.TestUtils;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
/**
- * Tests if Rand produces the same output, for a given set of parameters, across different (CP vs. MR) runtime platforms.
- *
+ * Tests both DML's seq() and PyDML's range() functions
+ * with different numbers of parameters, across different (CP vs. MR)
+ * runtime platforms.
*/
@RunWith(value = Parameterized.class)
public class SequenceTest extends AutomatedTestBase
@@ -53,35 +53,55 @@ public class SequenceTest extends AutomatedTestBase
private TEST_TYPE test_type;
private double from, to, incr;
+ private boolean isPyDml;
- public SequenceTest(TEST_TYPE tp, double f, double t, double i) {
+ public SequenceTest(TEST_TYPE tp, double f, double t, double i, boolean isPyDml) {
//numInputs = ni;
test_type = tp;
from = f;
to = t;
incr = i;
+ this.isPyDml = isPyDml;
}
@Parameters
public static Collection<Object[]> data() {
Object[][] data = new Object[][] {
- // 3 inputs
- {TEST_TYPE.THREE_INPUTS, 1, 2000, 1},
- {TEST_TYPE.THREE_INPUTS, 2000, 1, -1},
- {TEST_TYPE.THREE_INPUTS, 0, 150, 0.1},
- {TEST_TYPE.THREE_INPUTS, 150, 0, -0.1},
- {TEST_TYPE.THREE_INPUTS, 4000, 0, -3},
-
- // 2 inputs
- {TEST_TYPE.TWO_INPUTS, 1, 2000, Double.NaN},
- {TEST_TYPE.TWO_INPUTS, 2000, 1, Double.NaN},
- {TEST_TYPE.TWO_INPUTS, 0, 150, Double.NaN},
- {TEST_TYPE.TWO_INPUTS, 150, 0, Double.NaN},
- {TEST_TYPE.TWO_INPUTS, 4, 4, Double.NaN},
-
- // Error
- {TEST_TYPE.ERROR, 1, 2000, -1},
- {TEST_TYPE.ERROR, 150, 0, 1}
+ // DML - 3 inputs
+ {TEST_TYPE.THREE_INPUTS, 1, 2000, 1, false},
+ {TEST_TYPE.THREE_INPUTS, 2000, 1, -1, false},
+ {TEST_TYPE.THREE_INPUTS, 0, 150, 0.1, false},
+ {TEST_TYPE.THREE_INPUTS, 150, 0, -0.1, false},
+ {TEST_TYPE.THREE_INPUTS, 4000, 0, -3, false},
+
+ // PyDML - 3 inputs
+ {TEST_TYPE.THREE_INPUTS, 1, 2000, 1, true},
+ {TEST_TYPE.THREE_INPUTS, 2000, 1, -1, true},
+ {TEST_TYPE.THREE_INPUTS, 0, 150, 0.1, true},
+ {TEST_TYPE.THREE_INPUTS, 150, 0, -0.1, true},
+ {TEST_TYPE.THREE_INPUTS, 4000, 0, -3, true},
+
+ // DML - 2 inputs
+ {TEST_TYPE.TWO_INPUTS, 1, 2000, Double.NaN, false},
+ {TEST_TYPE.TWO_INPUTS, 2000, 1, Double.NaN, false},
+ {TEST_TYPE.TWO_INPUTS, 0, 150, Double.NaN, false},
+ {TEST_TYPE.TWO_INPUTS, 150, 0, Double.NaN, false},
+ {TEST_TYPE.TWO_INPUTS, 4, 4, Double.NaN, false},
+
+ // PyDML - 2 inputs
+ {TEST_TYPE.TWO_INPUTS, 1, 2000, Double.NaN, true},
+ {TEST_TYPE.TWO_INPUTS, 2000, 1, Double.NaN, true},
+ {TEST_TYPE.TWO_INPUTS, 0, 150, Double.NaN, true},
+ {TEST_TYPE.TWO_INPUTS, 150, 0, Double.NaN, true},
+ {TEST_TYPE.TWO_INPUTS, 4, 4, Double.NaN, true},
+
+ // DML - Error
+ {TEST_TYPE.ERROR, 1, 2000, -1, false},
+ {TEST_TYPE.ERROR, 150, 0, 1, false},
+
+ // PyDML - Error
+ {TEST_TYPE.ERROR, 1, 2000, -1, true},
+ {TEST_TYPE.ERROR, 150, 0, 1, true}
};
return Arrays.asList(data);
}
@@ -105,7 +125,12 @@ public class SequenceTest extends AutomatedTestBase
boolean exceptionExpected = false;
if ( test_type == TEST_TYPE.THREE_INPUTS || test_type == TEST_TYPE.ERROR ) {
- fullDMLScriptName = HOME + TEST_NAME + ".dml";
+ if (isPyDml) {
+ fullDMLScriptName = HOME + "Range" + ".pydml";
+ } else {
+ fullDMLScriptName = HOME + TEST_NAME + ".dml";
+ }
+
fullRScriptName = HOME + TEST_NAME + ".R";
programArgs = new String[]{"-args", Double.toString(from),
@@ -118,7 +143,11 @@ public class SequenceTest extends AutomatedTestBase
exceptionExpected = true;
}
else {
- fullDMLScriptName = HOME + TEST_NAME + "2inputs.dml";
+ if (isPyDml) {
+ fullDMLScriptName = HOME + "Range" + "2inputs.pydml";
+ } else {
+ fullDMLScriptName = HOME + TEST_NAME + "2inputs.dml";
+ }
fullRScriptName = HOME + TEST_NAME + "2inputs.R";
programArgs = new String[]{"-args", Double.toString(from),
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/c5f3e71a/src/test/scripts/functions/data/Range.pydml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/data/Range.pydml b/src/test/scripts/functions/data/Range.pydml
new file mode 100644
index 0000000..b18ee43
--- /dev/null
+++ b/src/test/scripts/functions/data/Range.pydml
@@ -0,0 +1,23 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+X = range($1, $2, $3)
+save(X, $4)
http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/c5f3e71a/src/test/scripts/functions/data/Range2inputs.pydml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/data/Range2inputs.pydml b/src/test/scripts/functions/data/Range2inputs.pydml
new file mode 100644
index 0000000..a85a29a
--- /dev/null
+++ b/src/test/scripts/functions/data/Range2inputs.pydml
@@ -0,0 +1,23 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+X = range($1, $2)
+save(X, $3)