Search in sources :

Example 6 with MatrixValue

use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.

the class MMCJMRReducerWithAggregator method processJoin.

private void processJoin(int tag, long inIndex, MatrixValue inValue) throws IOException {
    try {
        if (// for the cached matrix
        tag == 0) {
            cache.put(inIndex, inValue);
        } else // for the probing matrix
        {
            for (int i = 0; i < cache.getCacheSize(); i++) {
                Pair<MatrixIndexes, MatrixValue> tmp = cache.get(i);
                if (// left cached
                tagForLeft == 0) {
                    // perform matrix multiplication
                    indexesbuffer.setIndexes(tmp.getKey().getRowIndex(), inIndex);
                    OperationsOnMatrixValues.performAggregateBinaryIgnoreIndexes((MatrixBlock) tmp.getValue(), (MatrixBlock) inValue, (MatrixBlock) valueBuffer, (AggregateBinaryOperator) aggBinInstruction.getOperator());
                } else // right cached
                {
                    // perform matrix multiplication
                    indexesbuffer.setIndexes(inIndex, tmp.getKey().getColumnIndex());
                    OperationsOnMatrixValues.performAggregateBinaryIgnoreIndexes((MatrixBlock) inValue, (MatrixBlock) tmp.getValue(), (MatrixBlock) valueBuffer, (AggregateBinaryOperator) aggBinInstruction.getOperator());
                }
                // aggregate block to output buffer or direct output
                if (aggBinInstruction.getMMCJType() == MMCJType.AGG) {
                    aggregator.aggregateToBuffer(indexesbuffer, valueBuffer, tagForLeft == 0);
                } else {
                    // MMCJType.NO_AGG
                    collectFinalMultipleOutputs.collectOutput(indexesbuffer, valueBuffer, 0, cachedReporter);
                    resultsNonZeros[0] += valueBuffer.getNonZeros();
                }
            }
        }
    } catch (Exception ex) {
        throw new IOException(ex);
    }
}
Also used : MatrixValue(org.apache.sysml.runtime.matrix.data.MatrixValue) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) IOException(java.io.IOException) IOException(java.io.IOException)

Example 7 with MatrixValue

use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.

the class AppendMInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
    ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input1);
    if (blkList == null)
        return;
    // right now this only deals with appending matrix with number of column <= blockColFactor
    for (IndexedMatrixValue in1 : blkList) {
        if (in1 == null)
            continue;
        // check for boundary block w/ awareness of zero rows or columns
        int blen = _cbind ? blockColFactor : blockRowFactor;
        long lastBlockColIndex = Math.max((long) Math.ceil((double) _offset / blen), 1);
        // case 1: pass through of non-boundary blocks
        MatrixIndexes ix = in1.getIndexes();
        if ((_cbind ? ix.getColumnIndex() : ix.getRowIndex()) != lastBlockColIndex) {
            cachedValues.add(output, in1);
        } else // case 2: pass through full input block and rhs block
        if (_cbind && in1.getValue().getNumColumns() == blen || !_cbind && in1.getValue().getNumRows() == blen) {
            // output lhs block
            cachedValues.add(output, in1);
            // output shallow copy of rhs block
            DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
            if (_cbind) {
                cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex(), ix.getColumnIndex() + 1), dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue()));
            } else {
                cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(ix.getRowIndex() + 1, ix.getColumnIndex()), dcInput.getDataBlock(1, (int) ix.getColumnIndex()).getValue()));
            }
        } else // case 3: append operation on boundary block
        {
            DistributedCacheInput dcInput = MRBaseForCommonInstructions.dcValues.get(input2);
            // allocate space for the output value
            ArrayList<IndexedMatrixValue> outlist = new ArrayList<>(2);
            IndexedMatrixValue first = cachedValues.holdPlace(output, valueClass);
            first.getIndexes().setIndexes(ix);
            outlist.add(first);
            MatrixValue value_in2 = null;
            if (_cbind) {
                value_in2 = dcInput.getDataBlock((int) ix.getRowIndex(), 1).getValue();
                if (in1.getValue().getNumColumns() + value_in2.getNumColumns() > blen) {
                    IndexedMatrixValue second = cachedValues.holdPlace(output, valueClass);
                    second.getIndexes().setIndexes(ix.getRowIndex(), ix.getColumnIndex() + 1);
                    outlist.add(second);
                }
            } else {
                // rbind
                value_in2 = dcInput.getDataBlock(1, (int) ix.getColumnIndex()).getValue();
                if (in1.getValue().getNumRows() + value_in2.getNumRows() > blen) {
                    IndexedMatrixValue second = cachedValues.holdPlace(output, valueClass);
                    second.getIndexes().setIndexes(ix.getRowIndex() + 1, ix.getColumnIndex());
                    outlist.add(second);
                }
            }
            OperationsOnMatrixValues.performAppend(in1.getValue(), value_in2, outlist, blockRowFactor, blockColFactor, _cbind, true, 0);
        }
    }
}
Also used : DistributedCacheInput(org.apache.sysml.runtime.matrix.mapred.DistributedCacheInput) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue) MatrixValue(org.apache.sysml.runtime.matrix.data.MatrixValue) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) ArrayList(java.util.ArrayList) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 8 with MatrixValue

