Search in sources :

Example 1 with ReorgOperator

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);
        }
}
Also used : QuaternaryOperator(org.apache.sysml.runtime.matrix.operators.QuaternaryOperator) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue) MatrixValue(org.apache.sysml.runtime.matrix.data.MatrixValue) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 2 with ReorgOperator

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);
    }
}
Also used : ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 3 with ReorgOperator

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);
    }
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 4 with ReorgOperator

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);
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Example 5 with ReorgOperator

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);
}
Also used : CPOperand(org.apache.sysml.runtime.instructions.cp.CPOperand) ReorgOperator(org.apache.sysml.runtime.matrix.operators.ReorgOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

ReorgOperator (org.apache.sysml.runtime.matrix.operators.ReorgOperator)17 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)10 CPOperand (org.apache.sysml.runtime.instructions.cp.CPOperand)6 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)4 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)3 SortIndex (org.apache.sysml.runtime.functionobjects.SortIndex)2 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)2 ArrayList (java.util.ArrayList)1 SparkExecutionContext (org.apache.sysml.runtime.controlprogram.context.SparkExecutionContext)1 DiagIndex (org.apache.sysml.runtime.functionobjects.DiagIndex)1 RevIndex (org.apache.sysml.runtime.functionobjects.RevIndex)1 PartitionedBlock (org.apache.sysml.runtime.instructions.spark.data.PartitionedBlock)1 RowMatrixBlock (org.apache.sysml.runtime.instructions.spark.data.RowMatrixBlock)1 MatrixValue (org.apache.sysml.runtime.matrix.data.MatrixValue)1 Operator (org.apache.sysml.runtime.matrix.operators.Operator)1 QuaternaryOperator (org.apache.sysml.runtime.matrix.operators.QuaternaryOperator)1