-
Notifications
You must be signed in to change notification settings - Fork 478
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYSTEMDS-3804] New rewrite for reverse sequences
This patch adds a new rewrite rev(seq(1,n)) -> seq(n,1), a pattern we recently saw in a script on vectorized time series forecasting.
- Loading branch information
Showing
3 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/org/apache/sysds/test/functions/rewrite/RewriteRemoveUnnecessaryRevTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.sysds.test.functions.rewrite; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import org.apache.sysds.hops.OptimizerUtils; | ||
import org.apache.sysds.test.AutomatedTestBase; | ||
import org.apache.sysds.test.TestConfiguration; | ||
import org.apache.sysds.test.TestUtils; | ||
import org.apache.sysds.runtime.matrix.data.MatrixValue.CellIndex; | ||
|
||
public class RewriteRemoveUnnecessaryRevTest extends AutomatedTestBase | ||
{ | ||
private static final String TEST_NAME1 = "RewriteRemoveUnnecessaryRev"; | ||
|
||
private static final String TEST_DIR = "functions/rewrite/"; | ||
private static final String TEST_CLASS_DIR = TEST_DIR + RewritePushdownSumBinaryMult.class.getSimpleName() + "/"; | ||
|
||
@Override | ||
public void setUp() { | ||
TestUtils.clearAssertionInformation(); | ||
addTestConfiguration( TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "R" }) ); | ||
} | ||
|
||
@Test | ||
public void testRemoveSeqRevRewrite() { | ||
testRewriteRemoveSeqRev( TEST_NAME1, true ); | ||
} | ||
|
||
@Test | ||
public void testRemoveSeqRevNoRewrite() { | ||
testRewriteRemoveSeqRev( TEST_NAME1, false ); | ||
} | ||
|
||
private void testRewriteRemoveSeqRev( String testname, boolean rewrites ) | ||
{ | ||
boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION; | ||
int rows = 1001; | ||
|
||
try | ||
{ | ||
TestConfiguration config = getTestConfiguration(testname); | ||
loadTestConfiguration(config); | ||
|
||
String HOME = SCRIPT_DIR + TEST_DIR; | ||
fullDMLScriptName = HOME + testname + ".dml"; | ||
programArgs = new String[]{ "-stats","-args", String.valueOf(rows), output("Scalar") }; | ||
OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites; | ||
|
||
runTest(true, false, null, -1); | ||
|
||
//compare scalars | ||
int ret = (int)readDMLScalarFromOutputDir("Scalar").get(new CellIndex(1,1)).doubleValue(); | ||
Assert.assertEquals(ret, rows*(rows+1)/2); | ||
if( rewrites ) | ||
Assert.assertFalse(heavyHittersContainsString("rev")); | ||
} | ||
finally { | ||
OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/test/scripts/functions/rewrite/RewriteRemoveUnnecessaryRev.dml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. | ||
# | ||
#------------------------------------------------------------- | ||
|
||
rows = $1; | ||
|
||
# to be rewritten to: seq(rows,1) | ||
X = rev(seq(1,rows)) | ||
|
||
while(FALSE){} | ||
|
||
R = sum(X); | ||
write(R, $2) | ||
|