use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class MMTSJCPInstruction method parseInstruction.
public static MMTSJCPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 4);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
MMTSJType titype = MMTSJType.valueOf(parts[3]);
int k = Integer.parseInt(parts[4]);
if (!opcode.equalsIgnoreCase("tsmm"))
throw new DMLRuntimeException("Unknown opcode while parsing an MMTSJCPInstruction: " + str);
else
return new MMTSJCPInstruction(new Operator(true), in1, titype, out, k, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class AppendCPInstruction method parseInstruction.
public static AppendCPInstruction 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]);
AppendType type = (in1.getDataType() != DataType.MATRIX && in1.getDataType() != DataType.FRAME) ? AppendType.STRING : cbind ? AppendType.CBIND : AppendType.RBIND;
if (!opcode.equalsIgnoreCase("append"))
throw new DMLRuntimeException("Unknown opcode while parsing a AppendCPInstruction: " + str);
Operator op = new ReorgOperator(OffsetColumnIndex.getOffsetColumnIndexFnObject(-1));
if (type == AppendType.STRING)
return new ScalarAppendCPInstruction(op, in1, in2, in3, out, type, opcode, str);
else if (in1.getDataType() == DataType.MATRIX)
return new MatrixAppendCPInstruction(op, in1, in2, in3, out, type, opcode, str);
else
//DataType.FRAME
return new FrameAppendCPInstruction(op, in1, in2, in3, out, type, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class DataPartitionCPInstruction method parseInstruction.
public static DataPartitionCPInstruction parseInstruction(String str) throws DMLRuntimeException {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 3);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
PDataPartitionFormat pformat = PDataPartitionFormat.valueOf(parts[3]);
if (!opcode.equalsIgnoreCase("partition"))
throw new DMLRuntimeException("Unknown opcode while parsing an DataPartitionCPInstruction: " + str);
else
return new DataPartitionCPInstruction(new Operator(true), in1, pformat, out, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class GroupedAggMRCombiner method reduce.
@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<TaggedMatrixIndexes, WeightedCell> out, Reporter reporter) throws IOException {
long start = System.currentTimeMillis();
//get aggregate operator
GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
Operator op = ins.getOperator();
boolean isPartialAgg = true;
//combine iterator to single value
try {
if (//everything except sum
op instanceof CMOperator) {
if (((CMOperator) op).isPartialAggregateOperator()) {
cmObj.reset();
CM lcmFn = cmFn.get(key.getTag());
//partial aggregate cm operator
while (values.hasNext()) {
WeightedCell value = values.next();
lcmFn.execute(cmObj, value.getValue(), value.getWeight());
}
outCell.setValue(cmObj.getRequiredPartialResult(op));
outCell.setWeight(cmObj.getWeight());
} else //forward tuples to reducer
{
isPartialAgg = false;
while (values.hasNext()) out.collect(key, values.next());
}
} else if (//sum
op instanceof AggregateOperator) {
AggregateOperator aggop = (AggregateOperator) op;
if (aggop.correctionExists) {
KahanObject buffer = new KahanObject(aggop.initialValue, 0);
KahanPlus.getKahanPlusFnObject();
//partial aggregate with correction
while (values.hasNext()) {
WeightedCell value = values.next();
aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
}
outCell.setValue(buffer._sum);
outCell.setWeight(1);
} else //no correction
{
double v = aggop.initialValue;
//partial aggregate without correction
while (values.hasNext()) {
WeightedCell value = values.next();
v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
}
outCell.setValue(v);
outCell.setWeight(1);
}
} else
throw new IOException("Unsupported operator in instruction: " + ins);
} catch (Exception ex) {
throw new IOException(ex);
}
//collect the output (to reducer)
if (isPartialAgg)
out.collect(key, outCell);
reporter.incrCounter(Counters.COMBINE_OR_REDUCE_TIME, System.currentTimeMillis() - start);
}
use of org.apache.sysml.runtime.matrix.operators.Operator in project incubator-systemml by apache.
the class GroupedAggMRReducer method reduce.
@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<MatrixIndexes, MatrixCell> out, Reporter report) throws IOException {
commonSetup(report);
//get operator
GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
Operator op = ins.getOperator();
try {
if (//all, but sum
op instanceof CMOperator) {
cmObj.reset();
CM lcmFn = cmFn.get(key.getTag());
while (values.hasNext()) {
WeightedCell value = values.next();
lcmFn.execute(cmObj, value.getValue(), value.getWeight());
}
outCell.setValue(cmObj.getRequiredResult(op));
} else if (//sum
op instanceof AggregateOperator) {
AggregateOperator aggop = (AggregateOperator) op;
if (aggop.correctionExists) {
KahanObject buffer = new KahanObject(aggop.initialValue, 0);
while (values.hasNext()) {
WeightedCell value = values.next();
aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
}
outCell.setValue(buffer._sum);
} else {
double v = aggop.initialValue;
while (values.hasNext()) {
WeightedCell value = values.next();
v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
}
outCell.setValue(v);
}
} else
throw new IOException("Unsupported operator in instruction: " + ins);
} catch (Exception ex) {
throw new IOException(ex);
}
outIndex.setIndexes(key.getBaseObject());
cachedValues.reset();
cachedValues.set(key.getTag(), outIndex, outCell);
processReducerInstructions();
//output the final result matrices
outputResultsFromCachedValues(report);
}
Aggregations