use of org.apache.sysml.runtime.matrix.data.DenseBlock in project systemml by apache.
the class ResultMergeRemoteSparkWCompare method call.
@Override
public Tuple2<MatrixIndexes, MatrixBlock> call(Tuple2<MatrixIndexes, Tuple2<Iterable<MatrixBlock>, MatrixBlock>> arg) throws Exception {
MatrixIndexes ixin = arg._1();
Iterator<MatrixBlock> din = arg._2()._1().iterator();
MatrixBlock cin = arg._2()._2();
// create compare array
DenseBlock compare = DataConverter.convertToDenseBlock(cin, false);
// merge all blocks into compare block
MatrixBlock out = new MatrixBlock(cin);
while (din.hasNext()) mergeWithComp(out, din.next(), compare);
// create output tuple
return new Tuple2<>(new MatrixIndexes(ixin), out);
}
use of org.apache.sysml.runtime.matrix.data.DenseBlock in project systemml by apache.
the class DataConverter method convertToDenseBlock.
public static DenseBlock convertToDenseBlock(MatrixBlock mb, boolean deep) {
int rows = mb.getNumRows();
int cols = mb.getNumColumns();
DenseBlock ret = (!mb.isInSparseFormat() && mb.isAllocated() && !deep) ? mb.getDenseBlock() : // 0-initialized
DenseBlockFactory.createDenseBlock(rows, cols);
if (!mb.isEmptyBlock(false)) {
if (mb.isInSparseFormat()) {
Iterator<IJV> iter = mb.getSparseBlockIterator();
while (iter.hasNext()) {
IJV cell = iter.next();
ret.set(cell.getI(), cell.getJ(), cell.getV());
}
} else if (deep) {
ret.set(mb.getDenseBlock());
}
}
return ret;
}
use of org.apache.sysml.runtime.matrix.data.DenseBlock in project systemml by apache.
the class SpoofCellwise method executeSparseNoAggDense.
private long executeSparseNoAggDense(SparseBlock sblock, SideInput[] b, double[] scalars, MatrixBlock out, int m, int n, boolean sparseSafe, int rl, int ru) {
// note: sequential scan algorithm for both sparse-safe and -unsafe
// in order to avoid binary search for sparse-unsafe
DenseBlock c = out.getDenseBlock();
long lnnz = 0;
for (int i = rl; i < ru; i++) {
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);
double[] cvals = c.values(i);
int cix = c.pos(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++) lnnz += ((cvals[cix + j] = genexec(0, b, scalars, m, n, i, j)) != 0) ? 1 : 0;
// process current non-zero
lastj = aix[k];
lnnz += ((cvals[cix + lastj] = genexec(avals[k], b, scalars, m, n, i, lastj)) != 0) ? 1 : 0;
}
}
// process empty rows or remaining zeros
if (!sparseSafe)
for (int j = lastj + 1; j < n; j++) {
double[] cvals = c.values(i);
int cix = c.pos(i);
lnnz += ((cvals[cix + j] = genexec(0, b, scalars, m, n, i, j)) != 0) ? 1 : 0;
}
}
return lnnz;
}
use of org.apache.sysml.runtime.matrix.data.DenseBlock in project systemml by apache.
the class SpoofOuterProduct method execute.
@Override
public ScalarObject execute(ArrayList<MatrixBlock> inputs, ArrayList<ScalarObject> scalarObjects, int numThreads) {
// sanity check
if (inputs == null || inputs.size() < 3)
throw new RuntimeException("Invalid input arguments.");
if (inputs.get(0).isEmptyBlock(false))
return new DoubleObject(0);
if (2 * inputs.get(0).getNonZeros() * inputs.get(1).getNumColumns() < PAR_MINFLOP_THRESHOLD)
// sequential
return execute(inputs, scalarObjects);
// input preparation
DenseBlock[] ab = getDenseMatrices(prepInputMatrices(inputs, 1, 2, true, false));
SideInput[] b = prepInputMatrices(inputs, 3, false);
double[] scalars = prepInputScalars(scalarObjects);
// core sequential execute
final int m = inputs.get(0).getNumRows();
final int n = inputs.get(0).getNumColumns();
// rank
final int k = inputs.get(1).getNumColumns();
final long nnz = inputs.get(0).getNonZeros();
double sum = 0;
try {
ExecutorService pool = CommonThreadPool.get(k);
ArrayList<ParOuterProdAggTask> tasks = new ArrayList<>();
int numThreads2 = getPreferredNumberOfTasks(m, n, nnz, k, numThreads);
int blklen = (int) (Math.ceil((double) m / numThreads2));
for (int i = 0; i < numThreads2 & i * blklen < m; i++) tasks.add(new ParOuterProdAggTask(inputs.get(0), ab[0], ab[1], b, scalars, m, n, k, _outerProductType, i * blklen, Math.min((i + 1) * blklen, m), 0, n));
// execute tasks
List<Future<Double>> taskret = pool.invokeAll(tasks);
pool.shutdown();
for (Future<Double> task : taskret) sum += task.get();
} catch (Exception e) {
throw new DMLRuntimeException(e);
}
return new DoubleObject(sum);
}
use of org.apache.sysml.runtime.matrix.data.DenseBlock in project systemml by apache.
the class SpoofOuterProduct method execute.
@Override
public ScalarObject execute(ArrayList<MatrixBlock> inputs, ArrayList<ScalarObject> scalarObjects) {
// sanity check
if (inputs == null || inputs.size() < 3)
throw new RuntimeException("Invalid input arguments.");
if (inputs.get(0).isEmptyBlock(false))
return new DoubleObject(0);
// input preparation
DenseBlock[] ab = getDenseMatrices(prepInputMatrices(inputs, 1, 2, true, false));
SideInput[] b = prepInputMatrices(inputs, 3, false);
double[] scalars = prepInputScalars(scalarObjects);
// core sequential execute
final int m = inputs.get(0).getNumRows();
final int n = inputs.get(0).getNumColumns();
// rank
final int k = inputs.get(1).getNumColumns();
MatrixBlock a = inputs.get(0);
MatrixBlock out = new MatrixBlock(1, 1, false);
out.allocateDenseBlock();
if (a instanceof CompressedMatrixBlock)
executeCellwiseCompressed((CompressedMatrixBlock) a, ab[0], ab[1], b, scalars, out, m, n, k, _outerProductType, 0, m, 0, n);
else if (!a.isInSparseFormat())
executeCellwiseDense(a.getDenseBlock(), ab[0], ab[1], b, scalars, out.getDenseBlock(), m, n, k, _outerProductType, 0, m, 0, n);
else
executeCellwiseSparse(a.getSparseBlock(), ab[0], ab[1], b, scalars, out, m, n, k, a.getNonZeros(), _outerProductType, 0, m, 0, n);
return new DoubleObject(out.getDenseBlock().get(0, 0));
}
Aggregations