Search in sources :

Example 1 with ColGroupValue

use of org.apache.sysml.runtime.compress.ColGroupValue in project incubator-systemml by apache.

the class SpoofCellwise method executeCompressedAggSum.

private double executeCompressedAggSum(CompressedMatrixBlock 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);
    KahanObject kbuff2 = new KahanObject(0, 0);
    // special case: computation over value-tuples only
    if (sparseSafe && b.length == 0 && !a.hasUncompressedColGroup()) {
        // note: all remaining groups are guaranteed ColGroupValue
        boolean entireGrp = (rl == 0 && ru == a.getNumRows());
        int maxNumVals = a.getColGroups().stream().mapToInt(g -> ((ColGroupValue) g).getNumValues()).max().orElse(0);
        int[] counts = new int[maxNumVals];
        for (ColGroup grp : a.getColGroups()) {
            ColGroupValue grpv = (ColGroupValue) grp;
            counts = entireGrp ? grpv.getCounts(counts) : grpv.getCounts(rl, ru, counts);
            for (int k = 0; k < grpv.getNumValues(); k++) {
                kbuff2.set(0, 0);
                double in = grpv.sumValues(k, kplus, kbuff2);
                double out = genexec(in, b, scalars, m, n, -1, -1);
                kplus.execute3(kbuff, out, counts[k]);
            }
        }
    } else // general case of arbitrary side inputs
    {
        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());
            kplus.execute2(kbuff, val);
        }
    }
    return kbuff._sum;
}
Also used : ColGroup(org.apache.sysml.runtime.compress.ColGroup) IJV(org.apache.sysml.runtime.matrix.data.IJV) KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) ColGroupValue(org.apache.sysml.runtime.compress.ColGroupValue)

Example 2 with ColGroupValue

use of org.apache.sysml.runtime.compress.ColGroupValue in project systemml by apache.

the class SpoofCellwise method executeCompressedAggSum.

private double executeCompressedAggSum(CompressedMatrixBlock 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);
    KahanObject kbuff2 = new KahanObject(0, 0);
    // special case: computation over value-tuples only
    if (sparseSafe && b.length == 0 && !a.hasUncompressedColGroup()) {
        // note: all remaining groups are guaranteed ColGroupValue
        boolean entireGrp = (rl == 0 && ru == a.getNumRows());
        int maxNumVals = a.getColGroups().stream().mapToInt(g -> ((ColGroupValue) g).getNumValues()).max().orElse(0);
        int[] counts = new int[maxNumVals];
        for (ColGroup grp : a.getColGroups()) {
            ColGroupValue grpv = (ColGroupValue) grp;
            counts = entireGrp ? grpv.getCounts(counts) : grpv.getCounts(rl, ru, counts);
            for (int k = 0; k < grpv.getNumValues(); k++) {
                kbuff2.set(0, 0);
                double in = grpv.sumValues(k, kplus, kbuff2);
                double out = genexec(in, b, scalars, m, n, -1, -1);
                kplus.execute3(kbuff, out, counts[k]);
            }
        }
    } else // general case of arbitrary side inputs
    {
        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());
            kplus.execute2(kbuff, val);
        }
    }
    return kbuff._sum;
}
Also used : ColGroup(org.apache.sysml.runtime.compress.ColGroup) IJV(org.apache.sysml.runtime.matrix.data.IJV) KahanFunction(org.apache.sysml.runtime.functionobjects.KahanFunction) KahanObject(org.apache.sysml.runtime.instructions.cp.KahanObject) ColGroupValue(org.apache.sysml.runtime.compress.ColGroupValue)

Aggregations

ColGroup (org.apache.sysml.runtime.compress.ColGroup)2 ColGroupValue (org.apache.sysml.runtime.compress.ColGroupValue)2 KahanFunction (org.apache.sysml.runtime.functionobjects.KahanFunction)2 KahanObject (org.apache.sysml.runtime.instructions.cp.KahanObject)2 IJV (org.apache.sysml.runtime.matrix.data.IJV)2