我目前正在使用Ro.getElementAsDouble(index)
(代码如下)将值Ro
一一提取到LogNormArray
(double[]
)中。但我担心副本会浪费内存。我是java的新手,如果我不正确地考虑这个问题,我深表歉意。在 CI 中,会复制一个地址来“共享”数据,而不是复制整个数组。是否有类似的指针/地址传递工作流程?
我正在使用的玩具示例:
import java.util.Arrays;
import javax.script.*;
import org.renjin.sexp.*;
import org.renjin.script.*;
public class VectorRenjin {
public static void main(String[] args) throws Exception {
double[] LogNormArray = new double[10];
Vector Ro = LogNormalRand(10,0.0,1.0);
System.out.println("draws from log-normal " + Ro);
for(int i=0;i< Ro.length();i++) LogNormArray[i] = Ro.getElementAsDouble(i);
System.out.println("draws from log-normal " + Arrays.toString(LogNormArray));
}
public static Vector LogNormalRand(int n,double a, double b) throws Exception{
// create a script engine manager:
RenjinScriptEngineFactory factory = new RenjinScriptEngineFactory();
ScriptEngine engine = factory.getScriptEngine();
engine.put("n",n);
engine.put("a",a);
engine.put("b",b);
Vector res = (Vector)engine.eval("rlnorm(n,a,b)");
return res;
}
}