Skip to content
Snippets Groups Projects
Commit 460f837f authored by Florian Angerer's avatar Florian Angerer
Browse files

Fixing RNG tests.

parent 078b16d6
No related branches found
No related tags found
No related merge requests found
......@@ -109,13 +109,6 @@ public class RNGFunctions {
Casts.noCasts(FastRSetSeed.class);
}
@Specialization
@TruffleBoundary
protected RNull setSeed(int[] data) {
RContext.getInstance().stateRNG.currentSeeds = data;
return RNull.instance;
}
@Specialization
@TruffleBoundary
protected RNull setSeed(RAbstractIntVector data) {
......@@ -146,6 +139,7 @@ public class RNGFunctions {
int[] seedsArr = (int[]) seeds;
return RDataFactory.createIntVector(seedsArr, RDataFactory.INCOMPLETE_VECTOR);
}
assert seeds != null;
return seeds;
}
}
......
......@@ -104,7 +104,13 @@ public class RRNG {
private RandomNumberGenerator currentGenerator;
private final RandomNumberGenerator[] allGenerators;
private NormKind currentNormKind;
public Object currentSeeds;
/**
* Stores the current RNG seed. The type is Object because the user may assign an arbitrary
* value to variable {@value RRNG#RANDOM_SEED}. Allowed types are therefore any R value or
* an {@code int[]}.
*/
public Object currentSeeds = RMissing.instance;
private ContextStateImpl() {
this.currentNormKind = DEFAULT_NORM_KIND;
......@@ -325,13 +331,16 @@ public class RRNG {
int[] seedsArr = (int[]) seeds;
tmp = seedsArr.length == 0 ? RRuntime.INT_NA : seedsArr[0];
} else {
assert seeds != RMissing.instance;
assert seeds instanceof RTypedValue;
RError.warning(RError.NO_CALLER, RError.Message.SEED_TYPE, ((RTypedValue) seeds).getRType().getName());
// allow RMissing to indicate that ".Random.seed" has not been initialized yet
if (seeds != RMissing.instance) {
RError.warning(RError.NO_CALLER, RError.Message.SEED_TYPE, ((RTypedValue) seeds).getRType().getName());
}
handleInvalidSeed();
return;
}
if (tmp == RRuntime.INT_NA || tmp < 0 || tmp > 1000) {
assert seeds != RMissing.instance;
String type = seeds instanceof RTypedValue ? ((RTypedValue) seeds).getRType().getName() : "unknown";
RError.warning(RError.NO_CALLER, RError.Message.SEED_TYPE, type);
handleInvalidSeed();
......
......@@ -32,9 +32,9 @@ public class TestRRNG extends TestBase {
// changes generator to MarsagliaMulticarry and sets its 2 seeds
assertEval(".Random.seed <- c(401L, 1L, 2L); runif(3)");
// wrong values: not integer
assertEval(Output.IgnoreWarningContext, ".Random.seed <- c(401, 1, 2); invisible(runif(3))");
assertEval(Output.IgnoreWarningContext, Output.MayIgnoreWarningContext, ".Random.seed <- c(401, 1, 2); invisible(runif(3))");
// wrong values: wrong generator number
assertEval(Output.IgnoreWarningContext, ".Random.seed <- c(999, 1, 2); invisible(runif(3))");
assertEval(Output.IgnoreWarningContext, Output.MayIgnoreWarningContext, ".Random.seed <- c(999, 1, 2); invisible(runif(3))");
}
@Test
......
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