use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.
the class LargeMatrixMatrixMultTest method runMatrixVectorMultTest.
private static void runMatrixVectorMultTest(MultType mtype, 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);
}
boolean right = (mtype == MultType.RIGHT);
MatrixBlock mb = DataConverter.convertToMatrixBlock(input);
MatrixBlock vect = DataConverter.convertToMatrixBlock(right ? TestUtils.generateTestMatrix(cols, cols2, -1, 1, 1.0, 3) : TestUtils.generateTestMatrix(cols2, 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);
MatrixBlock ret1 = right ? mb.aggregateBinaryOperations(mb, vect, new MatrixBlock(), abop) : vect.aggregateBinaryOperations(vect, mb, new MatrixBlock(), abop);
// matrix-vector compressed
MatrixBlock ret2 = right ? cmb.aggregateBinaryOperations(cmb, vect, new MatrixBlock(), abop) : cmb.aggregateBinaryOperations(vect, cmb, new MatrixBlock(), abop);
// compare result with input
double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
TestUtils.compareMatrices(d1, d2, right ? rows : cols2, right ? cols2 : cols, 0.0000001);
} catch (Exception ex) {
throw new RuntimeException(ex);
} finally {
CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
}
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.
the class AggregateBinaryGPUInstruction method parseInstruction.
public static AggregateBinaryGPUInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
String opcode = parts[0];
if (!opcode.equalsIgnoreCase("ba+*"))
throw new DMLRuntimeException("AggregateBinaryInstruction.parseInstruction():: Unknown opcode " + opcode);
InstructionUtils.checkNumFields(parts, 5);
CPOperand in1 = new CPOperand(parts[1]);
CPOperand in2 = new CPOperand(parts[2]);
CPOperand out = new CPOperand(parts[3]);
boolean isLeftTransposed = Boolean.parseBoolean(parts[4]);
boolean isRightTransposed = Boolean.parseBoolean(parts[5]);
AggregateOperator agg = new AggregateOperator(0, Plus.getPlusFnObject());
AggregateBinaryOperator aggbin = new AggregateBinaryOperator(Multiply.getMultiplyFnObject(), agg, 1);
return new AggregateBinaryGPUInstruction(aggbin, in1, in2, out, opcode, str, isLeftTransposed, isRightTransposed);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.
the class GroupedAggregateMInstruction method parseInstruction.
public static GroupedAggregateMInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionParts(str);
InstructionUtils.checkNumFields(parts, 5);
byte in1 = Byte.parseByte(parts[1]);
byte in2 = Byte.parseByte(parts[2]);
byte out = Byte.parseByte(parts[3]);
int ngroups = Integer.parseInt(parts[4]);
// partitioning ignored
Operator op = new AggregateOperator(0, KahanPlus.getKahanPlusFnObject(), true, CorrectionLocationType.LASTCOLUMN);
return new GroupedAggregateMInstruction(op, in1, in2, out, ngroups, str);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.
the class UaggOuterChainInstruction method parseInstruction.
public static UaggOuterChainInstruction parseInstruction(String str) {
// check number of fields (2/3 inputs, output, type)
InstructionUtils.checkNumFields(str, 5);
// parse instruction parts (without exec type)
String[] parts = InstructionUtils.getInstructionParts(str);
AggregateUnaryOperator uaggop = InstructionUtils.parseBasicAggregateUnaryOperator(parts[1]);
BinaryOperator bop = InstructionUtils.parseBinaryOperator(parts[2]);
byte in1 = Byte.parseByte(parts[3]);
byte in2 = Byte.parseByte(parts[4]);
byte out = Byte.parseByte(parts[5]);
// derive aggregation operator from unary operator
String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(parts[1]);
CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(parts[1]);
String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
return new UaggOuterChainInstruction(bop, uaggop, aop, in1, in2, out, str);
}
use of org.apache.sysml.runtime.matrix.operators.AggregateOperator in project incubator-systemml by apache.
the class AggregateUnarySPInstruction method parseInstruction.
public static AggregateUnarySPInstruction parseInstruction(String str) {
String[] parts = InstructionUtils.getInstructionPartsWithValueType(str);
InstructionUtils.checkNumFields(parts, 3);
String opcode = parts[0];
CPOperand in1 = new CPOperand(parts[1]);
CPOperand out = new CPOperand(parts[2]);
SparkAggType aggtype = SparkAggType.valueOf(parts[3]);
String aopcode = InstructionUtils.deriveAggregateOperatorOpcode(opcode);
CorrectionLocationType corrLoc = InstructionUtils.deriveAggregateOperatorCorrectionLocation(opcode);
String corrExists = (corrLoc != CorrectionLocationType.NONE) ? "true" : "false";
AggregateUnaryOperator aggun = InstructionUtils.parseBasicAggregateUnaryOperator(opcode);
AggregateOperator aop = InstructionUtils.parseAggregateOperator(aopcode, corrExists, corrLoc.toString());
return new AggregateUnarySPInstruction(SPType.AggregateUnary, aggun, aop, in1, out, aggtype, opcode, str);
}
Aggregations