use of org.apache.sysml.runtime.instructions.cp.VariableCPInstruction in project incubator-systemml by apache.
the class Dag method collapseAssignvarAndRmvarInstructions.
private static ArrayList<Instruction> collapseAssignvarAndRmvarInstructions(ArrayList<Instruction> insts) {
ArrayList<Instruction> ret = new ArrayList<>();
Iterator<Instruction> iter = insts.iterator();
while (iter.hasNext()) {
Instruction inst = iter.next();
if (iter.hasNext() && inst instanceof VariableCPInstruction && ((VariableCPInstruction) inst).isAssignVariable()) {
VariableCPInstruction inst1 = (VariableCPInstruction) inst;
Instruction inst2 = iter.next();
if (inst2 instanceof VariableCPInstruction && ((VariableCPInstruction) inst2).isRemoveVariableNoFile() && inst1.getInput1().getName().equals(((VariableCPInstruction) inst2).getInput1().getName())) {
ret.add(VariableCPInstruction.prepareMoveInstruction(inst1.getInput1().getName(), inst1.getInput2().getName()));
} else {
ret.add(inst1);
ret.add(inst2);
}
} else {
ret.add(inst);
}
}
return ret;
}
use of org.apache.sysml.runtime.instructions.cp.VariableCPInstruction in project incubator-systemml by apache.
the class Dag method createPackedRmvarInstructions.
private static ArrayList<Instruction> createPackedRmvarInstructions(ArrayList<Instruction> insts) {
ArrayList<Instruction> ret = new ArrayList<>();
ArrayList<String> currRmVar = new ArrayList<>();
for (Instruction inst : insts) {
if (inst instanceof VariableCPInstruction && ((VariableCPInstruction) inst).isRemoveVariableNoFile()) {
// collect all subsequent rmvar instructions
currRmVar.add(((VariableCPInstruction) inst).getInput1().getName());
} else {
// construct packed rmvar instruction
if (!currRmVar.isEmpty()) {
ret.add(VariableCPInstruction.prepareRemoveInstruction(currRmVar.toArray(new String[0])));
currRmVar.clear();
}
// add other instruction
ret.add(inst);
}
}
// construct last packed rmvar instruction
if (!currRmVar.isEmpty()) {
ret.add(VariableCPInstruction.prepareRemoveInstruction(currRmVar.toArray(new String[0])));
}
return ret;
}
Aggregations