我目前使用Ro.getElementAsDouble(index)
(代碼如下)將Ro
中的值逐個提取爲LogNormArray
(double[]
)。但我擔心副本會浪費內存。我非常喜歡java的新手,所以如果我不正確地考慮這個問題,我很抱歉。在C我會複製一個地址來「共享」數據,而不是應對整個數組。是否有類似的指針/地址傳遞工作流程?Renjin/Java - Vector class to Java array class
玩具實施例我正在使用:
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;
}
}
謝謝,我真的在挖人淨項目! – csta