Search in sources :

Example 6 with Modulus

use of org.apache.sysml.runtime.functionobjects.Modulus in project incubator-systemml by apache.

the class ScalarModulusTest method testIntConst.

@Test
public void testIntConst() {
    int rows = 10;
    int cols = 10;
    int divisor = 20;
    int dividend = 20;
    TestConfiguration config = availableTestConfigurations.get("IntConstTest");
    config.addVariable("rows", rows);
    config.addVariable("cols", cols);
    config.addVariable("vardeclaration", "");
    config.addVariable("divisor", divisor);
    config.addVariable("dividend", dividend);
    loadTestConfiguration(config);
    double[][] vector = getNonZeroRandomMatrix(rows, 1, 1, 5, -1);
    double[][] computedVectorLeft = new double[rows][1];
    double[][] computedVectorRight = new double[rows][1];
    Modulus fnmod = Modulus.getFnObject();
    for (int i = 0; i < rows; i++) {
        computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor);
        computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]);
    }
    writeInputMatrix("vector", vector);
    writeExpectedMatrix("vector_left", computedVectorLeft);
    writeExpectedMatrix("vector_right", computedVectorRight);
    double[][] matrix = getNonZeroRandomMatrix(rows, cols, 1, 5, -1);
    double[][] computedMatrixLeft = new double[rows][cols];
    double[][] computedMatrixRight = new double[rows][cols];
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            computedMatrixLeft[i][j] = fnmod.execute(matrix[i][j], divisor);
            computedMatrixRight[i][j] = fnmod.execute(dividend, matrix[i][j]);
        }
    }
    writeInputMatrix("matrix", matrix);
    writeExpectedMatrix("matrix_left", computedMatrixLeft);
    writeExpectedMatrix("matrix_right", computedMatrixRight);
    runTest();
    compareResults();
}
Also used : Modulus(org.apache.sysml.runtime.functionobjects.Modulus) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) Test(org.junit.Test)

Example 7 with Modulus

use of org.apache.sysml.runtime.functionobjects.Modulus in project incubator-systemml by apache.

the class ElementwiseModulusTest method testDense.

@Test
public void testDense() {
    int rows = 10;
    int cols = 10;
    TestConfiguration config = availableTestConfigurations.get("DenseTest");
    config.addVariable("rows", rows);
    config.addVariable("cols", cols);
    loadTestConfiguration(config);
    double[][] a = getRandomMatrix(rows, cols, -5, 5, 1, -1);
    double[][] b = getNonZeroRandomMatrix(rows, cols, -20, 20, -1);
    double[][] c = new double[rows][cols];
    Modulus fnmod = Modulus.getFnObject();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            c[i][j] = fnmod.execute(a[i][j], b[i][j]);
        }
    }
    writeInputMatrix("a", a);
    writeInputMatrix("b", b);
    writeExpectedMatrix("c", c);
    runTest();
    compareResults();
}
Also used : Modulus(org.apache.sysml.runtime.functionobjects.Modulus) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) Test(org.junit.Test)

Example 8 with Modulus

use of org.apache.sysml.runtime.functionobjects.Modulus in project incubator-systemml by apache.

the class ElementwiseModulusTest method testDivisionByZero.

@Test
public void testDivisionByZero() {
    int rows = 10;
    int cols = 10;
    TestConfiguration config = availableTestConfigurations.get("DivisionByZeroTest");
    config.addVariable("rows", rows);
    config.addVariable("cols", cols);
    loadTestConfiguration(config);
    double[][] a = getRandomMatrix(rows, cols, -1, 1, 0.5, -1);
    double[][] b = getRandomMatrix(rows, cols, -1, 1, 0.5, -1);
    double[][] c = new double[rows][cols];
    Modulus fnmod = Modulus.getFnObject();
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            c[i][j] = fnmod.execute(a[i][j], b[i][j]);
        }
    }
    writeInputMatrix("a", a);
    writeInputMatrix("b", b);
    writeExpectedMatrix("c", c);
    runTest();
    compareResults();
}
Also used : Modulus(org.apache.sysml.runtime.functionobjects.Modulus) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) Test(org.junit.Test)

Example 9 with Modulus

use of org.apache.sysml.runtime.functionobjects.Modulus in project incubator-systemml by apache.

the class ScalarModulusTest method testSparse.

