use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class QuaternaryInstruction method processInstruction.
@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) throws DMLRuntimeException {
QuaternaryOperator qop = (QuaternaryOperator) optr;
ArrayList<IndexedMatrixValue> blkList = cachedValues.get(_input1);
if (blkList != null)
for (IndexedMatrixValue imv : blkList) {
//Step 1: prepare inputs and output
if (imv == null)
continue;
MatrixIndexes inIx = imv.getIndexes();
MatrixValue inVal = imv.getValue();
//allocate space for the output value
IndexedMatrixValue iout = null;
if (output == _input1)
iout = tempValue;
else
iout = cachedValues.holdPlace(output, valueClass);
MatrixIndexes outIx = iout.getIndexes();
MatrixValue outVal = iout.getValue();
//Step 2: get remaining inputs: Wij, Ui, Vj
MatrixValue Xij = inVal;
//get Wij if existing (null of WeightsType.NONE or WSigmoid any type)
IndexedMatrixValue iWij = (_input4 != -1) ? cachedValues.getFirst(_input4) : null;
MatrixValue Wij = (iWij != null) ? iWij.getValue() : null;
if (null == Wij && qop.hasFourInputs()) {
MatrixBlock mb = new MatrixBlock(1, 1, false);
String[] parts = InstructionUtils.getInstructionParts(instString);
mb.quickSetValue(0, 0, Double.valueOf(parts[4]));
Wij = mb;
}
//get Ui and Vj, potentially through distributed cache
MatrixValue Ui = //U
(!_cacheU) ? //U
cachedValues.getFirst(_input2).getValue() : MRBaseForCommonInstructions.dcValues.get(_input2).getDataBlock((int) inIx.getRowIndex(), 1).getValue();
MatrixValue Vj = //t(V)
(!_cacheV) ? //t(V)
cachedValues.getFirst(_input3).getValue() : MRBaseForCommonInstructions.dcValues.get(_input3).getDataBlock((int) inIx.getColumnIndex(), 1).getValue();
//handle special input case: //V through shuffle -> t(V)
if (Ui.getNumColumns() != Vj.getNumColumns()) {
Vj = LibMatrixReorg.reorg((MatrixBlock) Vj, new MatrixBlock(Vj.getNumColumns(), Vj.getNumRows(), Vj.isInSparseFormat()), new ReorgOperator(SwapIndex.getSwapIndexFnObject()));
}
//Step 3: process instruction
Xij.quaternaryOperations(qop, Ui, Vj, Wij, outVal);
if (qop.wtype1 != null || qop.wtype4 != null)
//wsloss
outIx.setIndexes(1, 1);
else if (qop.wtype2 != null || qop.wtype5 != null || qop.wtype3 != null && qop.wtype3.isBasic())
//wsigmoid/wdivmm-basic
outIx.setIndexes(inIx);
else {
//wdivmm
boolean left = qop.wtype3.isLeft();
outIx.setIndexes(left ? inIx.getColumnIndex() : inIx.getRowIndex(), 1);
}
//put the output value in the cache
if (iout == tempValue)
cachedValues.add(output, iout);
}
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class ReorgInstruction method parseInstruction.
public static ReorgInstruction parseInstruction(String str) throws DMLRuntimeException {
InstructionUtils.checkNumFields(str, 2);
String[] parts = InstructionUtils.getInstructionParts(str);
byte in, out;
String opcode = parts[0];
in = Byte.parseByte(parts[1]);
out = Byte.parseByte(parts[2]);
if (opcode.equalsIgnoreCase("r'")) {
return new ReorgInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), in, out, str);
} else if (opcode.equalsIgnoreCase("rev")) {
return new ReorgInstruction(new ReorgOperator(RevIndex.getRevIndexFnObject()), in, out, str);
} else if (opcode.equalsIgnoreCase("rdiag")) {
return new ReorgInstruction(new ReorgOperator(DiagIndex.getDiagIndexFnObject()), in, out, str);
} else {
throw new DMLRuntimeException("Unknown opcode while parsing a ReorgInstruction: " + str);
}
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class AppendMSPInstruction method parseInstruction.
public static AppendMSPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand offset = new CPOperand(parts[3]);
CPOperand out = new CPOperand(parts[4]);
boolean cbind = Boolean.parseBoolean(parts[5]);
if (!opcode.equalsIgnoreCase("mappend"))
throw new DMLRuntimeException("Unknown opcode while parsing a AppendMSPInstruction: " + str);
//construct matrix/frame appendm instruction
if (in1.getDataType().isMatrix()) {
return new MatrixAppendMSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, offset, out, cbind, opcode, str);
} else {
//frame
return new FrameAppendMSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, offset, out, cbind, opcode, str);
}
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class AppendGAlignedSPInstruction method parseInstruction.
public static AppendGAlignedSPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand in3 = new CPOperand(parts[3]);
CPOperand out = new CPOperand(parts[4]);
boolean cbind = Boolean.parseBoolean(parts[5]);
if (!opcode.equalsIgnoreCase("galignedappend"))
throw new DMLRuntimeException("Unknown opcode while parsing a AppendGSPInstruction: " + str);
return new AppendGAlignedSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, in3, out, cbind, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class AppendGSPInstruction method parseInstruction.
public static AppendGSPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 6);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand in3 = new CPOperand(parts[3]);
CPOperand in4 = new CPOperand(parts[4]);
CPOperand out = new CPOperand(parts[5]);
boolean cbind = Boolean.parseBoolean(parts[6]);
if (!opcode.equalsIgnoreCase("gappend"))
throw new DMLRuntimeException("Unknown opcode while parsing a AppendGSPInstruction: " + str);
return new AppendGSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, in3, in4, out, cbind, opcode, str);
}
Aggregations