You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@systemml.apache.org by mb...@apache.org on 2018/07/17 23:34:45 UTC

[2/2] systemml git commit: [SYSTEMML-2448] Fix sorted check of matrices (e.g., in outer binary)

[SYSTEMML-2448] Fix sorted check of matrices (e.g., in outer binary)

SYSTEMML-1747 introduces an issue where the sorted check returned true
for ordered descending instead of ordered ascending. This led to
incorrect results of certain operations such as outer binary with a
right-hand-side larger than 16 and unnecessary sorting overhead on
operations such as reading matrices. This patch fixes this issue and
introduces tests for theses special cases (decreasing sorted outer ops).


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

Branch: refs/heads/master
Commit: aed46e3b55a1b8a5611d5478fccd29284ce45dcf
Parents: 34482f8
Author: Matthias Boehm <mb...@gmail.com>
Authored: Tue Jul 17 16:36:01 2018 -0700
Committer: Matthias Boehm <mb...@gmail.com>
Committed: Tue Jul 17 16:36:01 2018 -0700

----------------------------------------------------------------------
 .../apache/sysml/runtime/util/SortUtils.java    |   5 +-
 .../FullSortedOuterCompareTest.java             | 160 +++++++++++++++++++
 .../FullSortedOuterCompare.R                    |  35 ++++
 .../FullSortedOuterCompare.dml                  |  24 +++
 .../matrix_full_cellwise/ZPackageSuite.java     |   7 +-
 5 files changed, 225 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/aed46e3b/src/main/java/org/apache/sysml/runtime/util/SortUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/runtime/util/SortUtils.java b/src/main/java/org/apache/sysml/runtime/util/SortUtils.java
