Search in sources :

Example 11 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 12 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 13 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 14 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)

Example 15 with Modulus

use of org.apache.sysml.runtime.functionobjects.Modulus in project 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)

Aggregations

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