use of org.apache.sysml.runtime.functionobjects.KahanFunction in project 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;
}
use of org.apache.sysml.runtime.functionobjects.KahanFunction in project 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]);
}
}
}
Aggregations