diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Cauchy.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Cauchy.java index f316640b6f3d78f09dac706a26d94790e5bf5a36..29452d13c149ec4e743c597ffc7a99f6c42508fa 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Cauchy.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Cauchy.java @@ -67,13 +67,13 @@ public final class Cauchy { return RMath.mlError(); } - x = (x - location) / scale; - if (Double.isNaN(x)) { + double x2 = (x - location) / scale; + if (Double.isNaN(x2)) { return RMath.mlError(); } - if (!Double.isFinite(x)) { - if (x < 0) { + if (!Double.isFinite(x2)) { + if (x2 < 0) { return DPQ.rdt0(lowerTail, logP); } else { return DPQ.rdt1(lowerTail, logP); @@ -81,7 +81,7 @@ public final class Cauchy { } if (!lowerTail) { - x = -x; + x2 = -x2; } /* @@ -91,18 +91,19 @@ public final class Cauchy { // GnuR has #ifdef HAVE_ATANPI where it uses atanpi function, here we only implement the // case when atanpi is not available for the moment - if (fabs(x) > 1) { - double y = Math.atan(1 / x) / M_PI; - return (x > 0) ? DPQ.rdclog(y, logP) : DPQ.rdval(-y, logP); + if (fabs(x2) > 1) { + double y = Math.atan(1 / x2) / M_PI; + return (x2 > 0) ? DPQ.rdclog(y, logP) : DPQ.rdval(-y, logP); } else { - return DPQ.rdval(0.5 + Math.atan(x) / M_PI, logP); + return DPQ.rdval(0.5 + Math.atan(x2) / M_PI, logP); } } } public static final class QCauchy implements Function3_2 { @Override - public double evaluate(double p, double location, double scale, boolean lowerTail, boolean logP) { + public double evaluate(double pIn, double location, double scale, boolean lowerTailIn, boolean logP) { + double p = pIn; if (Double.isNaN(p) || Double.isNaN(location) || Double.isNaN(scale)) { return p + location + scale; } @@ -118,6 +119,7 @@ public final class Cauchy { return RMath.mlError(); } + boolean lowerTail = lowerTailIn; if (logP) { if (p > -1) { /* diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Exp.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Exp.java index 0d3e6ecbc329391c74220746d77accc7919f6f49..e2cdac1583938382aa95390c34c6e4d0411515c2 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Exp.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Exp.java @@ -53,20 +53,20 @@ public final class Exp { public static final class PExp implements Function2_2 { @Override - public double evaluate(double x, double scale, boolean lowerTail, boolean logP) { - if (Double.isNaN(x) || Double.isNaN(scale)) { - return x + scale; + public double evaluate(double xIn, double scale, boolean lowerTail, boolean logP) { + if (Double.isNaN(xIn) || Double.isNaN(scale)) { + return xIn + scale; } if (scale < 0) { return RMath.mlError(); } - if (x <= 0.) { + if (xIn <= 0.) { return DPQ.rdt0(lowerTail, logP); } /* same as weibull( shape = 1): */ - x = -(x / scale); + double x = -(xIn / scale); return lowerTail ? (logP ? DPQ.rlog1exp(x) : -RMath.expm1(x)) : DPQ.rdexp(x, logP); } } @@ -93,7 +93,6 @@ public final class Exp { } return -scale * DPQ.rdtclog(p, lowerTail, logP); - } } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/GammaFunctions.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/GammaFunctions.java index 1638c38e2ce080d756db52c1c368bd0c9044230a..2a700e05a9605b176c60f1b734439fdcb02bb986 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/GammaFunctions.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/GammaFunctions.java @@ -187,7 +187,7 @@ public abstract class GammaFunctions { return 1 / (x * 12); } - static double lgamma(double x) { + static double lgamma(@SuppressWarnings("unused") double x) { throw RError.nyi(RError.SHOW_CALLER, "lgamma from libc"); } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QHyper.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QHyper.java index c3a43d3259eba623afcabfc64774ea901a893bbf..9a54383f82decd95101bb995de5f6fe776e444f4 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QHyper.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/QHyper.java @@ -20,27 +20,19 @@ import static com.oracle.truffle.r.library.stats.RMath.lfastchoose; import com.oracle.truffle.r.library.stats.DPQ.EarlyReturn; public final class QHyper { - public static double qhyper(double p, double nr, double nb, double n, boolean lowerTail, boolean logP) { + public static double qhyper(double pIn, double nrIn, double nbIn, double nIn, boolean lowerTail, boolean logP) { /* This is basically the same code as ./phyper.c *used* to be --> FIXME! */ - double capN; - double xstart; - double xend; - double xr; - double xb; - double sum; - double term; - boolean smallN; - if (Double.isNaN(p) || Double.isNaN(nr) || Double.isNaN(nb) || Double.isNaN(n)) { - return p + nr + nb + n; + if (Double.isNaN(pIn) || Double.isNaN(nrIn) || Double.isNaN(nbIn) || Double.isNaN(nIn)) { + return pIn + nrIn + nbIn + nIn; } - if (!Double.isFinite(p) || !Double.isFinite(nr) || !Double.isFinite(nb) || !Double.isFinite(n)) { + if (!Double.isFinite(pIn) || !Double.isFinite(nrIn) || !Double.isFinite(nbIn) || !Double.isFinite(nIn)) { return RMath.mlError(); } - nr = forceint(nr); - nb = forceint(nb); - capN = nr + nb; - n = forceint(n); + double nr = forceint(nrIn); + double nb = forceint(nbIn); + double capN = nr + nb; + double n = forceint(nIn); if (nr < 0 || nb < 0 || n < 0 || n > capN) { return RMath.mlError(); } @@ -50,24 +42,25 @@ public final class QHyper { * - 1, NR,NB, n) */ - xstart = fmax2(0, n - nb); - xend = fmin2(n, nr); + double xstart = fmax2(0, n - nb); + double xend = fmin2(n, nr); + double p = pIn; try { DPQ.rqp01boundaries(p, xstart, xend, lowerTail, logP); } catch (EarlyReturn ex) { return ex.result; } - xr = xstart; - xb = n - xr; /* always ( = #{black balls in sample} ) */ + double xr = xstart; + double xb = n - xr; /* always ( = #{black balls in sample} ) */ - smallN = (capN < 1000); /* won't have underflow in product below */ + boolean smallN = (capN < 1000); /* won't have underflow in product below */ /* * if N is small, term := product.ratio( bin.coef ); otherwise work with its Math.logarithm * to protect against underflow */ - term = lfastchoose(nr, xr) + lfastchoose(nb, xb) - lfastchoose(capN, n); + double term = lfastchoose(nr, xr) + lfastchoose(nb, xb) - lfastchoose(capN, n); if (smallN) { term = Math.exp(term); } @@ -78,7 +71,7 @@ public final class QHyper { p = DPQ.rdtqiv(p, lowerTail, logP); } p *= 1 - 1000 * DBL_EPSILON; /* was 64, but failed on FreeBSD sometimes */ - sum = smallN ? term : Math.exp(term); + double sum = smallN ? term : Math.exp(term); while (sum < p && xr < xend) { xr++; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RBeta.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RBeta.java index 5e1ce8ccb67f9fe4a5636c9194a4bcdf78437e24..714014b84e2fb45938f67394e8586fb4e360fee2 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RBeta.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RBeta.java @@ -43,17 +43,8 @@ public final class RBeta extends RandFunction2_Double { return 0.0; } - double a; - double b; - double r; - double s; - double t; - double u1; - double u2; double v = 0; double w = 0; - double y; - double z; // TODO: state variables double beta = 0; @@ -71,8 +62,8 @@ public final class RBeta extends RandFunction2_Double { oldb = bb; } - a = fmin2(aa, bb); - b = fmax2(aa, bb); /* a <= b */ + double a = fmin2(aa, bb); + double b = fmax2(aa, bb); /* a <= b */ double alpha = a + b; if (a <= 1.0) { /* --- Algorithm BC --- */ @@ -85,10 +76,11 @@ public final class RBeta extends RandFunction2_Double { } /* FIXME: "do { } while()", but not trivially because of "continue"s: */ for (;;) { - u1 = rand.unifRand(); - u2 = rand.unifRand(); + double u1 = rand.unifRand(); + double u2 = rand.unifRand(); + double z; if (u1 < 0.5) { - y = u1 * u2; + double y = u1 * u2; z = u1 * y; if (0.25 * u2 + z - y >= k1) { continue; @@ -97,7 +89,7 @@ public final class RBeta extends RandFunction2_Double { z = u1 * u1 * u2; if (z <= 0.25) { v = beta * Math.log(u1 / (1.0 - u1)); - w = wFromU1Bet(b, v, w); + w = wFromU1Bet(b, v); break; } if (z >= k2) { @@ -106,7 +98,7 @@ public final class RBeta extends RandFunction2_Double { } v = beta * Math.log(u1 / (1.0 - u1)); - w = wFromU1Bet(b, v, w); + w = wFromU1Bet(b, v); if (alpha * (Math.log(alpha / (a + w)) + v) - 1.3862944 >= Math.log(z)) { break; @@ -120,16 +112,18 @@ public final class RBeta extends RandFunction2_Double { beta = Math.sqrt((alpha - 2.0) / (2.0 * a * b - alpha)); gamma = a + 1.0 / beta; } + double r; + double t; do { - u1 = rand.unifRand(); - u2 = rand.unifRand(); + double u1 = rand.unifRand(); + double u2 = rand.unifRand(); v = beta * Math.log(u1 / (1.0 - u1)); - w = wFromU1Bet(a, v, w); + w = wFromU1Bet(a, v); - z = u1 * u1 * u2; + double z = u1 * u1 * u2; r = gamma * v - 1.3862944; - s = a + r - w; + double s = a + r - w; if (s + 2.609438 >= 5.0 * z) { break; } @@ -143,16 +137,13 @@ public final class RBeta extends RandFunction2_Double { } } - private static double wFromU1Bet(double aa, double v, double w) { + private static double wFromU1Bet(double aa, double v) { if (v <= expmax) { - w = aa * Math.exp(v); - if (!Double.isFinite(w)) { - w = Double.MAX_VALUE; - } + double result = aa * Math.exp(v); + return Double.isFinite(result) ? result : Double.MAX_VALUE; } else { - w = Double.MAX_VALUE; + return Double.MAX_VALUE; } - return w; } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RHyper.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RHyper.java index 7af8863b92164203fd5a0d8ccf56771a7d0e940b..4cd77bcd0f57d21cd29bf67ae35f76dffd84e88a 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RHyper.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RHyper.java @@ -34,7 +34,7 @@ public final class RHyper extends RandFunction3_Double { /* * 10.60460290274525022841722740072165, approx. value below = 10.6046028788027; * rel.error = 2.26 10^{-9} - * + * * FIXME: Use constants and if(n > ..) decisions from ./stirlerr.c ----- will be * even *faster* for n > 500 (or so) */ @@ -90,12 +90,7 @@ public final class RHyper extends RandFunction3_Double { public double execute(double nn1in, double nn2in, double kkin, RandomNumberProvider rand) { /* extern double afc(int); */ - int nn1; - int nn2; - int kk; int ix; // return value (coerced to double at the very end) - boolean setup1; - boolean setup2; /* check parameter validity */ @@ -103,30 +98,32 @@ public final class RHyper extends RandFunction3_Double { return RMath.mlError(); } - nn1in = forceint(nn1in); - nn2in = forceint(nn2in); - kkin = forceint(kkin); + double nn1int = forceint(nn1in); + double nn2int = forceint(nn2in); + double kkint = forceint(kkin); - if (nn1in < 0 || nn2in < 0 || kkin < 0 || kkin > nn1in + nn2in) { + if (nn1int < 0 || nn2int < 0 || kkint < 0 || kkint > nn1int + nn2int) { return RMath.mlError(); } - if (nn1in >= Integer.MAX_VALUE || nn2in >= Integer.MAX_VALUE || kkin >= Integer.MAX_VALUE) { + if (nn1int >= Integer.MAX_VALUE || nn2int >= Integer.MAX_VALUE || kkint >= Integer.MAX_VALUE) { /* * large n -- evade integer overflow (and inappropriate algorithms) -------- */ // FIXME: Much faster to give rbinom() approx when appropriate; -> see Kuensch(1989) // Johnson, Kotz,.. p.258 (top) mention the *four* different binomial approximations - if (kkin == 1.) { // Bernoulli - return rbinom.execute(kkin, nn1in / (nn1in + nn2in), rand); + if (kkint == 1.) { // Bernoulli + return rbinom.execute(kkint, nn1int / (nn1int + nn2int), rand); } // Slow, but safe: return F^{-1}(U) where F(.) = phyper(.) and U ~ U[0,1] - return QHyper.qhyper(rand.unifRand(), nn1in, nn2in, kkin, false, false); + return QHyper.qhyper(rand.unifRand(), nn1int, nn2int, kkint, false, false); } - nn1 = (int) nn1in; - nn2 = (int) nn2in; - kk = (int) kkin; + int nn1 = (int) nn1int; + int nn2 = (int) nn2int; + int kk = (int) kkint; /* if new parameter values, initialize */ + boolean setup1; + boolean setup2; if (nn1 != n1s || nn2 != n2s) { setup1 = true; setup2 = true; @@ -352,11 +349,11 @@ public final class RHyper extends RandFunction3_Double { if ((double) nn1 > (double) nn2) { ix1 = (double) kk - (double) nn2 + ix1; } else { - ix1 = (double) nn1 - ix1; + ix1 = nn1 - ix1; } } else { if ((double) nn1 > (double) nn2) { - ix1 = (double) kk - ix1; + ix1 = kk - ix1; } } return ix1; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java index 7b0d2a4c0dc0e158da8cfad77148cfff9c3028fe..02c61643311c94b45c6edeba1b1555115af402b4 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMath.java @@ -66,14 +66,14 @@ public class RMath { return mlError(); } - x = fmod(x, 1.); // tan(pi(x + k)) == tan(pi x) for all integer k + double x2 = fmod(x, 1.); // tan(pi(x + k)) == tan(pi x) for all integer k // map (-1,1) --> (-1/2, 1/2] : - if (x <= -0.5) { - x++; - } else if (x > 0.5) { - x--; + if (x2 <= -0.5) { + x2++; + } else if (x2 > 0.5) { + x2--; } - return (x == 0.) ? 0. : ((x == 0.5) ? Double.NaN : Math.tan(MathConstants.M_PI * x)); + return (x2 == 0.) ? 0. : ((x2 == 0.5) ? Double.NaN : Math.tan(MathConstants.M_PI * x2)); } // diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMultinom.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMultinom.java index 079a0ac5aaa636b00b4fffcc9f0bd6f60947766f..f6ec7325bbd3dff6af4f600aa1afdfea39ea27d8 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMultinom.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RMultinom.java @@ -13,10 +13,10 @@ package com.oracle.truffle.r.library.stats; import static com.oracle.truffle.r.nodes.builtin.CastBuilder.Predef.notIntNA; +import static com.oracle.truffle.r.runtime.RError.SHOW_CALLER; import static com.oracle.truffle.r.runtime.RError.Message.NA_IN_PROB_VECTOR; import static com.oracle.truffle.r.runtime.RError.Message.NEGATIVE_PROBABILITY; import static com.oracle.truffle.r.runtime.RError.Message.NO_POSITIVE_PROBABILITIES; -import static com.oracle.truffle.r.runtime.RError.SHOW_CALLER; import java.math.BigDecimal; import java.math.RoundingMode; @@ -115,9 +115,7 @@ public abstract class RMultinom extends RExternalBuiltinNode.Arg3 { * prob[j]) , sum_j rN[j] == n, sum_j prob[j] == 1. */ @TruffleBoundary - private boolean rmultinom(int n, double[] prob, int maxK, int[] rN, int rnStartIdx, RandomNumberProvider rand) { - int k; - double pp; + private boolean rmultinom(int nIn, double[] prob, int maxK, int[] rN, int rnStartIdx, RandomNumberProvider rand) { BigDecimal pTot = BigDecimal.ZERO; /* * This calculation is sensitive to exact values, so we try to ensure that the calculations @@ -125,6 +123,7 @@ public abstract class RMultinom extends RExternalBuiltinNode.Arg3 { * result. */ + int n = nIn; if (RRuntime.isNA(maxK) || maxK < 1 || RRuntime.isNA(n) || n < 0) { if (rN.length > rnStartIdx) { rN[rnStartIdx] = RRuntime.INT_NA; @@ -136,8 +135,8 @@ public abstract class RMultinom extends RExternalBuiltinNode.Arg3 { * Note: prob[K] is only used here for checking sum_k prob[k] = 1 ; Could make loop one * shorter and drop that check ! */ - for (k = 0; k < maxK; k++) { - pp = prob[k]; + for (int k = 0; k < maxK; k++) { + double pp = prob[k]; if (!Double.isFinite(pp) || pp < 0. || pp > 1.) { rN[rnStartIdx + k] = RRuntime.INT_NA; return false; @@ -158,12 +157,12 @@ public abstract class RMultinom extends RExternalBuiltinNode.Arg3 { } /* Generate the first K-1 obs. via binomials */ - for (k = 0; k < maxK - 1; k++) { /* (p_tot, n) are for "remaining binomial" */ + for (int k = 0; k < maxK - 1; k++) { /* (p_tot, n) are for "remaining binomial" */ BigDecimal probK = new BigDecimal(prob[k]); if (probK.compareTo(BigDecimal.ZERO) != 0) { - pp = probK.divide(pTot, RoundingMode.HALF_UP).doubleValue(); + double pp = probK.divide(pTot, RoundingMode.HALF_UP).doubleValue(); // System.out.printf("[%d] %.17f\n", k + 1, pp); - rN[rnStartIdx + k] = ((pp < 1.) ? (int) rbinom.execute((double) n, pp, rand) : + rN[rnStartIdx + k] = ((pp < 1.) ? (int) rbinom.execute(n, pp, rand) : /* >= 1; > 1 happens because of rounding */ n); n -= rN[rnStartIdx + k]; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNbinomMu.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNbinomMu.java index 03118361e216015b5a02094b8c0cb0255036da12..cfbb7798c6594f952c5b6f7ce9a5935a1c6cb800 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNbinomMu.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RNbinomMu.java @@ -18,13 +18,11 @@ public final class RNbinomMu extends RandFunction2_Double { private final RGamma rgamma = new RGamma(); @Override - public double execute(double size, double mu, RandomNumberProvider rand) { - if (!Double.isFinite(mu) || Double.isNaN(size) || size <= 0 || mu < 0) { + public double execute(double initialSize, double mu, RandomNumberProvider rand) { + if (!Double.isFinite(mu) || Double.isNaN(initialSize) || initialSize <= 0 || mu < 0) { return RMath.mlError(); } - if (!Double.isFinite(size)) { - size = Double.MAX_VALUE / 2.; - } + double size = Double.isFinite(initialSize) ? initialSize : Double.MAX_VALUE / 2.; return (mu == 0) ? 0 : RPois.rpois(rgamma.execute(size, mu / size, rand), rand); } } diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RPois.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RPois.java index 397cd4f7a7b437a580af80d175f0318d18432b15..420a81dc44c6cbcef837c9bec66befe439a58145 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RPois.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RPois.java @@ -131,7 +131,7 @@ public final class RPois extends RandFunction1_Double { if (l != 0) { for (k = (u <= 0.458) ? 1 : Math.min(l, m); k <= l; k++) { if (u <= pp[k]) { - return (double) k; + return k; } } if (l == 35) { /* u > pp[35] */ @@ -149,7 +149,7 @@ public final class RPois extends RandFunction1_Double { pp[k] = q; if (u <= q) { l = k; - return (double) k; + return k; } } l = 35; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java index 2bdaeeef565e8154753a5c4b561d1e56db0d6bd1..19717a9b865e7c364a7b4c24cc8de51b0e1824a1 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/RandGenerationFunctions.java @@ -188,6 +188,7 @@ public final class RandGenerationFunctions { return result; } + @SuppressWarnings("unused") Object evaluate(int length, RAbstractDoubleVector a, RAbstractDoubleVector b, RAbstractDoubleVector c, RandGenerationNodeData nodeData, RandomNumberProvider randProvider) { // DSL generates code for this class too, with abstract method it would not compile throw RInternalError.shouldNotReachHere("must be overridden"); diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Signrank.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Signrank.java index a6747c5660a3a8f134c1f57246f02008e5f560ce..9a976a351a50fa1ce7b5e8c1a92374859afa329a 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Signrank.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Signrank.java @@ -23,21 +23,17 @@ public final class Signrank { public static final class RSignrank extends RandFunction1_Double { @Override - public double execute(double n, RandomNumberProvider rand) { - int i; - int k; - double r; - - if (Double.isNaN(n)) { - return n; + public double execute(double nIn, RandomNumberProvider rand) { + if (Double.isNaN(nIn)) { + return nIn; } - if (Double.isInfinite(n)) { + if (Double.isInfinite(nIn)) { // In GnuR these "results" seem to be generated due to the behaviour of R_forceint, // and the "(int) n" cast, which ends up casting +/-infinity to integer... - return n < 0 ? RMath.mlError() : 0; + return nIn < 0 ? RMath.mlError() : 0; } - n = forceint(n); + double n = forceint(nIn); if (n < 0) { return RMath.mlError(); } @@ -45,9 +41,9 @@ public final class Signrank { if (n == 0) { return 0; } - r = 0.0; - k = (int) n; - for (i = 0; i < k; i++) { + double r = 0.0; + int k = (int) n; + for (int i = 0; i < k; i++) { r += (i + 1) * Math.floor(rand.unifRand() + 0.5); } return r; diff --git a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Wilcox.java b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Wilcox.java index acf8b5555f4b196401ecdf46965206a71ca1ff90..85ba6659908e2ab0748b1ff367a249906258f31a 100644 --- a/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Wilcox.java +++ b/com.oracle.truffle.r.library/src/com/oracle/truffle/r/library/stats/Wilcox.java @@ -25,24 +25,24 @@ public final class Wilcox { public static final class RWilcox extends RandFunction2_Double { @Override - public double execute(double m, double n, RandomNumberProvider rand) { + public double execute(double mIn, double nIn, RandomNumberProvider rand) { int i; int j; int k; double r; /* NaNs propagated correctly */ - if (Double.isNaN(m) || Double.isNaN(n)) { - return (m + n); + if (Double.isNaN(mIn) || Double.isNaN(nIn)) { + return mIn + nIn; } - if (!Double.isFinite(m) || !Double.isFinite(n)) { + if (!Double.isFinite(mIn) || !Double.isFinite(nIn)) { // GnuR does not check this and tries to allocate the memory, we do check this, but // fail with the same error message for compatibility reasons. throw RError.error(RError.SHOW_CALLER, CALLOC_COULD_NOT_ALLOCATE_INF); } - m = Math.round(m); - n = Math.round(n); + double m = Math.round(mIn); + double n = Math.round(nIn); if ((m < 0) || (n < 0)) { // TODO: for some reason the macro in GNUR here returns NA instead of NaN... // return StatsUtil.mlError(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Attr.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Attr.java index c961850f0f7c60e77cd608edd7cac570faa7c58c..662b6e581b8769273d8abfd512feb67e5ccdd71d 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Attr.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Attr.java @@ -49,7 +49,6 @@ import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.Utils; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RAttributable; -import com.oracle.truffle.r.runtime.data.RAttributeProfiles; import com.oracle.truffle.r.runtime.data.RAttributesLayout; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RInteger; diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java index 99f09dcce3d563e95b0a3292e91bb7de0395d97e..1c53a2a22f3c49d902566448a343248d18502451 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Combine.java @@ -68,7 +68,6 @@ import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.builtins.RBuiltin; import com.oracle.truffle.r.runtime.data.RArgsValuesAndNames; -import com.oracle.truffle.r.runtime.data.RAttributeProfiles; import com.oracle.truffle.r.runtime.data.RAttributesLayout; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RLanguage; @@ -458,7 +457,6 @@ public abstract class Combine extends RBuiltinNode { @NodeChild protected abstract static class CombineInputCast extends RNode { - private final RAttributeProfiles attrProfiles = RAttributeProfiles.create(); @Child private GetDimNamesAttributeNode getDimNamesNode = GetDimNamesAttributeNode.create(); @Child private GetNamesAttributeNode getNamesNode = GetNamesAttributeNode.create(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Drop.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Drop.java index 7104921f0dc2c92786597d31e9c707f6fadf5f1c..bb060fb21b0ac5b918907432c43338dc83c381b9 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Drop.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Drop.java @@ -36,7 +36,6 @@ import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.SetDimNa import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.SetNamesAttributeNode; import com.oracle.truffle.r.nodes.builtin.RBuiltinNode; import com.oracle.truffle.r.runtime.builtins.RBuiltin; -import com.oracle.truffle.r.runtime.data.RAttributeProfiles; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RList; import com.oracle.truffle.r.runtime.data.RStringVector; @@ -47,7 +46,6 @@ import com.oracle.truffle.r.runtime.data.model.RAbstractVector; public abstract class Drop extends RBuiltinNode { private final ConditionProfile nullDimensions = ConditionProfile.createBinaryProfile(); - private final RAttributeProfiles dimNamesAttrProfile = RAttributeProfiles.create(); private final ConditionProfile resultIsVector = ConditionProfile.createBinaryProfile(); private final ConditionProfile resultIsScalarProfile = ConditionProfile.createBinaryProfile(); private final ConditionProfile noDimNamesProfile = ConditionProfile.createBinaryProfile(); diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java index 2f1abb16b37e693639d363d1bbbc79e6e41a5e40..99d18142da4efbbeff608c53fbf2b8cabc9b265c 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/Sprintf.java @@ -52,7 +52,7 @@ public abstract class Sprintf extends RBuiltinNode { @Child private Sprintf sprintfRecursive; @Specialization - protected RStringVector sprintf(RAbstractStringVector fmt, @SuppressWarnings("unused") RNull x) { + protected RStringVector sprintf(@SuppressWarnings("unused") RAbstractStringVector fmt, @SuppressWarnings("unused") RNull x) { return RDataFactory.createEmptyStringVector(); } diff --git a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java index 094f7fb3b8b052cc251da25e495c326f181a1cf3..1133d63fa879b46b5bba99865a40c045c87690ab 100644 --- a/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java +++ b/com.oracle.truffle.r.nodes.builtin/src/com/oracle/truffle/r/nodes/builtin/base/UpdateClass.java @@ -18,7 +18,6 @@ import com.oracle.truffle.api.CompilerDirectives; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Specialization; -import com.oracle.truffle.api.profiles.BranchProfile; import com.oracle.truffle.r.nodes.attributes.SpecialAttributesFunctions.SetClassAttributeNode; import com.oracle.truffle.r.nodes.attributes.TypeFromModeNode; import com.oracle.truffle.r.nodes.binary.CastTypeNode; diff --git a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubscriptNode.java b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubscriptNode.java index 6aa4578656348d2c47e4ea9f19d82418716a06af..bc43a33bc3f77f8bb4bdec0c85238637caa52577 100644 --- a/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubscriptNode.java +++ b/com.oracle.truffle.r.nodes/src/com/oracle/truffle/r/nodes/access/vector/PositionCheckSubscriptNode.java @@ -31,7 +31,6 @@ import com.oracle.truffle.r.runtime.RError; import com.oracle.truffle.r.runtime.RError.Message; import com.oracle.truffle.r.runtime.RRuntime; import com.oracle.truffle.r.runtime.RType; -import com.oracle.truffle.r.runtime.data.RAttributeProfiles; import com.oracle.truffle.r.runtime.data.RDataFactory; import com.oracle.truffle.r.runtime.data.RInteger; import com.oracle.truffle.r.runtime.data.RMissing; @@ -48,8 +47,6 @@ abstract class PositionCheckSubscriptNode extends PositionCheckNode { private final boolean recursive; - private final RAttributeProfiles attributeProfile = RAttributeProfiles.create(); - PositionCheckSubscriptNode(ElementAccessMode mode, RType containerType, Object positionValue, int dimensionIndex, int numDimensions, boolean exact, boolean assignment, boolean recursive) { super(mode, containerType, positionValue, dimensionIndex, numDimensions, exact, assignment); this.recursive = recursive; diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_array.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_array.java index f3d72b9a76b32238317d54dcd86a78a788e09ede..c59d7c4c04748914777a44ed2f9dac95b652b373 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_array.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_array.java @@ -70,8 +70,7 @@ public class TestBuiltin_array extends TestBase { @Test public void testarray11() { - assertEval(Ignored.Unknown, - "argv <- list(list(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL), 8L, list(c('1', '2', '3', '4', '5', '6', '7', '8'))); .Internal(array(argv[[1]], argv[[2]], argv[[3]]))"); + assertEval("argv <- list(list(NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL), 8L, list(c('1', '2', '3', '4', '5', '6', '7', '8'))); .Internal(array(argv[[1]], argv[[2]], argv[[3]]))"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_identical.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_identical.java index d2fdc75685a637c5ee7d4bb80484fef5a580ecc2..83259357950962b4bcd8cebdc2140aa8955902e2 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_identical.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_identical.java @@ -154,7 +154,7 @@ public class TestBuiltin_identical extends TestBase { @Test public void testidentical28() { - assertEval(Ignored.Unknown, + assertEval(Ignored.Unstable, "argv <- list(structure(list(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), fac = structure(c(1L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L, 2L), .Label = c('A', 'B', 'C'), class = 'factor')), .Names = c('x', 'y', 'fac'), row.names = c(NA, -10L), class = 'data.frame'), structure(list(x = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1), y = c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10), fac = structure(c(1L, 3L, 2L, 3L, 3L, 1L, 2L, 3L, 2L, 2L), .Label = c('A', 'B', 'C'), class = 'factor')), .Names = c('x', 'y', 'fac'), row.names = c(NA, 10L), class = 'data.frame'), TRUE, TRUE, TRUE, TRUE, FALSE); .Internal(identical(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]], argv[[6]], argv[[7]]))"); } diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java index 3a060acb8ddaf346b119d28ca8af4104351bf311..f6d29dc8ce187711d5ca431f2ccac8c2555620b8 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_strsplit.java @@ -29,8 +29,7 @@ public class TestBuiltin_strsplit extends TestBase { @Test public void teststrsplit3() { - assertEval(Ignored.Unknown, - "argv <- list(' \\036 isSeekable() now returns FALSE on connections which have non-default encoding. Although documented to record if ‘in principle’ the connection supports seeking, it seems safer to report FALSE when it may not work.', '[ \\t\\n]', FALSE, TRUE, FALSE); .Internal(strsplit(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]]))"); + assertEval("argv <- list(' \\036 isSeekable() now returns FALSE on connections which have non-default encoding. Although documented to record if ‘in principle’ the connection supports seeking, it seems safer to report FALSE when it may not work.', '[ \\t\\n]', FALSE, TRUE, FALSE); .Internal(strsplit(argv[[1]], argv[[2]], argv[[3]], argv[[4]], argv[[5]]))"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unclass.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unclass.java index df73382e61060130120eaf3ab39e07285da7f5eb..7dd8dbaa17e66d79719e805bcd25e3842af19f36 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unclass.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/builtins/TestBuiltin_unclass.java @@ -150,7 +150,7 @@ public class TestBuiltin_unclass extends TestBase { @Test public void testunclass26() { - assertEval(Ignored.Unknown, "argv <- list(structure(list(a = 1), .Dim = 1L, .Dimnames = list('a')));unclass(argv[[1]]);"); + assertEval("argv <- list(structure(list(a = 1), .Dim = 1L, .Dimnames = list('a')));unclass(argv[[1]]);"); } @Test diff --git a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_rnbinom.java b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_rnbinom.java index c8385786a2adca7b6873fd5f998a489dbdc135a4..1da764331667df2230c83d2f9385eb8354099e25 100644 --- a/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_rnbinom.java +++ b/com.oracle.truffle.r.test/src/com/oracle/truffle/r/test/library/stats/TestExternal_rnbinom.java @@ -32,6 +32,6 @@ public class TestExternal_rnbinom extends TestBase { public void testRbinomWithMu() { assertEval("set.seed(42); rnbinom(5, 1, mu=2)"); // TODO: maybe problem with state variables, see RNbinomMu - assertEval(Ignored.Unimplemented, "set.seed(42); rnbinom(100, c(-1, 0, 1, 0.8, 10, NA, NaN, 1/0, -1/0), mu=c(-1, 0, 1, 0.8, 3, 10, NA, NaN, 1/0, -1/0))"); + assertEval(Ignored.Unstable, "set.seed(42); rnbinom(100, c(-1, 0, 1, 0.8, 10, NA, NaN, 1/0, -1/0), mu=c(-1, 0, 1, 0.8, 3, 10, NA, NaN, 1/0, -1/0))"); } }