index c3dcbaf..3c9f57a 100644
--- a/src/main/java/org/apache/sysml/runtime/util/SortUtils.java
+++ b/src/main/java/org/apache/sysml/runtime/util/SortUtils.java
@@ -28,18 +28,17 @@ import org.apache.sysml.runtime.matrix.data.MatrixBlock;
  */
 public class SortUtils 
 {
-
 	public static boolean isSorted(int start, int end, int[] indexes) {
 		boolean ret = true;
 		for( int i=start+1; i<end && ret; i++ )
-			ret &= (indexes[i]<indexes[i-1]);
+			ret &= (indexes[i-1]<indexes[i]);
 		return ret;
 	}
 
 	public static boolean isSorted(int start, int end, double[] values) {
 		boolean ret = true;
 		for( int i=start+1; i<end && ret; i++ )
-			ret &= (values[i]<values[i-1]);
+			ret &= (values[i-1]<values[i]);
 		return ret;
 	}
 	

http://git-wip-us.apache.org/repos/asf/systemml/blob/aed46e3b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/FullSortedOuterCompareTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/FullSortedOuterCompareTest.java b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/FullSortedOuterCompareTest.java
new file mode 100644
index 0000000..72e121a
--- /dev/null
+++ b/src/test/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/FullSortedOuterCompareTest.java
@@ -0,0 +1,160 @@
+/*
+ * 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.binary.matrix_full_cellwise;
+
+import java.util.HashMap;
+
+import org.junit.Test;
+
+import org.apache.sysml.api.DMLScript;
+import org.apache.sysml.api.DMLScript.RUNTIME_PLATFORM;
+import org.apache.sysml.lops.LopProperties.ExecType;
+import org.apache.sysml.runtime.matrix.MatrixCharacteristics;
+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 FullSortedOuterCompareTest extends AutomatedTestBase 
+{
+	private final static String TEST_NAME = "FullSortedOuterCompare";
+	private final static String TEST_DIR = "functions/binary/matrix_full_cellwise/";
+	private final static String TEST_CLASS_DIR = TEST_DIR + FullSortedOuterCompareTest.class.getSimpleName() + "/";
+	private final static double eps = 1e-10;
+	private final static int rows1 = 1111;
+	
+	@Override
+	public void setUp() {
+		TestUtils.clearAssertionInformation();
+		addTestConfiguration(TEST_NAME, new TestConfiguration(TEST_CLASS_DIR, TEST_NAME, new String[]{"C"}));
+	}
+
+	@Test
+	public void testLessIncreasingCP() {
+		runMatrixVectorCellwiseOperationTest("<", true, ExecType.CP);
+	}
+	
+	@Test
+	public void testLessEqualsIncreasingCP() {
+		runMatrixVectorCellwiseOperationTest("<=", true, ExecType.CP);
+	}
+	
+	@Test
+	public void testGreaterIncreasingCP() {
+		runMatrixVectorCellwiseOperationTest(">", true, ExecType.CP);
+	}
+	
+	@Test
+	public void testGreaterEqualsIncreasingCP() {
+		runMatrixVectorCellwiseOperationTest(">=", true, ExecType.CP);
+	}
+	
+	@Test
+	public void testEqualsIncreasingCP() {
+		runMatrixVectorCellwiseOperationTest("==", true, ExecType.CP);
+	}
+	
+	@Test
+	public void testNotEqualsIncreasingCP() {
+		runMatrixVectorCellwiseOperationTest("!=", true, ExecType.CP);
+	}
+
+	@Test
+	public void testLessIncreasingSP() {
+		runMatrixVectorCellwiseOperationTest("<", true, ExecType.SPARK);
+	}
+	
+	@Test
+	public void testLessEqualsIncreasingSP() {
+		runMatrixVectorCellwiseOperationTest("<=", true, ExecType.SPARK);
+	}
+	
+	@Test
+	public void testGreaterIncreasingSP() {
+		runMatrixVectorCellwiseOperationTest(">", true, ExecType.SPARK);
+	}
+	
+	@Test
+	public void testGreaterEqualsIncreasingSP() {
+		runMatrixVectorCellwiseOperationTest(">=", true, ExecType.SPARK);
+	}
+	
+	@Test
+	public void testEqualsIncreasingSP() {
+		runMatrixVectorCellwiseOperationTest("==", true, ExecType.SPARK);
+	}
+	
+	@Test
+	public void testNotEqualsIncreasingSP() {
+		runMatrixVectorCellwiseOperationTest("!=", true, ExecType.SPARK);
+	}
+	
+	private void runMatrixVectorCellwiseOperationTest( String otype, boolean incr, ExecType et)
+	{
+		//rtplatform for MR
+		RUNTIME_PLATFORM platformOld = rtplatform;
+		switch( et ){
+			case MR: rtplatform = RUNTIME_PLATFORM.HADOOP; break;
+			case SPARK: rtplatform = RUNTIME_PLATFORM.SPARK; break;
+			default: rtplatform = RUNTIME_PLATFORM.HYBRID; break;
+		}
+	
+		boolean sparkConfigOld = DMLScript.USE_LOCAL_SPARK_CONFIG;
+		if( rtplatform == RUNTIME_PLATFORM.SPARK )
+			DMLScript.USE_LOCAL_SPARK_CONFIG = true;
+	
+		try
+		{
+			loadTestConfiguration(getTestConfiguration(TEST_NAME));
+			
+			String HOME = SCRIPT_DIR + TEST_DIR;
+			fullDMLScriptName = HOME + TEST_NAME + ".dml";
+			programArgs = new String[]{"-explain", "recompile_runtime", "-args",
+				String.valueOf(rows1), otype, output("C") };
+			
+			fullRScriptName = HOME + TEST_NAME + ".R";
+			rCmd = "Rscript" + " " + fullRScriptName +" " + String.valueOf(rows1) 
+				+ " " + getSafeOp(otype) + " " + expectedDir();
+			
+			runTest(true, false, null, -1); 
+			runRScript(true); 
+			
+			//compare matrices 
+			HashMap<CellIndex, Double> dmlfile = readDMLMatrixFromHDFS("C");
+			HashMap<CellIndex, Double> rfile  = readRMatrixFromFS("C");
+			TestUtils.compareMatrices(dmlfile, rfile, eps, "Stat-DML", "Stat-R");
+			checkDMLMetaDataFile("C", new MatrixCharacteristics(rows1,rows1,1,1));
+		}
+		finally {
+			rtplatform = platformOld;
+			DMLScript.USE_LOCAL_SPARK_CONFIG = sparkConfigOld;
+		}
+	}
+	
+	private String getSafeOp(String op) {
+		switch(op) {
+			case "<": return "lt";
+			case "<=": return "lte";
+			case ">": return "gt";
+			case ">=": return "gte";
+			default: return op;
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/systemml/blob/aed46e3b/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.R
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.R b/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.R
new file mode 100644
index 0000000..38efd3b
--- /dev/null
+++ b/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.R
@@ -0,0 +1,35 @@
+#-------------------------------------------------------------
+#
+# 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.
+#
+#-------------------------------------------------------------
+
+
+args <- commandArgs(TRUE)
+options(digits=22)
+library("Matrix")
+
+N = as.integer(args[1]);
+A = as.matrix(seq(N,1,-1));
+
+op = ifelse(args[2]=="lt","<",ifelse(args[2]=="lte","<=",ifelse(args[2]=="gt",">",ifelse(args[2]=="gte",">=", args[2])))) 
+
+C = as.matrix(outer(A, t(A), op));
+C = matrix(C, nrow=nrow(A), ncol=nrow(A), byrow=FALSE)
+
+writeMM(as(C, "CsparseMatrix"), paste(args[3], "C", sep="")); 

http://git-wip-us.apache.org/repos/asf/systemml/blob/aed46e3b/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.dml
----------------------------------------------------------------------
diff --git a/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.dml b/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.dml
new file mode 100644
index 0000000..ead778a
--- /dev/null
+++ b/src/test/scripts/functions/binary/matrix_full_cellwise/FullSortedOuterCompare.dml
@@ -0,0 +1,24 @@
+#-------------------------------------------------------------
+#
+# 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 = seq($1,1,-1);
+C = outer(A, t(A), $2);
+write(C, $3);

http://git-wip-us.apache.org/repos/asf/systemml/blob/aed46e3b/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/ZPackageSuite.java
----------------------------------------------------------------------
diff --git a/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/ZPackageSuite.java b/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/ZPackageSuite.java
index 7f4a740..eb5c418 100644
--- a/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/ZPackageSuite.java
+++ b/src/test_suites/java/org/apache/sysml/test/integration/functions/binary/matrix_full_cellwise/ZPackageSuite.java
@@ -25,13 +25,14 @@ import org.junit.runners.Suite;
 /** Group together the tests in this package into a single suite so that the Maven build
  *  won't run two of them at once. */
 @RunWith(Suite.class)
-@Suite.SuiteClasses({	
+@Suite.SuiteClasses({
 	FullMatrixMatrixCellwiseOperationTest.class,
 	FullMatrixVectorColCellwiseOperationTest.class,
 	FullMatrixVectorRowCellwiseOperationTest.class,
-	FullVectorVectorCellwiseOperationTest.class,
-	FullVectorVectorCellwiseCompareOperationTest.class,
 	FullMinus1MultTest.class,
+	FullSortedOuterCompareTest.class,
+	FullVectorVectorCellwiseCompareOperationTest.class,
+	FullVectorVectorCellwiseOperationTest.class,
 })