Search in sources :

Example 66 with KahanObject

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

the class SpoofCellwise method executeSparseColAggSum.

private long executeSparseColAggSum(SparseBlock sblock, SideInput[] b, double[] scalars, MatrixBlock out, int m, int n, boolean sparseSafe, int rl, int ru) {
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    double[] corr = new double[n];
    // note: sequential scan algorithm for both sparse-safe and -unsafe
    // in order to avoid binary search for sparse-unsafe
    double[] c = out.getDenseBlockValues();
    for (int i = rl; i < ru; i++) {
        kbuff.set(0, 0);
        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++) {
                        kbuff.set(c[j], corr[j]);
                        kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
                        c[j] = kbuff._sum;
                        corr[j] = kbuff._correction;
                    }
                // process current non-zero
                lastj = aix[k];
                kbuff.set(c[aix[k]], corr[aix[k]]);
                kplus.execute2(kbuff, genexec(avals[k], b, scalars, m, n, i, lastj));
                c[aix[k]] = kbuff._sum;
                corr[aix[k]] = kbuff._correction;
            }
        }
        // process empty rows or remaining zeros
        if (!sparseSafe)
            for (int j = lastj + 1; j < n; j++) {
                kbuff.set(c[j], corr[j]);
                kplus.execute2(kbuff, genexec(0, b, scalars, m, n, i, j));
                c[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 67 with KahanObject

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

the class SpoofCellwise method executeCompressedRowAggSum.

private long executeCompressedRowAggSum(CompressedMatrixBlock a, SideInput[] b, double[] scalars, double[] c, int m, int n, boolean sparseSafe, int rl, int ru) {
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    long lnnz = 0;
    Iterator<IJV> iter = a.getIterator(rl, ru, !sparseSafe);
    while (iter.hasNext()) {
        IJV cell = iter.next();
        double val = genexec(cell.getV(), b, scalars, m, n, cell.getI(), cell.getJ());
        kbuff.set(c[cell.getI()], 0);
        kplus.execute2(kbuff, val);
        c[cell.getI()] = kbuff._sum;
    }
    for (int i = rl; i < ru; i++) lnnz += (c[i] != 0) ? 1 : 0;
    return lnnz;
}
Also used : IJV(org.apache.sysml.runtime.matrix.data.IJV) KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject)

Example 68 with KahanObject

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

the class SpoofCellwise method executeSparseRowAggSum.

private long executeSparseRowAggSum(SparseBlock sblock, SideInput[] b, double[] scalars, MatrixBlock out, int m, int n, boolean sparseSafe, int rl, int ru) {
    KahanFunction kplus = (KahanFunction) getAggFunction();
    KahanObject kbuff = new KahanObject(0, 0);
    // note: sequential scan algorithm for both sparse-safe and -unsafe
    // in order to avoid binary search for sparse-unsafe
    double[] c = out.getDenseBlockValues();
    long lnnz = 0;
    for (int i = rl; i < ru; i++) {
        kbuff.set(0, 0);
        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));
        lnnz += ((c[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 69 with KahanObject

use of org.apache.sysml.runtime.instructions.cp.KahanObject in project incubator-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)

Example 70 with KahanObject

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

the class SpoofMultiAggregate method aggregatePartialResults.

private void aggregatePartialResults(double[] c, ArrayList<double[]> pret) {
    ValueFunction[] vfun = getAggFunctions(_aggOps);
    for (int k = 0; k < _aggOps.length; k++) {
        if (vfun[k] instanceof KahanFunction) {
            KahanObject kbuff = new KahanObject(0, 0);
            KahanPlus kplus = KahanPlus.getKahanPlusFnObject();
            for (double[] tmp : pret) kplus.execute2(kbuff, tmp[k]);
            c[k] = kbuff._sum;
        } else {
            for (double[] tmp : pret) c[k] = vfun[k].execute(c[k], tmp[k]);
        }
    }
}
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

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