You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by ni...@apache.org on 2016/09/28 22:21:22 UTC

incubator-systemml git commit: [SYSTEMML-957] Bug fix for seq() in for loop

Repository: incubator-systemml
Updated Branches:
  refs/heads/master 07e94fb63 -> fa49ae507


[SYSTEMML-957] Bug fix for seq() in for loop

Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/fa49ae50
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/fa49ae50
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/fa49ae50

Branch: refs/heads/master
Commit: fa49ae507af76c4055ce20aa2237220eaf1e4cf8
Parents: 07e94fb
Author: Niketan Pansare <np...@us.ibm.com>
Authored: Wed Sep 28 15:19:47 2016 -0700
Committer: Niketan Pansare <np...@us.ibm.com>
Committed: Wed Sep 28 15:19:47 2016 -0700

----------------------------------------------------------------------
 .../java/org/apache/sysml/parser/dml/Dml.g4     |  2 +-
 .../sysml/parser/dml/DmlSyntacticValidator.java |  3 +-
 .../java/org/apache/sysml/parser/pydml/Pydml.g4 |  2 +-
 .../parser/pydml/PydmlSyntacticValidator.java   |  3 +-
 .../functions/parfor/ForLoopPredicateTest.java  | 15 ++++++++++
 .../scripts/functions/parfor/for_pred1a_seq.dml | 31 ++++++++++++++++++++
 6 files changed, 52 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fa49ae50/src/main/java/org/apache/sysml/parser/dml/Dml.g4
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/Dml.g4 b/src/main/java/org/apache/sysml/parser/dml/Dml.g4
index f2d0f4e..a3782f2 100644
--- a/src/main/java/org/apache/sysml/parser/dml/Dml.g4
+++ b/src/main/java/org/apache/sysml/parser/dml/Dml.g4
@@ -87,7 +87,7 @@ iterablePredicate returns [ org.apache.sysml.parser.common.ExpressionInfo info ]
          $info = new org.apache.sysml.parser.common.ExpressionInfo();
   } :
     from=expression ':' to=expression #IterablePredicateColonExpression
-    | ID '(' from=expression ',' to=expression ',' increment=expression ')' #IterablePredicateSeqExpression
+    | ID '(' from=expression ',' to=expression (',' increment=expression)? ')' #IterablePredicateSeqExpression
     ;
 
 functionStatement returns [ org.apache.sysml.parser.common.StatementInfo info ]

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fa49ae50/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
index e658a7e..8ff918d 100644
--- a/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/dml/DmlSyntacticValidator.java
@@ -772,7 +772,8 @@ public class DmlSyntacticValidator extends CommonSyntacticValidator implements D
 		}
 		ctx.info.from = ctx.from.info.expr;
 		ctx.info.to = ctx.to.info.expr;
-		ctx.info.increment = ctx.increment.info.expr;
+		if(ctx.increment != null && ctx.increment.info != null)
+			ctx.info.increment = ctx.increment.info.expr;
 	}
 
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fa49ae50/src/main/java/org/apache/sysml/parser/pydml/Pydml.g4
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/parser/pydml/Pydml.g4 b/src/main/java/org/apache/sysml/parser/pydml/Pydml.g4
index 7471f30..320793e 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/Pydml.g4
+++ b/src/main/java/org/apache/sysml/parser/pydml/Pydml.g4
@@ -203,7 +203,7 @@ iterablePredicate returns [ org.apache.sysml.parser.common.ExpressionInfo info ]
          $info = new org.apache.sysml.parser.common.ExpressionInfo();
   } :
     from=expression ':' to=expression #IterablePredicateColonExpression
-    | ID OPEN_PAREN from=expression ',' to=expression ',' increment=expression CLOSE_PAREN #IterablePredicateSeqExpression
+    | ID OPEN_PAREN from=expression ',' to=expression (',' increment=expression)? CLOSE_PAREN #IterablePredicateSeqExpression
     ;
 
 functionStatement returns [ org.apache.sysml.parser.common.StatementInfo info ]

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fa49ae50/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 65a0d97..b8ebdc8 100644
--- a/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
+++ b/src/main/java/org/apache/sysml/parser/pydml/PydmlSyntacticValidator.java
@@ -1370,7 +1370,8 @@ public class PydmlSyntacticValidator extends CommonSyntacticValidator implements
 		}
 		ctx.info.from = ctx.from.info.expr;
 		ctx.info.to = ctx.to.info.expr;
