Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/test/java/org/apache/sysds/test/AutomatedTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -1649,6 +1649,8 @@ protected String getScript() {
}

protected String getRScript() {
if(fullRScriptName != null)
return fullRScriptName;
return sourceDirectory + selectedTest + ".R";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
import static org.apache.sysds.api.mlcontext.ScriptFactory.dmlFromFile;

import org.apache.log4j.Logger;
import org.junit.Test;
import org.apache.sysds.api.mlcontext.Script;
import org.apache.sysds.runtime.matrix.data.MatrixBlock;
import org.apache.sysds.runtime.matrix.data.MatrixValue;
import org.apache.sysds.test.TestUtils;
import org.junit.Test;

import java.util.HashMap;

public class MLContextLinregTest extends MLContextTestBase {
protected static Logger log = Logger.getLogger(MLContextLinregTest.class);
Expand All @@ -37,6 +42,11 @@ public enum LinregType {
CG, DS,
}

private final static double eps = 1e-3;

private final static int rows = 2468;
private final static int cols = 507;

@Test
public void testLinregCGSparse() {
runLinregTestMLC(LinregType.CG, true);
Expand All @@ -59,24 +69,42 @@ public void testLinregDSDense() {

private void runLinregTestMLC(LinregType type, boolean sparse) {

double[][] X = getRandomMatrix(10, 3, 0, 1, sparse ? sparsity2 : sparsity1, 7);
double[][] Y = getRandomMatrix(10, 1, 0, 10, 1.0, 3);
double[][] X = getRandomMatrix(rows, cols, 0, 1, sparse ? sparsity2 : sparsity1, 7);
double[][] Y = getRandomMatrix(rows, 1, 0, 10, 1.0, 3);

// Hack Alert
// overwrite baseDirectory to the place where test data is stored.
baseDirectory = "target/testTemp/functions/mlcontext/";

fullRScriptName = "src/test/scripts/functions/codegenalg/Algorithm_LinregCG.R";

writeInputMatrixWithMTD("X", X, true);
writeInputMatrixWithMTD("y", Y, true);

rCmd = getRCmd(inputDir(), "0", "0.000001", "0", "0.001", expectedDir());
runRScript(true);

MatrixBlock outmat = new MatrixBlock();

switch (type) {
case CG:
Script lrcg = dmlFromFile(TEST_SCRIPT_CG);
lrcg.in("X", X).in("y", Y).in("$icpt", "0").in("$tol", "0.000001").in("$maxi", "0").in("$reg", "0.000001")
.out("beta_out");
ml.execute(lrcg);
outmat = ml.execute(lrcg).getMatrix("beta_out").toMatrixBlock();

break;

case DS:
Script lrds = dmlFromFile(TEST_SCRIPT_DS);
lrds.in("X", X).in("y", Y).in("$icpt", "0").in("$reg", "0.000001").out("beta_out");
ml.execute(lrds);
outmat = ml.execute(lrds).getMatrix("beta_out").toMatrixBlock();

break;
}

//compare matrices
HashMap<MatrixValue.CellIndex, Double> rfile = readRMatrixFromFS("w");
TestUtils.compareMatrices(rfile, outmat, eps);
}
}