Search in sources :

Example 71 with KahanObject

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

the class ColGroupDDC method computeSum.

protected void computeSum(MatrixBlock result, KahanFunction kplus) {
    int nrow = getNumRows();
    int ncol = getNumCols();
    KahanObject kbuff = new KahanObject(result.quickGetValue(0, 0), result.quickGetValue(0, 1));
    for (int i = 0; i < nrow; i++) for (int j = 0; j < ncol; j++) kplus.execute2(kbuff, getData(i, j));
    result.quickSetValue(0, 0, kbuff._sum);
    result.quickSetValue(0, 1, kbuff._correction);
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 72 with KahanObject

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

the class ColGroupDDC method computeRowSums.

protected void computeRowSums(MatrixBlock result, KahanFunction kplus, int rl, int ru) {
    int ncol = getNumCols();
    KahanObject kbuff = new KahanObject(0, 0);
    for (int i = rl; i < ru; i++) {
        kbuff.set(result.quickGetValue(i, 0), result.quickGetValue(i, 1));
        for (int j = 0; j < ncol; j++) kplus.execute2(kbuff, getData(i, j));
        result.quickSetValue(i, 0, kbuff._sum);
        result.quickSetValue(i, 1, kbuff._correction);
    }
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 73 with KahanObject

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

the class ColGroupDDC1 method computeRowSums.

public static void computeRowSums(ColGroupDDC1[] grps, MatrixBlock result, KahanFunction kplus, int rl, int ru) {
    // note: due to corrections the output might be a large dense block
    DenseBlock c = result.getDenseBlock();
    KahanObject kbuff = new KahanObject(0, 0);
    KahanPlus kplus2 = KahanPlus.getKahanPlusFnObject();
    // prepare distinct values once
    double[][] vals = new double[grps.length][];
    for (int i = 0; i < grps.length; i++) {
        // pre-aggregate all distinct values (guaranteed <=255)
        vals[i] = grps[i].sumAllValues(kplus, kbuff);
    }
    // cache-conscious row sums operations
    // iterative over codes of all groups and add to output
    // (use kahan plus not general KahanFunction for correctness in case of sqk+)
    // 16KB
    int blksz = 1024;
    double[] tmpAgg = new double[blksz];
    for (int bi = rl; bi < ru; bi += blksz) {
        Arrays.fill(tmpAgg, 0);
        // aggregate all groups
        for (int j = 0; j < grps.length; j++) {
            double[] valsj = vals[j];
            byte[] dataj = grps[j]._data;
            for (int i = bi; i < Math.min(bi + blksz, ru); i++) tmpAgg[i - bi] += valsj[dataj[i] & 0xFF];
        }
        // add partial results of all ddc groups
        for (int i = bi; i < Math.min(bi + blksz, ru); i++) {
            double[] cvals = c.values(i);
            int cix = c.pos(i);
            kbuff.set(cvals[cix], cvals[cix + 1]);
            kplus2.execute2(kbuff, tmpAgg[i - bi]);
            cvals[cix] = kbuff._sum;
            cvals[cix + 1] = kbuff._correction;
        }
    }
}
Also used : DenseBlock(org.apache.sysml.runtime.matrix.data.DenseBlock) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) KahanPlus(org.apache.sysml.runtime.functionobjects.KahanPlus)

Example 74 with KahanObject

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

the class ColGroupDDC1 method computeSum.

@Override
protected void computeSum(MatrixBlock result, KahanFunction kplus) {
    final int ncol = getNumCols();
    final int numVals = getNumValues();
    // iterative over codes and count per code (guaranteed <=255)
    int[] counts = getCounts();
    // post-scaling of pre-aggregate with distinct values
    KahanObject kbuff = new KahanObject(result.quickGetValue(0, 0), result.quickGetValue(0, 1));
    for (int k = 0, valOff = 0; k < numVals; k++, valOff += ncol) {
        int cntk = counts[k];
        for (int j = 0; j < ncol; j++) kplus.execute3(kbuff, _values[valOff + j], cntk);
    }
    result.quickSetValue(0, 0, kbuff._sum);
    result.quickSetValue(0, 1, kbuff._correction);
}
Also used : KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 75 with KahanObject

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

the class ColGroupOLE method computeColSums.

@Override
protected final void computeColSums(MatrixBlock result, KahanFunction kplus) {
    KahanObject kbuff = new KahanObject(0, 0);
    // 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++) {
            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)

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