-		ctx.info.increment = ctx.increment.info.expr;
+		if(ctx.increment != null && ctx.increment.info != null)
+			ctx.info.increment = ctx.increment.info.expr;
 	}
 
 

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fa49ae50/src/test/java/org/apache/sysml/test/integration/functions/parfor/ForLoopPredicateTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/parfor/ForLoopPredicateTest.java b/src/test/java/org/apache/sysml/test/integration/functions/parfor/ForLoopPredicateTest.java
index b25bf61..115b4e8 100644
--- a/src/test/java/org/apache/sysml/test/integration/functions/parfor/ForLoopPredicateTest.java
+++ b/src/test/java/org/apache/sysml/test/integration/functions/parfor/ForLoopPredicateTest.java
@@ -37,6 +37,7 @@ public class ForLoopPredicateTest extends AutomatedTestBase
 	private final static String TEST_NAME4 = "for_pred2b"; //var seq
 	private final static String TEST_NAME5 = "for_pred3a"; //expression
 	private final static String TEST_NAME6 = "for_pred3b"; //expression seq
+	private final static String TEST_NAME7 = "for_pred1a_seq"; //const seq two parameters (this tests is only for parser)
 	private final static String TEST_DIR = "functions/parfor/";
 	private final static String TEST_CLASS_DIR = TEST_DIR + ForLoopPredicateTest.class.getSimpleName() + "/";
 	
@@ -53,6 +54,7 @@ public class ForLoopPredicateTest extends AutomatedTestBase
 		addTestConfiguration(TEST_NAME4, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME4, new String[]{"R"}));
 		addTestConfiguration(TEST_NAME5, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME5, new String[]{"R"}));
 		addTestConfiguration(TEST_NAME6, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME6, new String[]{"R"}));
+		addTestConfiguration(TEST_NAME7, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME7, new String[]{"R"}));
 	}
 
 	@Test
@@ -62,6 +64,12 @@ public class ForLoopPredicateTest extends AutomatedTestBase
 	}
 	
 	@Test
+	public void testForConstIntegerSeq2ParametersPredicate() 
+	{
+		runForPredicateTest(7, true);
+	}
+	
+	@Test
 	public void testForConstIntegerSeqPredicate() 
 	{
 		runForPredicateTest(2, true);
@@ -98,6 +106,12 @@ public class ForLoopPredicateTest extends AutomatedTestBase
 	}
 	
 	@Test
+	public void testForConstDoubleSeq2ParametersPredicate() 
+	{
+		runForPredicateTest(7, false);
+	}
+	
+	@Test
 	public void testForConstDoubleSeqPredicate() 
 	{
 		runForPredicateTest(2, false);
@@ -143,6 +157,7 @@ public class ForLoopPredicateTest extends AutomatedTestBase
 			case 4: TEST_NAME = TEST_NAME4; break;
 			case 5: TEST_NAME = TEST_NAME5; break;
 			case 6: TEST_NAME = TEST_NAME6; break;
+			case 7: TEST_NAME = TEST_NAME7; break;
 		}
 		
 		getAndLoadTestConfiguration(TEST_NAME);

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/fa49ae50/src/test/scripts/functions/parfor/for_pred1a_seq.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/parfor/for_pred1a_seq.dml b/src/test/scripts/functions/parfor/for_pred1a_seq.dml
new file mode 100644
index 0000000..9daf781
--- /dev/null
+++ b/src/test/scripts/functions/parfor/for_pred1a_seq.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.
+#
+#-------------------------------------------------------------
+
+
+sum = 0;
+for( i in seq($1, $2) ) 
+{
+   sum = sum + 1; 
+}  
+
+R = matrix(1, rows=1, cols=1);
+R = R * sum;
+write(R, $4);
\ No newline at end of file