Repository: incubator-systemml
Updated Branches:
  refs/heads/master 0bff338bc -> 82b51425e


Cleanup unnecessary code duplication in jmlc and mlcontext apis

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

Branch: refs/heads/master
Commit: 29d510816358d6b24ac17473970ca5ff67400122
Parents: 0bff338
Author: Matthias Boehm <[email protected]>
Authored: Thu Mar 10 14:39:33 2016 -0800
Committer: Matthias Boehm <[email protected]>
Committed: Thu Mar 10 14:39:33 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/sysml/api/MLContext.java    | 31 +-------------
 .../org/apache/sysml/api/jmlc/JMLCUtils.java    | 43 ++++++++++++--------
 2 files changed, 29 insertions(+), 45 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/29d51081/src/main/java/org/apache/sysml/api/MLContext.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/MLContext.java 
b/src/main/java/org/apache/sysml/api/MLContext.java
index 11d3327..7585e73 100644
--- a/src/main/java/org/apache/sysml/api/MLContext.java
+++ b/src/main/java/org/apache/sysml/api/MLContext.java
@@ -63,7 +63,6 @@ import 
org.apache.sysml.runtime.controlprogram.context.ExecutionContextFactory;
 import org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext;
 import org.apache.sysml.runtime.instructions.Instruction;
 import org.apache.sysml.runtime.instructions.cp.Data;
-import org.apache.sysml.runtime.instructions.cp.VariableCPInstruction;
 import org.apache.sysml.runtime.instructions.spark.data.RDDObject;
 import org.apache.sysml.runtime.instructions.spark.data.RDDProperties;
 import 
org.apache.sysml.runtime.instructions.spark.functions.ConvertStringToLongTextPair;
@@ -980,34 +979,8 @@ public class MLContext {
         * @return
         */
        ArrayList<Instruction> 
performCleanupAfterRecompilation(ArrayList<Instruction> tmp) {
-               String [] outputs = null;
-               if(_outVarnames != null) {
-                       outputs = _outVarnames.toArray(new String[0]);
-               }
-               else {
-                       outputs = new String[0];
-               }
-               
-               // No need to clean up entire program as this method is only 
called for last level program block
-//             JMLCUtils.cleanupRuntimeProgram(_rtprog, outputs);
-               
-               for( int i=0; i<tmp.size(); i++ )
-               {
-                       Instruction linst = tmp.get(i);
-                       if( linst instanceof VariableCPInstruction && 
((VariableCPInstruction)linst).isRemoveVariable() )
-                       {
-                               VariableCPInstruction varinst = 
(VariableCPInstruction) linst;
-                               for( String var : outputs )
-                                       if( varinst.isRemoveVariable(var) )
-                                       {
-                                               tmp.remove(i);
-                                               i--;
-                                               break;
-                                       }
-                       }
-               }
-               
-               return tmp;
+               String [] outputs = (_outVarnames != null) ? 
_outVarnames.toArray(new String[0]) : new String[0];
+               return JMLCUtils.cleanupRuntimeInstructions(tmp, outputs);
        }
        
        // -------------------------------- Utility methods ends 
----------------------------------------------------------

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/29d51081/src/main/java/org/apache/sysml/api/jmlc/JMLCUtils.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/jmlc/JMLCUtils.java 
b/src/main/java/org/apache/sysml/api/jmlc/JMLCUtils.java
index 6e38de2..8c9a6ae 100644
--- a/src/main/java/org/apache/sysml/api/jmlc/JMLCUtils.java
+++ b/src/main/java/org/apache/sysml/api/jmlc/JMLCUtils.java
@@ -34,8 +34,6 @@ import 
org.apache.sysml.runtime.instructions.cp.VariableCPInstruction;
 
 public class JMLCUtils 
 {
-       
-       
        /**
         * Removes rmvar instructions that would remove any of the given 
outputs.
         * This is important for keeping registered outputs after the program 
terminates.
@@ -64,7 +62,7 @@ public class JMLCUtils
         * @param pb
         * @param outputs
         */
-       private static void rCleanupRuntimeProgram( ProgramBlock pb, String[] 
outputs )
+       public static void rCleanupRuntimeProgram( ProgramBlock pb, String[] 
outputs )
        {
                if( pb instanceof WhileProgramBlock )
                {
@@ -89,21 +87,34 @@ public class JMLCUtils
                else
                {
                        ArrayList<Instruction> tmp = pb.getInstructions();
-                       for( int i=0; i<tmp.size(); i++ )
+                       cleanupRuntimeInstructions(tmp, outputs);
+               }
+       }
+       
+       /**
+        * 
+        * @param insts
+        * @param outputs
+        * @return
+        */
+       public static ArrayList<Instruction> cleanupRuntimeInstructions( 
ArrayList<Instruction> insts, String[] outputs )
+       {               
+               for( int i=0; i<insts.size(); i++ )
+               {
+                       Instruction linst = insts.get(i);
+                       if( linst instanceof VariableCPInstruction && 
((VariableCPInstruction)linst).isRemoveVariable() )
                        {
-                               Instruction linst = tmp.get(i);
-                               if( linst instanceof VariableCPInstruction && 
((VariableCPInstruction)linst).isRemoveVariable() )
-                               {
-                                       VariableCPInstruction varinst = 
(VariableCPInstruction) linst;
-                                       for( String var : outputs )
-                                               if( 
varinst.isRemoveVariable(var) )
-                                               {
-                                                       tmp.remove(i);
-                                                       i--;
-                                                       break;
-                                               }
-                               }
+                               VariableCPInstruction varinst = 
(VariableCPInstruction) linst;
+                               for( String var : outputs )
+                                       if( varinst.isRemoveVariable(var) )
+                                       {
+                                               insts.remove(i);
+                                               i--;
+                                               break;
+                                       }
                        }
                }
+               
+               return insts;
        }
 }

Reply via email to