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 2017/07/15 04:15:37 UTC

[11/23] systemml git commit: Review comments, part 2

Review comments, part 2


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

Branch: refs/heads/master
Commit: d6d37952bdb1cd76d61c376b2051292ca272ee0a
Parents: 737f93b
Author: Dylan Hutchison <dh...@cs.washington.edu>
Authored: Sun Jun 11 02:27:34 2017 -0700
Committer: Dylan Hutchison <dh...@cs.washington.edu>
Committed: Sun Jun 18 17:43:45 2017 -0700

----------------------------------------------------------------------
 .../sysml/hops/rewrite/HopRewriteUtils.java     | 23 +++++-------
 ...RewriteElementwiseMultChainOptimization.java | 38 +++++++-------------
 .../java/org/apache/sysml/utils/Explain.java    |  2 +-
 3 files changed, 22 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/systemml/blob/d6d37952/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
index 8f71359..b98901a 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/HopRewriteUtils.java
@@ -246,22 +246,15 @@ public class HopRewriteUtils
 	 * Replace an old Hop with a replacement Hop.
 	 * If the old Hop has no parents, then return the replacement.
 	 * Otherwise rewire each of the Hop's parents into the replacement and return the replacement.
-	 * @param old To be replaced
-	 * @param replacement The replacement
-	 * @return replacement
+	 * @param hold To be replaced
+	 * @param hnew The replacement
+	 * @return hnew
 	 */
-	public static Hop replaceHop(final Hop old, final Hop replacement) {
-		if (old.getParent().isEmpty())
-			return replacement; // new old!
-		HopRewriteUtils.rewireAllParentChildReferences(old, replacement);
-		return replacement;
-	}
-
-
-	public static void rewireAllParentChildReferences( Hop hold, Hop hnew ) {
-		ArrayList<Hop> parents = new ArrayList<Hop>(hold.getParent());
-		for( Hop lparent : parents )
-			HopRewriteUtils.replaceChildReference(lparent, hold, hnew);
+	public static Hop rewireAllParentChildReferences( Hop hold, Hop hnew ) {
+		ArrayList<Hop> parents = hold.getParent();
+		while (!parents.isEmpty())
+			HopRewriteUtils.replaceChildReference(parents.get(0), hold, hnew);
+		return hnew;
 	}
 	
 	public static void replaceChildReference( Hop parent, Hop inOld, Hop inNew ) {

http://git-wip-us.apache.org/repos/asf/systemml/blob/d6d37952/src/main/java/org/apache/sysml/hops/rewrite/RewriteElementwiseMultChainOptimization.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/hops/rewrite/RewriteElementwiseMultChainOptimization.java b/src/main/java/org/apache/sysml/hops/rewrite/RewriteElementwiseMultChainOptimization.java
index 1dd5813..91b7306 100644
--- a/src/main/java/org/apache/sysml/hops/rewrite/RewriteElementwiseMultChainOptimization.java
+++ b/src/main/java/org/apache/sysml/hops/rewrite/RewriteElementwiseMultChainOptimization.java
@@ -98,7 +98,7 @@ public class RewriteElementwiseMultChainOptimization extends HopRewriteRule {
 								emults.size(), root.getHopID(), replacement.getHopID()));
 
 					// 5. Replace root with replacement
-					final Hop newRoot = HopRewriteUtils.replaceHop(root, replacement);
+					final Hop newRoot = HopRewriteUtils.rewireAllParentChildReferences(root, replacement);
 
 					// 6. Recurse at leaves (no need to repeat the interior emults)
 					for (final Hop leaf : leaves.elementSet()) {
@@ -166,6 +166,18 @@ public class RewriteElementwiseMultChainOptimization extends HopRewriteRule {
 	 * Disambiguate by Hop ID.
 	 */
 	private static final Comparator<Hop> compareByDataType = new Comparator<Hop>() {
+		private final int[] orderDataType = new int[Expression.DataType.values().length];
+		{
+			for (int i = 0, valuesLength = Expression.DataType.values().length; i < valuesLength; i++)
+				switch(Expression.DataType.values()[i]) {
+				case SCALAR: orderDataType[i] = 4; break;
+				case MATRIX: orderDataType[i] = 3; break;
+				case FRAME:  orderDataType[i] = 2; break;
+				case OBJECT: orderDataType[i] = 1; break;
+				case UNKNOWN:orderDataType[i] = 0; break;
+				}
+		}
+
 		@Override
 		public final int compare(Hop o1, Hop o2) {
 			int c = Integer.compare(orderDataType[o1.getDataType().ordinal()], orderDataType[o2.getDataType().ordinal()]);
@@ -198,30 +210,6 @@ public class RewriteElementwiseMultChainOptimization extends HopRewriteRule {
 			if (c != 0) return c;
 			return Long.compare(o1.getHopID(), o2.getHopID());
 		}
-		private final int[] orderDataType;
-		{
-			Expression.DataType[] dtValues = Expression.DataType.values();
-			orderDataType = new int[dtValues.length];
-			for (int i = 0, valuesLength = dtValues.length; i < valuesLength; i++) {
-				switch(dtValues[i]) {
-				case SCALAR:
-					orderDataType[i] = 4;
-					break;
-				case MATRIX:
-					orderDataType[i] = 3;
-					break;
-				case FRAME:
-					orderDataType[i] = 2;
-					break;
-				case OBJECT:
-					orderDataType[i] = 1;
-					break;
-				case UNKNOWN:
-					orderDataType[i] = 0;
-					break;
-				}
-			}
-		}
 	}.reversed();
 
 	/**

http://git-wip-us.apache.org/repos/asf/systemml/blob/d6d37952/src/main/java/org/apache/sysml/utils/Explain.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/utils/Explain.java b/src/main/java/org/apache/sysml/utils/Explain.java
index 450c6e5..6451396 100644
--- a/src/main/java/org/apache/sysml/utils/Explain.java
+++ b/src/main/java/org/apache/sysml/utils/Explain.java
@@ -76,7 +76,7 @@ public class Explain
 	//internal configuration parameters
 	private static final boolean REPLACE_SPECIAL_CHARACTERS = true;	
 	private static final boolean SHOW_MEM_ABOVE_BUDGET      = true;
-	private static final boolean SHOW_LITERAL_HOPS          = true;
+	private static final boolean SHOW_LITERAL_HOPS          = false;
 	private static final boolean SHOW_DATA_DEPENDENCIES     = true;
 	private static final boolean SHOW_DATA_FLOW_PROPERTIES  = true;