Search in sources :

Example 46 with KahanObject

use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.

the class ColGroupOLE method computeSum.

@Override
protected final void computeSum(MatrixBlock result, KahanFunction kplus) {
    KahanObject kbuff = new KahanObject(result.quickGetValue(0, 0), result.quickGetValue(0, 1));
    // iterate over all values and their bitmaps
    final int numVals = getNumValues();
    final int numCols = getNumCols();
    for (int k = 0; k < numVals; k++) {
        int boff = _ptr[k];
        int blen = len(k);
        int valOff = k * numCols;
        // iterate over bitmap blocks and count partial lengths
        int count = 0;
        for (int bix = 0; bix < blen; bix += _data[boff + bix] + 1) count += _data[boff + bix];
        // scale counts by all values
        for (int j = 0; j < numCols; j++) kplus.execute3(kbuff, _values[valOff + j], count);
    }
    result.quickSetValue(0, 0, kbuff._sum);
    result.quickSetValue(0, 1, kbuff._correction);
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 47 with KahanObject

use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.

the class ColGroupRLE method computeColSums.

@Override
protected final void computeColSums(MatrixBlock result, KahanFunction kplus) {
    KahanObject kbuff = new KahanObject(0, 0);
    final int numCols = getNumCols();
    final int numVals = getNumValues();
    for (int k = 0; k < numVals; k++) {
        int boff = _ptr[k];
        int blen = len(k);
        int valOff = k * numCols;
        int curRunEnd = 0;
        int count = 0;
        for (int bix = 0; bix < blen; bix += 2) {
            int curRunStartOff = curRunEnd + _data[boff + bix];
            curRunEnd = curRunStartOff + _data[boff + bix + 1];
            count += curRunEnd - curRunStartOff;
        }
        // scale counts by all values
        for (int j = 0; j < numCols; j++) {
            kbuff.set(result.quickGetValue(0, _colIndexes[j]), result.quickGetValue(1, _colIndexes[j]));
            kplus.execute3(kbuff, _values[valOff + j], count);
            result.quickSetValue(0, _colIndexes[j], kbuff._sum);
            result.quickSetValue(1, _colIndexes[j], kbuff._correction);
        }
    }
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 48 with KahanObject

use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.

the class ColGroupRLE method computeSum.

@Override
protected final void computeSum(MatrixBlock result, KahanFunction kplus) {
    KahanObject kbuff = new KahanObject(result.quickGetValue(0, 0), result.quickGetValue(0, 1));
    final int numCols = getNumCols();
    final int numVals = getNumValues();
    for (int k = 0; k < numVals; k++) {
        int boff = _ptr[k];
        int blen = len(k);
        int valOff = k * numCols;
        int curRunEnd = 0;
        int count = 0;
        for (int bix = 0; bix < blen; bix += 2) {
            int curRunStartOff = curRunEnd + _data[boff + bix];
            curRunEnd = curRunStartOff + _data[boff + bix + 1];
            count += curRunEnd - curRunStartOff;
        }
        // scale counts by all values
        for (int j = 0; j < numCols; j++) kplus.execute3(kbuff, _values[valOff + j], count);
    }
    result.quickSetValue(0, 0, kbuff._sum);
    result.quickSetValue(0, 1, kbuff._correction);
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 49 with KahanObject

use of org.apache.sysml.runtime.instructions.cp.KahanObject in project 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);
}
Also used : CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) Operator(org.apache.sysml.runtime.matrix.operators.Operator) WeightedCell(org.apache.sysml.runtime.matrix.data.WeightedCell) AggregateOperator(org.apache.sysml.runtime.matrix.operators.AggregateOperator) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) CM(org.apache.sysml.runtime.functionobjects.CM) IOException(java.io.IOException) CMOperator(org.apache.sysml.runtime.matrix.operators.CMOperator) GroupedAggregateInstruction(org.apache.sysml.runtime.instructions.mr.GroupedAggregateInstruction) IOException(java.io.IOException)

Example 50 with KahanObject

use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.

the class LibMatrixAgg method cumaggregateUnaryMatrixSparse.

private static void cumaggregateUnaryMatrixSparse(MatrixBlock in, MatrixBlock out, AggType optype, ValueFunction vFn, double[] agg, int rl, int ru) {
    final int m = in.rlen;
    final int n = in.clen;
    SparseBlock a = in.getSparseBlock();
    DenseBlock dc = out.getDenseBlock();
    double[] c = out.getDenseBlockValues();
    switch(optype) {
        case CUM_KAHAN_SUM:
            {
                // CUMSUM
                KahanObject kbuff = new KahanObject(0, 0);
                KahanPlus kplus = KahanPlus.getKahanPlusFnObject();
                s_ucumkp(a, agg, dc, m, n, kbuff, kplus, rl, ru);
                break;
            }
        case CUM_PROD:
            {
                // CUMPROD
                s_ucumm(a, agg, c, n, rl, ru);
                break;
            }
        case CUM_MIN:
        case CUM_MAX:
            {
                double init = (optype == AggType.CUM_MAX) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
                s_ucummxx(a, agg, c, n, init, (Builtin) vFn, rl, ru);
                break;
            }
        default:
            throw new DMLRuntimeException("Unsupported cumulative aggregation type: " + optype);
    }
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) KahanPlus(org.apache.sysml.runtime.functionobjects.KahanPlus) Builtin(org.apache.sysml.runtime.functionobjects.Builtin) DMLRuntimeException(org.apache.sysml.runtime.DMLRuntimeException)

Aggregations

KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)115 KahanPlus (org.apache.sysml.runtime.functionobjects.KahanPlus)49 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)28 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)28 CM_COV_Object (org.apache.sysml.runtime.instructions.cp.CM_COV_Object)15 CM (org.apache.sysml.runtime.functionobjects.CM)14 Builtin (org.apache.sysml.runtime.functionobjects.Builtin)12 ReduceAll (org.apache.sysml.runtime.functionobjects.ReduceAll)10 DenseBlock (org.apache.sysml.runtime.matrix.data.DenseBlock)10 CMOperator (org.apache.sysml.runtime.matrix.operators.CMOperator)10 IOException (java.io.IOException)8 WeightedCell (org.apache.sysml.runtime.matrix.data.WeightedCell)8 AggregateOperator (org.apache.sysml.runtime.matrix.operators.AggregateOperator)8 KahanPlusSq (org.apache.sysml.runtime.functionobjects.KahanPlusSq)6 ReduceCol (org.apache.sysml.runtime.functionobjects.ReduceCol)6 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)6 IJV (org.apache.sysml.runtime.matrix.data.IJV)6 ArrayList (java.util.ArrayList)4 ExecutorService (java.util.concurrent.ExecutorService)4 Future (java.util.concurrent.Future)4