use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.
the class ColGroupOLE method computeSum.
@Override
protected final void computeSum(MatrixBlock result, KahanFunction kplus) {
KahanObject kbuff = new KahanObject(result.quickGetValue(0, 0), result.quickGetValue(0, 1));
// 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++) kplus.execute3(kbuff, _values[valOff + j], count);
}
result.quickSetValue(0, 0, kbuff._sum);
result.quickSetValue(0, 1, kbuff._correction);
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.
the class ColGroupRLE method computeColSums.
@Override
protected final void computeColSums(MatrixBlock result, KahanFunction kplus) {
KahanObject kbuff = new KahanObject(0, 0);
final int numCols = getNumCols();
final int numVals = getNumValues();
for (int k = 0; k < numVals; k++) {
int boff = _ptr[k];
int blen = len(k);
int valOff = k * numCols;
int curRunEnd = 0;
int count = 0;
for (int bix = 0; bix < blen; bix += 2) {
int curRunStartOff = curRunEnd + _data[boff + bix];
curRunEnd = curRunStartOff + _data[boff + bix + 1];
count += curRunEnd - curRunStartOff;
}
// 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);
}
}
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.
the class ColGroupRLE method computeSum.
@Override
protected final void computeSum(MatrixBlock result, KahanFunction kplus) {
KahanObject kbuff = new KahanObject(result.quickGetValue(0, 0), result.quickGetValue(0, 1));
final int numCols = getNumCols();
final int numVals = getNumValues();
for (int k = 0; k < numVals; k++) {
int boff = _ptr[k];
int blen = len(k);
int valOff = k * numCols;
int curRunEnd = 0;
int count = 0;
for (int bix = 0; bix < blen; bix += 2) {
int curRunStartOff = curRunEnd + _data[boff + bix];
curRunEnd = curRunStartOff + _data[boff + bix + 1];
count += curRunEnd - curRunStartOff;
}
// scale counts by all values
for (int j = 0; j < numCols; j++) kplus.execute3(kbuff, _values[valOff + j], count);
}
result.quickSetValue(0, 0, kbuff._sum);
result.quickSetValue(0, 1, kbuff._correction);
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.
the class GroupedAggMRReducer method reduce.
@Override
public void reduce(TaggedMatrixIndexes key, Iterator<WeightedCell> values, OutputCollector<MatrixIndexes, MatrixCell> out, Reporter report) throws IOException {
commonSetup(report);
// get operator
GroupedAggregateInstruction ins = grpaggInstructions.get(key.getTag());
Operator op = ins.getOperator();
try {
if (// all, but sum
op instanceof CMOperator) {
cmObj.reset();
CM lcmFn = cmFn.get(key.getTag());
while (values.hasNext()) {
WeightedCell value = values.next();
lcmFn.execute(cmObj, value.getValue(), value.getWeight());
}
outCell.setValue(cmObj.getRequiredResult(op));
} else if (// sum
op instanceof AggregateOperator) {
AggregateOperator aggop = (AggregateOperator) op;
if (aggop.correctionExists) {
KahanObject buffer = new KahanObject(aggop.initialValue, 0);
while (values.hasNext()) {
WeightedCell value = values.next();
aggop.increOp.fn.execute(buffer, value.getValue() * value.getWeight());
}
outCell.setValue(buffer._sum);
} else {
double v = aggop.initialValue;
while (values.hasNext()) {
WeightedCell value = values.next();
v = aggop.increOp.fn.execute(v, value.getValue() * value.getWeight());
}
outCell.setValue(v);
}
} else
throw new IOException("Unsupported operator in instruction: " + ins);
} catch (Exception ex) {
throw new IOException(ex);
}
outIndex.setIndexes(key.getBaseObject());
cachedValues.reset();
cachedValues.set(key.getTag(), outIndex, outCell);
processReducerInstructions();
// output the final result matrices
outputResultsFromCachedValues(report);
}
use of org.apache.sysml.runtime.instructions.cp.KahanObject in project systemml by apache.
the class LibMatrixAgg method cumaggregateUnaryMatrixSparse.
private static void cumaggregateUnaryMatrixSparse(MatrixBlock in, MatrixBlock out, AggType optype, ValueFunction vFn, double[] agg, int rl, int ru) {
final int m = in.rlen;
final int n = in.clen;
SparseBlock a = in.getSparseBlock();
DenseBlock dc = out.getDenseBlock();
double[] c = out.getDenseBlockValues();
switch(optype) {
case CUM_KAHAN_SUM:
{
// CUMSUM
KahanObject kbuff = new KahanObject(0, 0);
KahanPlus kplus = KahanPlus.getKahanPlusFnObject();
s_ucumkp(a, agg, dc, m, n, kbuff, kplus, rl, ru);
break;
}
case CUM_PROD:
{
// CUMPROD
s_ucumm(a, agg, c, n, rl, ru);
break;
}
case CUM_MIN:
case CUM_MAX:
{
double init = (optype == AggType.CUM_MAX) ? Double.NEGATIVE_INFINITY : Double.POSITIVE_INFINITY;
s_ucummxx(a, agg, c, n, init, (Builtin) vFn, rl, ru);
break;
}
default:
throw new DMLRuntimeException("Unsupported cumulative aggregation type: " + optype);
}
}
Aggregations