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);
}
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);
}
}
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;
}
}
}
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);
}
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);
}
}
}
Aggregations