use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.

the class BinUaggChainInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
    ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
    if (blkList == null)
        return;
    for (IndexedMatrixValue imv : blkList) {
        if (imv == null)
            continue;
        MatrixIndexes inIx = imv.getIndexes();
        MatrixValue inVal = imv.getValue();
        // allocate space for the intermediate and output value
        IndexedMatrixValue iout = cachedValues.holdPlace(output, valueClass);
        MatrixIndexes outIx = iout.getIndexes();
        MatrixValue outVal = iout.getValue();
        // process instruction
        OperationsOnMatrixValues.performAggregateUnary(inIx, inVal, _tmpIx, _tmpVal, _uaggOp, blockRowFactor, blockColFactor);
        ((MatrixBlock) _tmpVal).dropLastRowsOrColumns(_uaggOp.aggOp.correctionLocation);
        OperationsOnMatrixValues.performBinaryIgnoreIndexes(inVal, _tmpVal, outVal, _bOp);
        outIx.setIndexes(inIx);
    }
}
Also used : 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) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 9 with MatrixValue

use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.

the class ParameterizedBuiltinMRInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
    ArrayList<IndexedMatrixValue> blkList = cachedValues.get(input);
    if (blkList != null)
        for (IndexedMatrixValue imv : blkList) {
            if (imv == null)
                continue;
            if (_opcode.equalsIgnoreCase("replace")) {
                MatrixValue in = imv.getValue();
                MatrixIndexes inIX = imv.getIndexes();
                // allocate space for the output value
                IndexedMatrixValue iout = null;
                if (output == input)
                    iout = tempValue;
                else
                    iout = cachedValues.holdPlace(output, valueClass);
                iout.getIndexes().setIndexes(inIX);
                MatrixValue out = iout.getValue();
                // process instruction
                in.replaceOperations(out, _pattern, _replace);
                // put the output value in the cache
                if (iout == tempValue)
                    cachedValues.add(output, iout);
            } else if (_opcode.equalsIgnoreCase("rexpand")) {
                // process instruction
                ArrayList<IndexedMatrixValue> out = new ArrayList<>();
                LibMatrixReorg.rexpand(imv, _max, _dirRows, _cast, _ignore, blockRowFactor, blockColFactor, out);
                // put the output values in the cache
                for (IndexedMatrixValue lout : out) cachedValues.add(output, lout);
            }
        }
}
Also used : IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue) MatrixValue(org.apache.sysml.runtime.matrix.data.MatrixValue) MatrixIndexes(org.apache.sysml.runtime.matrix.data.MatrixIndexes) ArrayList(java.util.ArrayList) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Example 10 with MatrixValue

use of org.apache.sysml.runtime.matrix.data.MatrixValue in project incubator-systemml by apache.

the class RemoveEmptyMRInstruction method processInstruction.

@Override
public void processInstruction(Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) {
    // get input and offsets
    IndexedMatrixValue inData = cachedValues.getFirst(input1);
    IndexedMatrixValue inOffset = cachedValues.getFirst(input2);
    MatrixIndexes ix = inData.getIndexes();
    MatrixValue mb = inData.getValue();
    if (_len > 0) {
        // execute remove empty operations
        ArrayList<IndexedMatrixValue> out = new ArrayList<>();
        LibMatrixReorg.rmempty(inData, inOffset, _rmRows, _len, blockRowFactor, blockColFactor, out);
        // put results into cache map
        for (IndexedMatrixValue imv : out) cachedValues.add(output, imv);
    } else {
        int n = _emptyRet ? 1 : 0;
        cachedValues.add(output, new IndexedMatrixValue(new MatrixIndexes(_rmRows ? 1 : ix.getRowIndex(), _rmRows ? ix.getColumnIndex() : 1), new MatrixBlock(_rmRows ? n : mb.getNumRows(), _rmRows ? mb.getNumColumns() : n, false)));
    }
}
Also used : 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) ArrayList(java.util.ArrayList) IndexedMatrixValue(org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)

Aggregations

MatrixValue (org.apache.sysml.runtime.matrix.data.MatrixValue)14 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)11 IndexedMatrixValue (org.apache.sysml.runtime.matrix.mapred.IndexedMatrixValue)8 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)5 ArrayList (java.util.ArrayList)3 DistributedCacheInput (org.apache.sysml.runtime.matrix.mapred.DistributedCacheInput)3 IOException (java.io.IOException)2 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1 ReduceAll (org.apache.sysml.runtime.functionobjects.ReduceAll)1 ReduceCol (org.apache.sysml.runtime.functionobjects.ReduceCol)1 AggregateInstruction (org.apache.sysml.runtime.instructions.mr.AggregateInstruction)1 ReblockInstruction (org.apache.sysml.runtime.instructions.mr.ReblockInstruction)1 MatrixCharacteristics (org.apache.sysml.runtime.matrix.MatrixCharacteristics)1 AggregateBinaryOperator (org.apache.sysml.runtime.matrix.operators.AggregateBinaryOperator)1 QuaternaryOperator (org.apache.sysml.runtime.matrix.operators.QuaternaryOperator)1 ReorgOperator (org.apache.sysml.runtime.matrix.operators.ReorgOperator)1