use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class LibMatrixMult method prepMatrixMultTransposeSelfInput.
private static MatrixBlock prepMatrixMultTransposeSelfInput(MatrixBlock m1, boolean leftTranspose) {
MatrixBlock ret = m1;
if (// X%*%t(X) SPARSE MATRIX
!leftTranspose && m1.sparse && m1.rlen > 1) {
// directly via LibMatrixReorg in order to prevent sparsity change
MatrixBlock tmpBlock = new MatrixBlock(m1.clen, m1.rlen, m1.sparse);
LibMatrixReorg.reorg(m1, tmpBlock, new ReorgOperator(SwapIndex.getSwapIndexFnObject()));
ret = tmpBlock;
}
return ret;
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class ReorgCPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) {
// acquire inputs
MatrixBlock matBlock = ec.getMatrixInput(input1.getName(), getExtendedOpcode());
ReorgOperator r_op = (ReorgOperator) _optr;
if (r_op.fn instanceof SortIndex) {
// additional attributes for sort
int[] cols = _col.getDataType().isMatrix() ? DataConverter.convertToIntVector(ec.getMatrixInput(_col.getName())) : new int[] { (int) ec.getScalarInput(_col.getName(), _col.getValueType(), _col.isLiteral()).getLongValue() };
boolean desc = ec.getScalarInput(_desc.getName(), _desc.getValueType(), _desc.isLiteral()).getBooleanValue();
boolean ixret = ec.getScalarInput(_ixret.getName(), _ixret.getValueType(), _ixret.isLiteral()).getBooleanValue();
r_op = r_op.setFn(new SortIndex(cols, desc, ixret));
}
// execute operation
MatrixBlock soresBlock = (MatrixBlock) (matBlock.reorgOperations(r_op, new MatrixBlock(), 0, 0, 0));
// release inputs/outputs
if (r_op.fn instanceof SortIndex && _col.getDataType().isMatrix())
ec.releaseMatrixInput(_col.getName());
ec.releaseMatrixInput(input1.getName(), getExtendedOpcode());
ec.setMatrixOutput(output.getName(), soresBlock, getExtendedOpcode());
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class ReorgGPUInstruction method parseInstruction.
public static ReorgGPUInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 2);
String opcode = parts[0];
CPOperand in = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
if (!(opcode.equalsIgnoreCase("r'")))
throw new DMLRuntimeException("Unknown opcode while parsing a ReorgInstruction: " + str);
else
return new ReorgGPUInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), in, out, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class ReorgInstruction 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 in : blkList) {
if (in == null)
continue;
int startRow = 0, startColumn = 0, length = 0;
// process instruction
if (((ReorgOperator) optr).fn instanceof DiagIndex) {
// special diag handling (overloaded, size-dependent operation; hence decided during runtime)
boolean V2M = (_mcIn.getRows() == 1 || _mcIn.getCols() == 1);
// input can be row/column vector
long rlen = Math.max(_mcIn.getRows(), _mcIn.getCols());
// Note: for M2V we directly skip non-diagonal blocks block
if (V2M || in.getIndexes().getRowIndex() == in.getIndexes().getColumnIndex()) {
if (V2M) {
// allocate space for the output value
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
OperationsOnMatrixValues.performReorg(in.getIndexes(), in.getValue(), out.getIndexes(), out.getValue(), ((ReorgOperator) optr), startRow, startColumn, length);
// (only for block representation)
if (_outputEmptyBlocks && valueClass.equals(MatrixBlock.class)) {
// row index is equal to the col index
long diagIndex = out.getIndexes().getRowIndex();
long brlen = Math.max(_mcIn.getRowsPerBlock(), _mcIn.getColsPerBlock());
long numRowBlocks = (rlen / brlen) + ((rlen % brlen != 0) ? 1 : 0);
for (long rc = 1; rc <= numRowBlocks; rc++) {
// prevent duplicate output
if (rc == diagIndex)
continue;
IndexedMatrixValue emptyIndexValue = cachedValues.holdPlace(output, valueClass);
int lbrlen = (int) ((rc * brlen <= rlen) ? brlen : rlen % brlen);
emptyIndexValue.getIndexes().setIndexes(rc, diagIndex);
emptyIndexValue.getValue().reset(lbrlen, out.getValue().getNumColumns(), true);
}
}
} else // M2V
{
// allocate space for the output value
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
// compute matrix indexes
out.getIndexes().setIndexes(in.getIndexes().getRowIndex(), 1);
// compute result block
in.getValue().reorgOperations((ReorgOperator) optr, out.getValue(), startRow, startColumn, length);
}
}
} else if (((ReorgOperator) optr).fn instanceof RevIndex) {
// execute reverse operation
ArrayList<IndexedMatrixValue> out = new ArrayList<>();
LibMatrixReorg.rev(in, _mcIn.getRows(), _mcIn.getRowsPerBlock(), out);
// output indexed matrix values
for (IndexedMatrixValue outblk : out) cachedValues.add(output, outblk);
} else // general case (e.g., transpose)
{
// allocate space for the output value
IndexedMatrixValue out = cachedValues.holdPlace(output, valueClass);
OperationsOnMatrixValues.performReorg(in.getIndexes(), in.getValue(), out.getIndexes(), out.getValue(), ((ReorgOperator) optr), startRow, startColumn, length);
}
}
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class AppendRSPInstruction method parseInstruction.
public static AppendRSPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 4);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
boolean cbind = Boolean.parseBoolean(parts[4]);
if (!opcode.equalsIgnoreCase("rappend"))
throw new DMLRuntimeException("Unknown opcode while parsing a MatrixAppendRSPInstruction: " + str);
if (in1.getDataType().isMatrix()) {
return new MatrixAppendRSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, out, cbind, opcode, str);
} else {
return new FrameAppendRSPInstruction(new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1)), in1, in2, out, cbind, opcode, str);
}
}
Aggregations