Search in sources :

Example 6 with WeightedCell

use of org.apache.sysml.runtime.matrix.data.WeightedCell in project incubator-systemml by apache.

the class PerformGroupByAggInReducer method call.

@Override
public WeightedCell call(Iterable<WeightedCell> kv) throws Exception {
    WeightedCell outCell = new WeightedCell();
    CM_COV_Object cmObj = new CM_COV_Object();
    if (//everything except sum
    op instanceof CMOperator) {
        cmObj.reset();
        // cmFn.get(key.getTag());
        CM lcmFn = CM.getCMFnObject(((CMOperator) op).aggOpType);
        if (((CMOperator) op).isPartialAggregateOperator()) {
            throw new DMLRuntimeException("Incorrect usage, should have used PerformGroupByAggInCombiner");
        } else //forward tuples to reducer
        {
            for (WeightedCell value : kv) lcmFn.execute(cmObj, value.getValue(), value.getWeight());
            outCell.setValue(cmObj.getRequiredResult(op));
            outCell.setWeight(1);
        }
    } 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
            for (WeightedCell value : kv) 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
            for (WeightedCell value : kv) v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
            outCell.setValue(v);
            outCell.setWeight(1);
        }
    } else
        throw new DMLRuntimeException("Unsupported operator in grouped aggregate instruction:" + op);
    return outCell;
}
Also used : WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) CM_COV_Object(org.apache.sysml.runtime.instructions.cp.CM_COV_Object) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) CM(org.apache.sysml.runtime.functionobjects.CM) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)6 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)5 CM (org.apache.sysml.runtime.functionobjects.CM)4 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)4 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)2 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)2 GroupedAggregateInstruction (org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction)2 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)2 MatrixIndexes (org.apache.sysml.runtime.matrix.data.MatrixIndexes)2 Operator (org.apache.sysml.runtime.matrix.operators.Operator)2 Tuple2 (scala.Tuple2)2