[SYSTEMML-2158] Fix size propagation nary rbind (incorrect rows/cols) This patch fixes a size propagation issue of the recently introduced nary rbind. Specifically, the rows and column dimensions where mixed up when propagating sizes during IPA or dynamic recompilation. This fixes potential result correctness issues because nrow(X) might be compiled into the program whenever we are able to exactly infer the sizes.
Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/9481bef4 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/9481bef4 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/9481bef4 Branch: refs/heads/master Commit: 9481bef4e2b6e4caf0b0692b8f8e00120b434db1 Parents: 14ea51b Author: Matthias Boehm <[email protected]> Authored: Wed Feb 21 22:30:06 2018 -0800 Committer: Matthias Boehm <[email protected]> Committed: Wed Feb 21 22:30:06 2018 -0800 ---------------------------------------------------------------------- src/main/java/org/apache/sysml/hops/NaryOp.java | 4 +- .../misc/SizePropagationRBindTest.java | 83 ++++++++++++++++++++ .../functions/misc/SizePropagationRBind.dml | 29 +++++++ .../functions/misc/ZPackageSuite.java | 1 + 4 files changed, 115 insertions(+), 2 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/9481bef4/src/main/java/org/apache/sysml/hops/NaryOp.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/sysml/hops/NaryOp.java b/src/main/java/org/apache/sysml/hops/NaryOp.java index cc90044..bc3b163 100644 --- a/src/main/java/org/apache/sysml/hops/NaryOp.java +++ b/src/main/java/org/apache/sysml/hops/NaryOp.java @@ -183,8 +183,8 @@ public class NaryOp extends Hop { setDim2(HopRewriteUtils.getSumValidInputDims(this, false)); break; case RBIND: - setDim1(HopRewriteUtils.getSumValidInputDims(this, false)); - setDim2(HopRewriteUtils.getMaxInputDim(this, true)); + setDim1(HopRewriteUtils.getSumValidInputDims(this, true)); + setDim2(HopRewriteUtils.getMaxInputDim(this, false)); break; case PRINTF: //do nothing: http://git-wip-us.apache.org/repos/asf/systemml/blob/9481bef4/src/test/java/org/apache/sysml/test/integration/functions/misc/SizePropagationRBindTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/sysml/test/integration/functions/misc/SizePropagationRBindTest.java b/src/test/java/org/apache/sysml/test/integration/functions/misc/SizePropagationRBindTest.java new file mode 100644 index 0000000..bde8fc7 --- /dev/null +++ b/src/test/java/org/apache/sysml/test/integration/functions/misc/SizePropagationRBindTest.java @@ -0,0 +1,83 @@ +/* + * 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.sysml.test.integration.functions.misc; + +import org.junit.Test; + +import org.junit.Assert; + +import java.util.HashMap; + +import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM; +import org.apache.sysml.hops.OptimizerUtils; +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; + +public class SizePropagationRBindTest extends AutomatedTestBase +{ + private static final String TEST_NAME1 = "SizePropagationRBind"; + + private static final String TEST_DIR = "functions/misc/"; + private static final String TEST_CLASS_DIR = TEST_DIR + SizePropagationRBindTest.class.getSimpleName() + "/"; + + private static final int N = 100; + + @Override + public void setUp() { + TestUtils.clearAssertionInformation(); + addTestConfiguration( TEST_NAME1, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME1, new String[] { "R" }) ); + } + + @Test + public void testSizePropagationRBindNoRewrites() { + testSizePropagationRBind( TEST_NAME1, false ); + } + + @Test + public void testSizePropagationRBindRewrites() { + testSizePropagationRBind( TEST_NAME1, true ); + } + + private void testSizePropagationRBind( String testname, boolean rewrites ) { + boolean oldFlag = OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION; + RUNTIME_PLATFORM oldPlatform = rtplatform; + + try { + TestConfiguration config = getTestConfiguration(testname); + loadTestConfiguration(config); + + String HOME = SCRIPT_DIR + TEST_DIR; + fullDMLScriptName = HOME + testname + ".dml"; + programArgs = new String[]{ "-stats","-args", String.valueOf(N), output("R") }; + OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = rewrites; + rtplatform = RUNTIME_PLATFORM.SINGLE_NODE; + + runTest(true, false, null, -1); + HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("R"); + Assert.assertTrue( dmlfile.get(new CellIndex(1,1))==2*(N+2) ); + } + finally { + OptimizerUtils.ALLOW_ALGEBRAIC_SIMPLIFICATION = oldFlag; + rtplatform = oldPlatform; + } + } +} http://git-wip-us.apache.org/repos/asf/systemml/blob/9481bef4/src/test/scripts/functions/misc/SizePropagationRBind.dml ---------------------------------------------------------------------- diff --git a/src/test/scripts/functions/misc/SizePropagationRBind.dml b/src/test/scripts/functions/misc/SizePropagationRBind.dml new file mode 100644 index 0000000..43ad3c1 --- /dev/null +++ b/src/test/scripts/functions/misc/SizePropagationRBind.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +A = matrix(0,0,1); +for(i in 1:$1) + A = rbind(A, matrix(1,1,1)); +A = rbind(matrix(1,1,1), matrix(1,1,1), A); +print(nrow(A)); + +R = as.matrix(sum(A)+nrow(A)) +write(R, $2); http://git-wip-us.apache.org/repos/asf/systemml/blob/9481bef4/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java ---------------------------------------------------------------------- diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java index 9fbb2a3..80db7c7 100644 --- a/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java +++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/misc/ZPackageSuite.java @@ -73,6 +73,7 @@ import org.junit.runners.Suite; ScalarMatrixUnaryBinaryTermTest.class, ScalarToMatrixInLoopTest.class, SetWorkingDirTest.class, + SizePropagationRBindTest.class, ToStringTest.class, ValueTypeAutoCastingTest.class, ValueTypeCastingTest.class,
