use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class ReorgSPInstruction method parseInstruction.
public static ReorgSPInstruction parseInstruction(String str) {
CPOperand in = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
CPOperand out = new CPOperand("", ValueType.UNKNOWN, DataType.UNKNOWN);
String opcode = InstructionUtils.getOpCode(str);
if (opcode.equalsIgnoreCase("r'")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgSPInstruction(new ReorgOperator(SwapIndex.getSwapIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rev")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgSPInstruction(new ReorgOperator(RevIndex.getRevIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rdiag")) {
// max 2 operands
parseUnaryInstruction(str, in, out);
return new ReorgSPInstruction(new ReorgOperator(DiagIndex.getDiagIndexFnObject()), in, out, opcode, str);
} else if (opcode.equalsIgnoreCase("rsort")) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 5, 6);
in.split(parts[1]);
out.split(parts[5]);
CPOperand col = new CPOperand(parts[2]);
CPOperand desc = new CPOperand(parts[3]);
CPOperand ixret = new CPOperand(parts[4]);
boolean bSortIndInMem = false;
if (parts.length > 5)
bSortIndInMem = Boolean.parseBoolean(parts[6]);
return new ReorgSPInstruction(new ReorgOperator(new SortIndex(1, false, false)), in, col, desc, ixret, out, opcode, bSortIndInMem, 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 ZipmmSPInstruction method processInstruction.
@Override
public void processInstruction(ExecutionContext ec) {
SparkExecutionContext sec = (SparkExecutionContext) ec;
// get rdd inputs (for computing r = t(X)%*%y via r = t(t(y)%*%X))
// X
JavaPairRDD<MatrixIndexes, MatrixBlock> in1 = sec.getBinaryBlockRDDHandleForVariable(input1.getName());
// y
JavaPairRDD<MatrixIndexes, MatrixBlock> in2 = sec.getBinaryBlockRDDHandleForVariable(input2.getName());
// process core zipmm matrix multiply (in contrast to cpmm, the join over original indexes
// preserves the original partitioning and with that potentially unnecessary join shuffle)
JavaRDD<MatrixBlock> out = // join over original indexes
in1.join(in2).values().map(// compute block multiplications, incl t(y)
new ZipMultiplyFunction(_tRewrite));
// single-block aggregation (guaranteed by zipmm blocksize constraint)
MatrixBlock out2 = RDDAggregateUtils.sumStable(out);
// final transpose of result (for t(t(y)%*%X))), if transpose rewrite
if (_tRewrite) {
ReorgOperator rop = new ReorgOperator(SwapIndex.getSwapIndexFnObject());
out2 = (MatrixBlock) out2.reorgOperations(rop, new MatrixBlock(), 0, 0, 0);
}
// put output block into symbol table (no lineage because single block)
// this also includes implicit maintenance of matrix characteristics
sec.setMatrixOutput(output.getName(), out2, getExtendedOpcode());
}
use of org.apache.sysml.runtime.matrix.operators.ReorgOperator in project incubator-systemml by apache.
the class LibMatrixMult method prepMatrixMultRightInput.
private static MatrixBlock prepMatrixMultRightInput(MatrixBlock m1, MatrixBlock m2) {
MatrixBlock ret = m2;
// transpose if dense-dense, skinny rhs matrix (not vector), and memory guarded by output
if (checkPrepMatrixMultRightInput(m1, m2)) {
MatrixBlock tmpBlock = new MatrixBlock(m2.clen, m2.rlen, m2.sparse);
LibMatrixReorg.reorg(m2, 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 MatrixBlock method sortOperations.
public MatrixValue sortOperations(MatrixValue weights, MatrixValue result) {
boolean wtflag = (weights != null);
MatrixBlock wts = (weights == null ? null : checkType(weights));
checkType(result);
if (getNumColumns() != 1) {
throw new DMLRuntimeException("Invalid input dimensions (" + getNumRows() + "x" + getNumColumns() + ") to sort operation.");
}
if (wts != null && wts.getNumColumns() != 1) {
throw new DMLRuntimeException("Invalid weight dimensions (" + wts.getNumRows() + "x" + wts.getNumColumns() + ") to sort operation.");
}
// prepare result, currently always dense
// #rows in temp matrix = 1 + #nnz in the input ( 1 is for the "zero" value)
int dim1 = (int) (1 + this.getNonZeros());
if (result == null)
result = new MatrixBlock(dim1, 2, false);
else
result.reset(dim1, 2, false);
// Copy the input elements into a temporary array for sorting
// First column is data and second column is weights
// (since the inputs are vectors, they are likely dense - hence quickget is sufficient)
MatrixBlock tdw = new MatrixBlock(dim1, 2, false);
double d, w, zero_wt = 0;
int ind = 1;
if (// w/ weights
wtflag) {
for (int i = 0; i < rlen; i++) {
d = quickGetValue(i, 0);
w = wts.quickGetValue(i, 0);
if (d != 0) {
tdw.quickSetValue(ind, 0, d);
tdw.quickSetValue(ind, 1, w);
ind++;
} else
zero_wt += w;
}
} else // w/o weights
{
zero_wt = getNumRows() - getNonZeros();
for (int i = 0; i < rlen; i++) {
d = quickGetValue(i, 0);
if (d != 0) {
tdw.quickSetValue(ind, 0, d);
tdw.quickSetValue(ind, 1, 1);
ind++;
}
}
}
tdw.quickSetValue(0, 0, 0.0);
// num zeros in input
tdw.quickSetValue(0, 1, zero_wt);
// Sort td and tw based on values inside td (ascending sort), incl copy into result
SortIndex sfn = new SortIndex(1, false, false);
ReorgOperator rop = new ReorgOperator(sfn);
LibMatrixReorg.reorg(tdw, (MatrixBlock) result, rop);
return result;
}
Aggregations