@Test
public void testSparse() {
    int rows = 100;
    int cols = 50;
    int divisor = 20;
    int dividend = 20;
    TestConfiguration config = availableTestConfigurations.get("SparseTest");
    config.addVariable("rows", rows);
    config.addVariable("cols", cols);
    config.addVariable("vardeclaration", "");
    config.addVariable("divisor", divisor);
    config.addVariable("dividend", dividend);
    loadTestConfiguration(config);
    double[][] vector = getRandomMatrix(rows, 1, 1, 5, 0.05, -1);
    double[][] computedVectorLeft = new double[rows][1];
    double[][] computedVectorRight = new double[rows][1];
    Modulus fnmod = Modulus.getFnObject();
    for (int i = 0; i < rows; i++) {
        computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor);
        computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]);
    }
    writeInputMatrix("vector", vector);
    writeExpectedMatrix("vector_left", computedVectorLeft);
    writeExpectedMatrix("vector_right", computedVectorRight);
    double[][] matrix = getRandomMatrix(rows, cols, -1, 1, 0.05, -1);
    double[][] computedMatrixLeft = new double[rows][cols];
    double[][] computedMatrixRight = new double[rows][cols];
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            computedMatrixLeft[i][j] = fnmod.execute(matrix[i][j], divisor);
            computedMatrixRight[i][j] = fnmod.execute(dividend, matrix[i][j]);
        }
    }
    writeInputMatrix("matrix", matrix);
    writeExpectedMatrix("matrix_left", computedMatrixLeft);
    writeExpectedMatrix("matrix_right", computedMatrixRight);
    runTest();
    compareResults();
}
Also used : Modulus(org.apache.sysml.runtime.functionobjects.Modulus) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) Test(org.junit.Test)

Example 10 with Modulus

use of org.apache.sysml.runtime.functionobjects.Modulus in project incubator-systemml by apache.

the class ScalarModulusTest method testDoubleConst.

@Test
public void testDoubleConst() {
    int rows = 10;
    int cols = 10;
    int divisor = 20;
    int dividend = 20;
    TestConfiguration config = availableTestConfigurations.get("DoubleConstTest");
    config.addVariable("rows", rows);
    config.addVariable("cols", cols);
    config.addVariable("vardeclaration", "");
    config.addVariable("divisor", divisor);
    config.addVariable("dividend", dividend);
    loadTestConfiguration(config);
    double[][] vector = getNonZeroRandomMatrix(rows, 1, 1, 5, -1);
    double[][] computedVectorLeft = new double[rows][1];
    double[][] computedVectorRight = new double[rows][1];
    Modulus fnmod = Modulus.getFnObject();
    for (int i = 0; i < rows; i++) {
        computedVectorLeft[i][0] = fnmod.execute(vector[i][0], divisor);
        computedVectorRight[i][0] = fnmod.execute(dividend, vector[i][0]);
    }
    writeInputMatrix("vector", vector);
    writeExpectedMatrix("vector_left", computedVectorLeft);
    writeExpectedMatrix("vector_right", computedVectorRight);
    double[][] matrix = getNonZeroRandomMatrix(rows, cols, 1, 5, -1);
    double[][] computedMatrixLeft = new double[rows][cols];
    double[][] computedMatrixRight = new double[rows][cols];
    for (int i = 0; i < rows; i++) {
        for (int j = 0; j < cols; j++) {
            computedMatrixLeft[i][j] = fnmod.execute(matrix[i][j], divisor);
            computedMatrixRight[i][j] = fnmod.execute(dividend, matrix[i][j]);
        }
    }
    writeInputMatrix("matrix", matrix);
    writeExpectedMatrix("matrix_left", computedMatrixLeft);
    writeExpectedMatrix("matrix_right", computedMatrixRight);
    runTest();
    compareResults();
}
Also used : Modulus(org.apache.sysml.runtime.functionobjects.Modulus) TestConfiguration(org.apache.sysml.test.integration.TestConfiguration) Test(org.junit.Test)

Aggregations

Modulus (org.apache.sysml.runtime.functionobjects.Modulus)10 TestConfiguration (org.apache.sysml.test.integration.TestConfiguration)9 Test (org.junit.Test)9 Pointer (jcuda.Pointer)1 DMLRuntimeException (org.apache.sysml.runtime.DMLRuntimeException)1 MatrixObject (org.apache.sysml.runtime.controlprogram.caching.MatrixObject)1 Divide (org.apache.sysml.runtime.functionobjects.Divide)1 IntegerDivide (org.apache.sysml.runtime.functionobjects.IntegerDivide)1 Minus1Multiply (org.apache.sysml.runtime.functionobjects.Minus1Multiply)1 CSRPointer (org.apache.sysml.runtime.instructions.gpu.context.CSRPointer)1 LeftScalarOperator (org.apache.sysml.runtime.matrix.operators.LeftScalarOperator)1 RightScalarOperator (org.apache.sysml.runtime.matrix.operators.RightScalarOperator)1