use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-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));
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class SpoofRowwise method execute.
public MatrixBlock execute(ArrayList<MatrixBlock> inputs, ArrayList<ScalarObject> scalarObjects, MatrixBlock out, boolean allocTmp, boolean aggIncr) {
// sanity check
if (inputs == null || inputs.size() < 1 || out == null)
throw new RuntimeException("Invalid input arguments.");
// result allocation and preparations
final int m = inputs.get(0).getNumRows();
final int n = inputs.get(0).getNumColumns();
final int n2 = _type.isConstDim2(_constDim2) ? (int) _constDim2 : _type.isRowTypeB1() || hasMatrixSideInput(inputs) ? getMinColsMatrixSideInputs(inputs) : -1;
if (!aggIncr || !out.isAllocated())
allocateOutputMatrix(m, n, n2, out);
DenseBlock c = out.getDenseBlock();
final boolean flipOut = _type.isRowTypeB1ColumnAgg() && LibSpoofPrimitives.isFlipOuter(out.getNumRows(), out.getNumColumns());
// input preparation
SideInput[] b = prepInputMatrices(inputs, 1, inputs.size() - 1, false, _tB1);
double[] scalars = prepInputScalars(scalarObjects);
// setup thread-local memory if necessary
if (allocTmp && _reqVectMem > 0)
LibSpoofPrimitives.setupThreadLocalMemory(_reqVectMem, n, n2);
// core sequential execute
MatrixBlock a = inputs.get(0);
if (a instanceof CompressedMatrixBlock)
executeCompressed((CompressedMatrixBlock) a, b, scalars, c, n, 0, m);
else if (!a.isInSparseFormat())
executeDense(a.getDenseBlock(), b, scalars, c, n, 0, m);
else
executeSparse(a.getSparseBlock(), b, scalars, c, n, 0, m);
// post-processing
if (allocTmp && _reqVectMem > 0)
LibSpoofPrimitives.cleanupThreadLocalMemory();
if (flipOut) {
fixTransposeDimensions(out);
out = LibMatrixReorg.transpose(out, new MatrixBlock(out.getNumColumns(), out.getNumRows(), false));
}
if (!aggIncr) {
out.recomputeNonZeros();
out.examSparsity();
}
return out;
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class ParVectorMatrixMultTest method runMatrixVectorMultTest.
private static void runMatrixVectorMultTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
MatrixBlock vector = DataConverter.convertToMatrixBlock(TestUtils.generateTestMatrix(1, rows, 1, 1, 1.0, 3));
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
AggregateOperator aop = new AggregateOperator(0, Plus.getPlusFnObject());
AggregateBinaryOperator abop = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), aop, InfrastructureAnalyzer.getLocalParallelism());
MatrixBlock ret1 = vector.aggregateBinaryOperations(vector, mb, new MatrixBlock(), abop);
// matrix-vector compressed
MatrixBlock ret2 = cmb.aggregateBinaryOperations(vector, cmb, new MatrixBlock(), abop);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
TestUtils.compareMatrices(d1, d2, 1, cols, 0.0000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicMatrixCentralMomentTest method runMatrixAppendTest.
private static void runMatrixAppendTest(SparsityType sptype, ValueType vtype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// quantile uncompressed
AggregateOperationTypes opType = CMOperator.getCMAggOpType(2);
CMOperator cm = new CMOperator(CM.getCMFnObject(opType), opType);
double ret1 = mb.cmOperations(cm).getRequiredResult(opType);
// quantile compressed
double ret2 = cmb.cmOperations(cm).getRequiredResult(opType);
// compare result with input
TestUtils.compareScalars(ret1, ret2, 0.0000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.compress.CompressedMatrixBlock in project incubator-systemml by apache.
the class BasicMatrixMultChainTest method runMatrixMultChainTest.
private static void runMatrixMultChainTest(SparsityType sptype, ValueType vtype, ChainType ctype, boolean compress) {
try {
// prepare sparsity for input data
double sparsity = -1;
switch(sptype) {
case DENSE:
sparsity = sparsity1;
break;
case SPARSE:
sparsity = sparsity2;
break;
case EMPTY:
sparsity = sparsity3;
break;
}
// generate input data
double min = (vtype == ValueType.CONST) ? 10 : -10;
double[][] input = TestUtils.generateTestMatrix(rows, cols, min, 10, sparsity, 7);
if (vtype == ValueType.RAND_ROUND_OLE || vtype == ValueType.RAND_ROUND_DDC) {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = (vtype == ValueType.RAND_ROUND_DDC);
input = TestUtils.round(input);
}
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
MatrixBlock vector1 = DataConverter.convertToMatrixBlock(TestUtils.generateTestMatrix(cols, 1, 0, 1, 1.0, 3));
MatrixBlock vector2 = (ctype == ChainType.XtwXv) ? DataConverter.convertToMatrixBlock(TestUtils.generateTestMatrix(rows, 1, 0, 1, 1.0, 3)) : null;
// compress given matrix block
CompressedMatrixBlock cmb = new CompressedMatrixBlock(mb);
if (compress)
cmb.compress();
// matrix-vector uncompressed
MatrixBlock ret1 = (MatrixBlock) mb.chainMatrixMultOperations(vector1, vector2, new MatrixBlock(), ctype);
// matrix-vector compressed
MatrixBlock ret2 = (MatrixBlock) cmb.chainMatrixMultOperations(vector1, vector2, new MatrixBlock(), ctype);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
TestUtils.compareMatrices(d1, d2, cols, 1, 0.0000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
Aggregations