use of org.apache.sysml.runtime.instructions.cp.KahanObject in project incubator-systemml by apache.
the class ColGroupOLE method computeRowSums.
@Override
protected final void computeRowSums(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();
final int blksz = BitmapEncoder.BITMAP_BLOCK_SZ;
final int numVals = getNumValues();
if (ALLOW_CACHE_CONSCIOUS_ROWSUMS && LOW_LEVEL_OPT && numVals > 1 && _numRows > blksz) {
final int blksz2 = ColGroupOffset.WRITE_CACHE_BLKSZ / 2;
// step 1: prepare position and value arrays
int[] apos = skipScan(numVals, rl);
double[] aval = sumAllValues(kplus, kbuff, false);
// step 2: cache conscious row sums via horizontal scans
for (int bi = rl; bi < ru; bi += blksz2) {
int bimax = Math.min(bi + blksz2, ru);
// horizontal segment scan, incl pos maintenance
for (int k = 0; k < numVals; k++) {
int boff = _ptr[k];
int blen = len(k);
double val = aval[k];
int bix = apos[k];
for (int ii = bi; ii < bimax && bix < blen; ii += blksz) {
// prepare length, start, and end pos
int len = _data[boff + bix];
int pos = boff + bix + 1;
// compute partial results
for (int i = 0; i < len; i++) {
int rix = ii + _data[pos + i];
double[] cvals = c.values(rix);
int cix = c.pos(rix);
kbuff.set(cvals[cix], cvals[cix + 1]);
kplus2.execute2(kbuff, val);
cvals[cix] = kbuff._sum;
cvals[cix + 1] = kbuff._correction;
}
bix += len + 1;
}
apos[k] = bix;
}
}
} else {
// iterate over all values and their bitmaps
for (int k = 0; k < numVals; k++) {
// prepare value-to-add for entire value bitmap
int boff = _ptr[k];
int blen = len(k);
double val = sumValues(k, kplus, kbuff);
// iterate over bitmap blocks and add values
if (val != 0) {
int slen;
int bix = skipScanVal(k, rl);
for (int off = ((rl + 1) / blksz) * blksz; bix < blen && off < ru; bix += slen + 1, off += blksz) {
slen = _data[boff + bix];
for (int i = 1; i <= slen; i++) {
int rix = off + _data[boff + bix + i];
double[] cvals = c.values(rix);
int cix = c.pos(rix);
kbuff.set(cvals[cix], cvals[cix + 1]);
kplus2.execute2(kbuff, val);
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 PerformGroupByAggInCombiner method call.
@Override
public WeightedCell call(WeightedCell value1, WeightedCell value2) throws Exception {
WeightedCell outCell = new WeightedCell();
CM_COV_Object cmObj = new CM_COV_Object();
if (// everything except sum
_op instanceof CMOperator) {
if (((CMOperator) _op).isPartialAggregateOperator()) {
cmObj.reset();
// cmFn.get(key.getTag());
CM lcmFn = CM.getCMFnObject(((CMOperator) _op).aggOpType);
// partial aggregate cm operator
lcmFn.execute(cmObj, value1.getValue(), value1.getWeight());
lcmFn.execute(cmObj, value2.getValue(), value2.getWeight());
outCell.setValue(cmObj.getRequiredPartialResult(_op));
outCell.setWeight(cmObj.getWeight());
} else // forward tuples to reducer
{
throw new DMLRuntimeException("Incorrect usage, should have used PerformGroupByAggInReducer");
}
} else if (// sum
_op instanceof AggregateOperator) {
AggregateOperator aggop = (AggregateOperator) _op;
if (aggop.correctionExists) {
KahanObject buffer = new KahanObject(aggop.initialValue, 0);
KahanPlus.getKahanPlusFnObject();
// partial aggregate with correction
aggop.increOp.fn.execute(buffer, value1.getValue() * value1.getWeight());
aggop.increOp.fn.execute(buffer, value2.getValue() * value2.getWeight());
outCell.setValue(buffer._sum);
outCell.setWeight(1);
} else // no correction
{
double v = aggop.initialValue;
// partial aggregate without correction
v = aggop.increOp.fn.execute(v, value1.getValue() * value1.getWeight());
v = aggop.increOp.fn.execute(v, value2.getValue() * value2.getWeight());
outCell.setValue(v);
outCell.setWeight(1);
}
} else
throw new DMLRuntimeException("Unsupported operator in grouped aggregate instruction:" + _op);
return outCell;
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project incubator-systemml by apache.
the class PerformGroupByAggInReducer method call.
@Override
public WeightedCell call(Iterable<WeightedCell> kv) throws Exception {
WeightedCell outCell = new WeightedCell();
CM_COV_Object cmObj = new CM_COV_Object();
if (// everything except sum
op instanceof CMOperator) {
cmObj.reset();
// cmFn.get(key.getTag());
CM lcmFn = CM.getCMFnObject(((CMOperator) op).aggOpType);
if (((CMOperator) op).isPartialAggregateOperator()) {
throw new DMLRuntimeException("Incorrect usage, should have used PerformGroupByAggInCombiner");
} else // forward tuples to reducer
{
for (WeightedCell value : kv) lcmFn.execute(cmObj, value.getValue(), value.getWeight());
outCell.setValue(cmObj.getRequiredResult(op));
outCell.setWeight(1);
}
} else if (// sum
op instanceof AggregateOperator) {
AggregateOperator aggop = (AggregateOperator) op;
if (aggop.correctionExists) {
KahanObject buffer = new KahanObject(aggop.initialValue, 0);
KahanPlus.getKahanPlusFnObject();
// partial aggregate with correction
for (WeightedCell value : kv) aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
outCell.setValue(buffer._sum);
outCell.setWeight(1);
} else // no correction
{
double v = aggop.initialValue;
// partial aggregate without correction
for (WeightedCell value : kv) v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
outCell.setValue(v);
outCell.setWeight(1);
}
} else
throw new DMLRuntimeException("Unsupported operator in grouped aggregate instruction:" + op);
return outCell;
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project incubator-systemml by apache.
the class LibMatrixAgg method aggregateBinaryMatrixDenseGeneric.
private static void aggregateBinaryMatrixDenseGeneric(MatrixBlock in, MatrixBlock aggVal, MatrixBlock aggCorr) {
if (in.denseBlock == null || in.isEmptyBlock(false))
return;
final int m = in.rlen;
final int n = in.clen;
double[] a = in.getDenseBlockValues();
KahanObject buffer = new KahanObject(0, 0);
KahanPlus akplus = KahanPlus.getKahanPlusFnObject();
// incl implicit nnz maintenance
for (int i = 0, ix = 0; i < m; i++) for (int j = 0; j < n; j++, ix++) {
buffer._sum = aggVal.quickGetValue(i, j);
buffer._correction = aggCorr.quickGetValue(i, j);
akplus.execute(buffer, a[ix]);
aggVal.quickSetValue(i, j, buffer._sum);
aggCorr.quickSetValue(i, j, buffer._correction);
}
// note: nnz of aggVal/aggCorr maintained internally
if (aggVal.sparse)
aggVal.examSparsity(false);
if (aggCorr.sparse)
aggCorr.examSparsity(false);
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project incubator-systemml by apache.
the class LibMatrixAgg method aggregateBinaryMatrixLastRowDenseGeneric.
private static void aggregateBinaryMatrixLastRowDenseGeneric(MatrixBlock in, MatrixBlock aggVal) {
if (in.denseBlock == null || in.isEmptyBlock(false))
return;
final int m = in.rlen;
final int n = in.clen;
final int cix = (m - 1) * n;
double[] a = in.getDenseBlockValues();
KahanObject buffer = new KahanObject(0, 0);
KahanPlus akplus = KahanPlus.getKahanPlusFnObject();
// incl implicit nnz maintenance
for (int i = 0, ix = 0; i < m - 1; i++) for (int j = 0; j < n; j++, ix++) {
buffer._sum = aggVal.quickGetValue(i, j);
buffer._correction = aggVal.quickGetValue(m - 1, j);
akplus.execute(buffer, a[ix], a[cix + j]);
aggVal.quickSetValue(i, j, buffer._sum);
aggVal.quickSetValue(m - 1, j, buffer._correction);
}
// note: nnz of aggVal maintained internally
aggVal.examSparsity();
}
Aggregations