use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project systemml by apache.
the class AggregateUnarySPInstruction method parseInstruction.
public static AggregateUnarySPInstruction parseInstruction(String str) {
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]);
SparkAggType aggtype = SparkAggType.valueOf(parts[3]);
String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(opcode);
CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(opcode);
String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
AggregateUnaryOperator aggun = InstructionUtils.parseBasicAggregateUnaryOperator(opcode);
AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
return new AggregateUnarySPInstruction(SPType.AggregateUnary, aggun, aop, in1, out, aggtype, opcode, str);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project systemml by apache.
the class AggregateBinaryInstruction method parseInstruction.
public static AggregateBinaryInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionParts(str);
byte in1, in2, out;
String opcode = parts[0];
in1 = Byte.parseByte(parts[1]);
in2 = Byte.parseByte(parts[2]);
out = Byte.parseByte(parts[3]);
if (opcode.equalsIgnoreCase("cpmm") || opcode.equalsIgnoreCase("rmm") || opcode.equalsIgnoreCase(MapMult.OPCODE)) {
AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg);
AggregateBinaryInstruction inst = new AggregateBinaryInstruction(aggbin, opcode, in1, in2, out, str);
if (parts.length == 5) {
inst.setMMCJType(MMCJType.valueOf(parts[4]));
} else if (parts.length == 6) {
// mapmm
inst.setCacheTypeMapMult(CacheType.valueOf(parts[4]));
inst.setOutputEmptyBlocksMapMult(Boolean.parseBoolean(parts[5]));
}
return inst;
}
throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project systemml by apache.
the class MatrixBlock method min.
/**
* Wrapper method for reduceall-min of a matrix.
*
* @return ?
*/
public double min() {
// construct operator
AggregateOperator aop = new AggregateOperator(Double.POSITIVE_INFINITY, Builtin.getBuiltinFnObject("min"));
AggregateUnaryOperator auop = new AggregateUnaryOperator(aop, ReduceAll.getReduceAllFnObject());
// execute operation
MatrixBlock out = new MatrixBlock(1, 1, false);
LibMatrixAgg.aggregateUnaryMatrix(this, out, auop);
return out.quickGetValue(0, 0);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project systemml by apache.
the class MatrixBlock method max.
/**
* Wrapper method for reduceall-max of a matrix.
*
* @return ?
*/
public double max() {
// construct operator
AggregateOperator aop = new AggregateOperator(Double.NEGATIVE_INFINITY, Builtin.getBuiltinFnObject("max"));
AggregateUnaryOperator auop = new AggregateUnaryOperator(aop, ReduceAll.getReduceAllFnObject());
// execute operation
MatrixBlock out = new MatrixBlock(1, 1, false);
LibMatrixAgg.aggregateUnaryMatrix(this, out, auop);
return out.quickGetValue(0, 0);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project 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);
}
Aggregations