Search in sources :

Example 16 with RightScalarOperator

use of org.apache.sysml.runtime.matrix.operators.RightScalarOperator in project systemml by apache.

the class BasicScalarOperationsTest method runScalarOperationsTest.

private static void runScalarOperationsTest(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();
        // matrix-scalar uncompressed
        ScalarOperator sop = new RightScalarOperator(Multiply.getMultiplyFnObject(), 7);
        MatrixBlock ret1 = (MatrixBlock) mb.scalarOperations(sop, new MatrixBlock());
        // matrix-scalar compressed
        MatrixBlock ret2 = (MatrixBlock) cmb.scalarOperations(sop, new MatrixBlock());
        if (compress)
            ret2 = ((CompressedMatrixBlock) ret2).decompress();
        // compare result with input
        double[][] d1 = DataConverter.convertToDoubleMatrix(ret1);
        double[][] d2 = DataConverter.convertToDoubleMatrix(ret2);
        TestUtils.compareMatrices(d1, d2, rows, cols, 0.0000001);
    } catch (Exception ex) {
        throw new RuntimeException(ex);
    } finally {
        CompressedMatrixBlock.ALLOW_DDC_ENCODING = true;
    }
}
Also used : CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator) ScalarOperator(org.apache.sysml.runtime.matrix.operators.ScalarOperator) CompressedMatrixBlock(org.apache.sysml.runtime.compress.CompressedMatrixBlock) MatrixBlock(org.apache.sysml.runtime.matrix.data.MatrixBlock) RightScalarOperator(org.apache.sysml.runtime.matrix.operators.RightScalarOperator)

Aggregations

RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)16 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)9 LeftScalarOperator (org.apache.sysml.runtime.matrix.operators.LeftScalarOperator)8 ScalarOperator (org.apache.sysml.runtime.matrix.operators.ScalarOperator)8 Minus1Multiply (org.apache.sysml.runtime.functionobjects.Minus1Multiply)6 Pointer (jcuda.Pointer)4 CompressedMatrixBlock (org.apache.sysml.runtime.compress.CompressedMatrixBlock)4 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)4 KahanPlus (org.apache.sysml.runtime.functionobjects.KahanPlus)4 Multiply (org.apache.sysml.runtime.functionobjects.Multiply)4 Plus (org.apache.sysml.runtime.functionobjects.Plus)4 CSRPointer (org.apache.sysml.runtime.instructions.gpu.context.CSRPointer)4 MatrixBlock (org.apache.sysml.runtime.matrix.data.MatrixBlock)4 BinaryOperator (org.apache.sysml.runtime.matrix.operators.BinaryOperator)4 And (org.apache.sysml.runtime.functionobjects.And)2 Builtin (org.apache.sysml.runtime.functionobjects.Builtin)2 CM (org.apache.sysml.runtime.functionobjects.CM)2 Divide (org.apache.sysml.runtime.functionobjects.Divide)2 Equals (org.apache.sysml.runtime.functionobjects.Equals)2 GreaterThan (org.apache.sysml.runtime.functionobjects.GreaterThan)2