Skip to content

Commit

Permalink
Refactoring, remove r2js package for backward compatibility.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas CHABALIER committed Dec 19, 2023
1 parent fa67153 commit 52d2737
Show file tree
Hide file tree
Showing 11 changed files with 9 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.math.R.R2js;
package org.math.R;

import java.io.BufferedReader;
import java.io.File;
Expand All @@ -13,7 +13,6 @@
import java.util.stream.Collectors;

import org.apache.commons.io.FileUtils;
import org.math.R.*;

/**
* This class evaluate an R expression by parsing it in javascript expression
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
package org.math.R.R2js;

import org.math.R.RLog;
import org.math.R.RLogPrintStream;
import org.math.R.Rsession;
package org.math.R;

import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package org.math.R.R2js;
package org.math.R;

import java.util.ArrayList;
import java.util.List;
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/org/math/R/R.js
Original file line number Diff line number Diff line change
Expand Up @@ -558,12 +558,12 @@

function SysSetEnv(kv) {
for(var k in kv) {
Java.type('org.math.R.R2js.AbstractR2jsSession').setEnv(k,kv[k]);
Java.type('org.math.R.AbstractR2jsSession').setEnv(k,kv[k]);
}
}

function SysGetEnv(k) {
var v = Java.type('org.math.R.R2js.AbstractR2jsSession').getEnv(k);
var v = Java.type('org.math.R.AbstractR2jsSession').getEnv(k);
if (isNull(v))
return '';
return v;
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/math/R/BasicTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.math.R.R2js.AbstractR2jsSession;
import org.math.R.R2js.R2jsSession;

/**
*
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/math/R/BrentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.math.R.R2js.R2jsSession;
import org.math.R.R2js.AbstractR2jsSession;
import org.math.array.DoubleArray;
import org.math.array.LinearAlgebra;

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/math/R/GradientDescent1DTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.math.R.R2js.AbstractR2jsSession;
import org.math.R.R2js.R2jsSession;
import org.math.R.Rsession.RException;
import org.math.array.DoubleArray;

Expand Down
2 changes: 0 additions & 2 deletions src/test/java/org/math/R/GradientDescentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.math.R.R2js.AbstractR2jsSession;
import org.math.R.R2js.R2jsSession;
import org.math.R.Rsession.RException;
import org.math.array.DoubleArray;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.math.R.R2js;
package org.math.R;

import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.math.R.AbstractR2jsSession;
import org.math.R.R2jsUtils;
import org.math.R.Rsession;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.math.R.R2js;
package org.math.R;

import java.io.*;
import java.net.InetAddress;
Expand All @@ -16,8 +16,6 @@
//import org.graalvm.polyglot.*;

import org.junit.Test;
import org.math.R.RLog;
import org.math.R.RLogSlf4j;
import org.math.R.Rsession.RException;

import static org.junit.Assert.*;
Expand Down Expand Up @@ -1484,87 +1482,4 @@ public void testDecimalPoints() throws RException {
assert (Double) engine.eval("1e-31+1e-32") == 1.1e-31;
assertEquals((Double) engine.eval("1e-31*1e-32"), 1e-63, 1e-75); //"normal" floating error of 1e-15 on multiplication
}

// @Test
// public void testEvaluationTime() throws RException, ScriptException, IOException {
// String MATH_JS_FILE = "/org/math/R/math.js";
// InputStream mathInputStream = this.getClass().getResourceAsStream(MATH_JS_FILE);
////
////
//// StringBuilder textBuilder = new StringBuilder();
//// try (Reader reader = new BufferedReader(new InputStreamReader
//// (mathInputStream, StandardCharsets.UTF_8))) {
//// int c = 0;
//// while ((c = reader.read()) != -1) {
//// textBuilder.append((char) c);
//// }
//// }
////
//// Context polyglotContext = Context.create();
//
////
//// //polyglotContext.eval("js", textBuilder);
//
//
// // POLYGLOT
//// long time1 = System.currentTimeMillis();
//// Source scriptSource = Source.newBuilder("js",new File("/home/chabs/Documents/workspaces/rsession/src/main/resources/org/math/R/math.js")).build();
//// Engine engine = Engine.create();
//// Context ctx = Context.newBuilder()
//// .engine(engine)
//// .build();
//// long time2 = System.currentTimeMillis();
////
//// Value result = ctx.eval(scriptSource);
//// //Value math = ctx.getBindings("js").getMember("math");
//// System.out.println("Res=" + ctx.eval("js", "math.add(1,2)"));
////
//// long time3 = System.currentTimeMillis();
////
//// //Context newContext = Context.newBuilder("js").(true).option("js.foreign-object-prototype", Boolean.TRUE.toString()).build();
//// Context newContext = Context.newBuilder()
//// .engine(engine)
//// .build();
//// newContext.eval(scriptSource);
//// //newContext.getBindings("js").putMember("math", math);
////
//// System.out.println("Res=" + newContext.eval("js", "math.add(1,11)"));
////
//// long time4 = System.currentTimeMillis();
////
//// System.out.println("Evaluation time polyglot:" + (time2 - time1) + " ms");
//// System.out.println("Evaluation time polyglot:" + (time3 - time2) + " ms");
//// System.out.println("Evaluation time polyglot:" + (time4 - time3) + " ms");
//
//
//
// long time1 = System.currentTimeMillis();
// ScriptEngineManager manager = new ScriptEngineManager(null);
// long time11 = System.currentTimeMillis();
// ScriptEngine js = manager.getEngineByName("JavaScript");
// if (js==null) js = manager.getEngineByName("js");
// if (js==null) js = manager.getEngineByExtension("js");
// if (js==null) js = manager.getEngineByName("nashorn");
// if (js==null) js = manager.getEngineByName("Nashorn");
// //if (js==null) js = new jdk.nashorn.api.scripting.NashornScriptEngineFactory().getScriptEngine();
// if (js==null) throw new IllegalArgumentException("Could not load JavaScript ScriptEngine: "+manager.getEngineFactories());
//
// long time2 = System.currentTimeMillis();
// js.eval(new InputStreamReader(mathInputStream, Charset.forName("UTF-8")));
// System.out.println("Res="+ js.eval("math.add(1,2)"));
// Object math = js.get("math");
// long time3 = System.currentTimeMillis();
// ScriptEngine js2 = manager.getEngineByName("JavaScript");
// //System.out.println("Res="+ js2.eval("math.add(1,11)"));
// js2.put("math", math);
// System.out.println("Res="+ js2.eval("math.add(1,11)"));
// long time4 = System.currentTimeMillis();
//
// System.out.println("Evaluation time polyglot---:" + (time11 - time1) + " ms");
// System.out.println("Evaluation time polyglot:" + (time2 - time1) + " ms");
// System.out.println("Evaluation time polyglot:" + (time3 - time2) + " ms");
// System.out.println("Evaluation time polyglot:" + (time4 - time3) + " ms");
//
// }

}
2 changes: 0 additions & 2 deletions src/test/java/org/math/R/RPanelsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.math.R.R2js.AbstractR2jsSession;
import org.math.R.R2js.R2jsSession;
import org.math.R.Rsession.RException;

/**
Expand Down

0 comments on commit 52d2737

Please sign in to comment.