Skip to content
Snippets Groups Projects
Commit 0c73338c authored by stepan's avatar stepan
Browse files

Implement 'rf'

parent 93f745dc
No related branches found
No related tags found
No related merge requests found
/*
* This material is distributed under the GNU General Public License
* Version 2. You may review the terms of this license at
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Copyright (C) 1998 Ross Ihaka
* Copyright (c) 1998--2008, The R Core Team
* Copyright (c) 2016, 2016, Oracle and/or its affiliates
*
* All rights reserved.
*/
package com.oracle.truffle.r.library.stats;
import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandomNumberProvider;
public final class RChisq {
public static double rchisq(double df, RandomNumberProvider rand) {
if (!Double.isFinite(df) || df < 0.0) {
return StatsUtil.mlError();
}
return new RGamma().evaluate(df / 2.0, 2.0, rand);
}
}
/*
* This material is distributed under the GNU General Public License
* Version 2. You may review the terms of this license at
* http://www.gnu.org/licenses/gpl-2.0.html
*
* Copyright (C) 1998 Ross Ihaka
* Copyright (c) 1998--2008, The R Core Team
* Copyright (c) 2016, 2016, Oracle and/or its affiliates
*
* All rights reserved.
*/
package com.oracle.truffle.r.library.stats;
import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandFunction2_Double;
import com.oracle.truffle.r.library.stats.RandGenerationFunctions.RandomNumberProvider;
public final class Rf implements RandFunction2_Double {
@Override
public double evaluate(double n1, double n2, RandomNumberProvider rand) {
if (Double.isNaN(n1) || Double.isNaN(n2) || n1 <= 0. || n2 <= 0.) {
return StatsUtil.mlError();
}
double v1;
double v2;
v1 = Double.isFinite(n1) ? (RChisq.rchisq(n1, rand) / n1) : 1;
v2 = Double.isFinite(n2) ? (RChisq.rchisq(n2, rand) / n2) : 1;
return v1 / v2;
}
}
......@@ -59,6 +59,7 @@ import com.oracle.truffle.r.library.stats.RCauchy;
import com.oracle.truffle.r.library.stats.RGamma;
import com.oracle.truffle.r.library.stats.RandGenerationFunctionsFactory;
import com.oracle.truffle.r.library.stats.Rbinom;
import com.oracle.truffle.r.library.stats.Rf;
import com.oracle.truffle.r.library.stats.Rnorm;
import com.oracle.truffle.r.library.stats.Runif;
import com.oracle.truffle.r.library.stats.SplineFunctionsFactory.SplineCoefNodeGen;
......@@ -375,6 +376,8 @@ public class ForeignFunctions {
return RandGenerationFunctionsFactory.Function2_DoubleNodeGen.create(new RGamma());
case "rcauchy":
return RandGenerationFunctionsFactory.Function2_DoubleNodeGen.create(new RCauchy());
case "rf":
return RandGenerationFunctionsFactory.Function2_DoubleNodeGen.create(new Rf());
case "qgamma":
return StatsFunctionsFactory.Function3_2NodeGen.create(new QgammaFunc());
case "dbinom":
......
......@@ -31,7 +31,7 @@ import com.oracle.truffle.r.test.TestBase;
* tests for its specific corner cases if those are not covered here.
*/
public class TestRandGenerationFunctions extends TestBase {
private static final String[] FUNCTION2_NAMES = {"rnorm", "runif", "rgamma", "rbeta", "rcauchy"};
private static final String[] FUNCTION2_NAMES = {"rnorm", "runif", "rgamma", "rbeta", "rcauchy", "rf"};
private static final String[] FUNCTION2_PARAMS = {
"10, 10, 10",
"20, c(-1, 0, 0.2, 2:5), c(-1, 0, 0.1, 0.9, 3)",
......
......@@ -58,6 +58,8 @@ com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/TOMS708.java
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/SNorm.java,gnu_r_ihaka_core.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/SExp.java,gnu_r_ihaka_core.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RGamma.java,gnu_r_ihaka_core.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Rf.java,gnu_r_ihaka_core.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RChisq.java,gnu_r_ihaka_core.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/tools/DirChmod.java,gnu_r.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/tools/ToolsText.java,gnu_r.copyright
com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/utils/CountFields.java,gnu_r.copyright
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment