Search in sources :

Example 11 with KahanFunction

use of org.apache.sysml.runtime.functionobjects.KahanFunction in project systemml by apache.

the class SpoofCellwise method executeDenseAggSum.

private double executeDenseAggSum(DenseBlock a, SideInput[] b, double[] scalars, int m, int n, boolean sparseSafe, int rl, int ru) {
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    if (a == null && !sparseSafe) {
        for (int i = rl; i < ru; i++) for (int j = 0; j < n; j++) kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
    } else if (a != null) {
        for (int i = rl; i < ru; i++) {
            double[] avals = a.values(i);
            int aix = a.pos(i);
            for (int j = 0; j < n; j++) {
                double aval = avals[aix + j];
                if (aval != 0 || !sparseSafe)
                    kplus.execute2(kbuff, genexec(aval, b, scalars, m, n, i, j));
            }
        }
    }
    return kbuff._sum;
}
Also used : KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 12 with KahanFunction

use of org.apache.sysml.runtime.functionobjects.KahanFunction in project systemml by apache.

the class SpoofCellwise method executeSparseAggSum.

private double executeSparseAggSum(SparseBlock sblock, SideInput[] b, double[] scalars, int m, int n, boolean sparseSafe, int rl, int ru) {
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    // in order to avoid binary search for sparse-unsafe
    for (int i = rl; i < ru; i++) {
        int lastj = -1;
        // handle non-empty rows
        if (sblock != null && !sblock.isEmpty(i)) {
            int apos = sblock.pos(i);
            int alen = sblock.size(i);
            int[] aix = sblock.indexes(i);
            double[] avals = sblock.values(i);
            for (int k = apos; k < apos + alen; k++) {
                // process zeros before current non-zero
                if (!sparseSafe)
                    for (int j = lastj + 1; j < aix[k]; j++) kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
                // process current non-zero
                lastj = aix[k];
                kplus.execute2(kbuff, genexec(avals[k], b, scalars, m, n, i, lastj));
            }
        }
        // process empty rows or remaining zeros
        if (!sparseSafe)
            for (int j = lastj + 1; j < n; j++) kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
    }
    return kbuff._sum;
}
Also used : KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 13 with KahanFunction

use of org.apache.sysml.runtime.functionobjects.KahanFunction in project systemml by apache.

the class SpoofCellwise method executeDenseColAggSum.

private long executeDenseColAggSum(DenseBlock a, SideInput[] b, double[] scalars, DenseBlock c, int m, int n, boolean sparseSafe, int rl, int ru) {
    // single block
    double[] lc = c.valuesAt(0);
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    double[] corr = new double[n];
    if (a == null && !sparseSafe) {
        for (int i = rl; i < ru; i++) for (int j = 0; j < n; j++) {
            kbuff.set(lc[j], corr[j]);
            kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
            lc[j] = kbuff._sum;
            corr[j] = kbuff._correction;
        }
    } else if (a != null) {
        for (int i = rl; i < ru; i++) {
            double[] avals = a.values(i);
            int aix = a.pos(i);
            for (int j = 0; j < n; j++) {
                double aval = avals[aix + j];
                if (aval != 0 || !sparseSafe) {
                    kbuff.set(lc[j], corr[j]);
                    kplus.execute2(kbuff, genexec(aval, b, scalars, m, n, i, j));
                    lc[j] = kbuff._sum;
                    corr[j] = kbuff._correction;
                }
            }
        }
    }
    return -1;
}
Also used : KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 14 with KahanFunction

use of org.apache.sysml.runtime.functionobjects.KahanFunction in project systemml by apache.

the class SpoofCellwise method executeDenseRowAggSum.

private long executeDenseRowAggSum(DenseBlock a, SideInput[] b, double[] scalars, DenseBlock c, int m, int n, boolean sparseSafe, int rl, int ru) {
    // note: output always single block
    double[] lc = c.valuesAt(0);
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    long lnnz = 0;
    if (a == null && !sparseSafe) {
        for (int i = rl; i < ru; i++) {
            kbuff.set(0, 0);
            for (int j = 0; j < n; j++) kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
            lnnz += ((lc[i] = kbuff._sum) != 0) ? 1 : 0;
        }
    } else if (a != null) {
        for (int i = rl; i < ru; i++) {
            kbuff.set(0, 0);
            double[] avals = a.values(i);
            int aix = a.pos(i);
            for (int j = 0; j < n; j++) {
                double aval = avals[aix + j];
                if (aval != 0 || !sparseSafe)
                    kplus.execute2(kbuff, genexec(aval, b, scalars, m, n, i, j));
            }
            lnnz += ((lc[i] = kbuff._sum) != 0) ? 1 : 0;
        }
    }
    return lnnz;
}
Also used : KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 15 with KahanFunction

use of org.apache.sysml.runtime.functionobjects.KahanFunction in project systemml by apache.

the class SpoofMultiAggregate method aggregatePartialResults.

public static void aggregatePartialResults(AggOp[] aggOps, MatrixBlock c, MatrixBlock b) {
    ValueFunction[] vfun = getAggFunctions(aggOps);
    for (int k = 0; k < aggOps.length; k++) {
        if (vfun[k] instanceof KahanFunction) {
            KahanObject kbuff = new KahanObject(c.quickGetValue(0, k), 0);
            KahanPlus kplus = KahanPlus.getKahanPlusFnObject();
            kplus.execute2(kbuff, b.quickGetValue(0, k));
            c.quickSetValue(0, k, kbuff._sum);
        } else {
            double cval = c.quickGetValue(0, k);
            double bval = b.quickGetValue(0, k);
            c.quickSetValue(0, k, vfun[k].execute(cval, bval));
        }
    }
}
Also used : ValueFunction(org.apache.sysml.runtime.functionobjects.ValueFunction) KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) KahanPlus(org.apache.sysml.runtime.functionobjects.KahanPlus)

Aggregations

KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)32 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)28 KahanPlus (org.apache.sysml.runtime.functionobjects.KahanPlus)10 ValueFunction (org.apache.sysml.runtime.functionobjects.ValueFunction)10 ArrayList (java.util.ArrayList)6 ExecutorService (java.util.concurrent.ExecutorService)6 Future (java.util.concurrent.Future)6 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)6 IJV (org.apache.sysml.runtime.matrix.data.IJV)6 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)6 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)4 Builtin (org.apache.sysml.runtime.functionobjects.Builtin)4 KahanPlusSq (org.apache.sysml.runtime.functionobjects.KahanPlusSq)4 ReduceAll (org.apache.sysml.runtime.functionobjects.ReduceAll)4 ReduceCol (org.apache.sysml.runtime.functionobjects.ReduceCol)4 IOException (java.io.IOException)2 ColGroup (org.apache.sysml.runtime.compress.ColGroup)2 ColGroupValue (org.apache.sysml.runtime.compress.ColGroupValue)2 Timing (org.apache.sysml.runtime.controlprogram.parfor.stat.Timing)2 BuiltinCode (org.apache.sysml.runtime.functionobjects.Builtin.BuiltinCode)2