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();
}
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();
}
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();
}
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();
}
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();
}
Aggregations