@Override public void processInstruction( Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int brlen, int bclen) throws DMLUnsupportedOperationException, DMLRuntimeException { // get both inputs IndexedMatrixValue left = cachedValues.getFirst(input1); IndexedMatrixValue right = cachedValues.getFirst(input2); // check non-existing block if (left == null || right == null) throw new DMLRuntimeException( "Missing append input: isNull(left): " + (left == null) + ", isNull(right): " + (right == null)); // core append operation MatrixBlock mbLeft = (MatrixBlock) left.getValue(); MatrixBlock mbRight = (MatrixBlock) right.getValue(); MatrixBlock ret = mbLeft.appendOperations(mbRight, new MatrixBlock(), _cbind); // put result into cache cachedValues.add(output, new IndexedMatrixValue(left.getIndexes(), ret)); }
@Override public void processInstruction( Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) throws DMLRuntimeException { IndexedMatrixValue in1 = cachedValues.getFirst(input1); IndexedMatrixValue in2 = cachedValues.getFirst(input2); if (in1 == null && in2 == null) return; // allocate space for the output value // try to avoid coping as much as possible IndexedMatrixValue out; if ((output != input1 && output != input2) || (output == input1 && in1 == null) || (output == input2 && in2 == null)) out = cachedValues.holdPlace(output, valueClass); else out = tempValue; // if one of the inputs is null, then it is a all zero block MatrixIndexes finalIndexes = null; if (in1 == null) { in1 = zeroInput; in1.getValue().reset(in2.getValue().getNumRows(), in2.getValue().getNumColumns()); finalIndexes = in2.getIndexes(); } else finalIndexes = in1.getIndexes(); if (in2 == null) { in2 = zeroInput; in2.getValue().reset(in1.getValue().getNumRows(), in1.getValue().getNumColumns()); } // process instruction out.getIndexes().setIndexes(finalIndexes); OperationsOnMatrixValues.performBinaryIgnoreIndexes( in1.getValue(), in2.getValue(), out.getValue(), ((BinaryOperator) optr)); // put the output value in the cache if (out == tempValue) cachedValues.add(output, out); }
@Override public void processInstruction( Class<? extends MatrixValue> valueClass, CachedValueMap cachedValues, IndexedMatrixValue tempValue, IndexedMatrixValue zeroInput, int blockRowFactor, int blockColFactor) throws DMLRuntimeException { IndexedMatrixValue in1 = cachedValues.getFirst(input1); // original data IndexedMatrixValue in2 = cachedValues.getFirst(input2); // offset row vector if (in1 == null || in2 == null) throw new DMLRuntimeException( "Unexpected empty input (left=" + ((in1 == null) ? "null" : in1.getIndexes()) + ", right=" + ((in2 == null) ? "null" : in2.getIndexes()) + ")."); // prepare inputs and outputs IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass); MatrixBlock data = (MatrixBlock) in1.getValue(); MatrixBlock offset = (MatrixBlock) in2.getValue(); MatrixBlock blk = (MatrixBlock) out.getValue(); blk.reset(data.getNumRows(), data.getNumColumns()); // blockwise offset aggregation and prefix sum computation MatrixBlock data2 = new MatrixBlock(data); // cp data MatrixBlock fdata2 = data2.sliceOperations(0, 0, 0, data2.getNumColumns() - 1, new MatrixBlock()); // 1-based fdata2.binaryOperationsInPlace(_bop, offset); // sum offset to first row data2.copy(0, 0, 0, data2.getNumColumns() - 1, fdata2, true); // 0-based data2.unaryOperations(_uop, blk); // compute columnwise prefix sums/prod/min/max // set output indexes out.getIndexes().setIndexes(in1.getIndexes()); }
@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 = (!_cacheU) ? cachedValues.getFirst(_input2).getValue() // U : MRBaseForCommonInstructions.dcValues .get(_input2) .getDataBlock((int) inIx.getRowIndex(), 1) .getValue(); MatrixValue Vj = (!_cacheV) ? cachedValues.getFirst(_input3).getValue() // t(V) : 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); // set output indexes if (qop.wtype1 != null || qop.wtype4 != null) outIx.setIndexes(1, 1); // wsloss else if (qop.wtype2 != null || qop.wtype5 != null || qop.wtype3 != null && qop.wtype3.isBasic()) outIx.setIndexes(inIx); // wsigmoid/wdivmm-basic 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); } }