Skip to content

Commit

Permalink
Exclude PCG on MacOS PowerPC (#91)
Browse files Browse the repository at this point in the history
  • Loading branch information
rstub committed May 28, 2024
1 parent e55775f commit d02120a
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: dqrng
Type: Package
Title: Fast Pseudo Random Number Generators
Version: 0.4.0.1
Version: 0.4.0.2
Authors@R: c(
person("Ralf", "Stubner", email = "ralf.stubner@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0009-0009-1908-106X")),
person("daqana GmbH", role = "cph"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

* Fix an UBSAN error found by CRAN ([#90](https://github.com/daqana/dqrng/pull/90) fixing [#89](https://github.com/daqana/dqrng/issues/89))
* Fix a compilation error when the compiler does not provide a 128bit integer type ([#90](https://github.com/daqana/dqrng/pull/90) fixing [#88](https://github.com/daqana/dqrng/issues/88))
* Disable PCG64 on MacOS PowerPC ([#91](https://github.com/daqana/dqrng/pull/91) fixing [#88](https://github.com/daqana/dqrng/issues/88))

# dqrng 0.4.0

Expand Down
2 changes: 2 additions & 0 deletions inst/include/dqrng_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ inline void random_64bit_wrapper<::dqrng::xoshiro256starstar>::set_stream(result
gen.long_jump(stream);
}

#if !(defined(__APPLE__) && defined(__POWERPC__))
template<>
inline void random_64bit_wrapper<pcg64>::set_stream(result_type stream) {
// set the stream relative to the current stream, i.e. stream = 0 does not change the RNG
Expand All @@ -121,6 +122,7 @@ inline void random_64bit_wrapper<pcg64>::seed(result_type seed, result_type stre
gen.seed(seed, stream);
cache = false;
}
#endif

inline uint64_t get_seed_from_r() {
Rcpp::RNGScope rngScope;
Expand Down
5 changes: 3 additions & 2 deletions inst/include/xoshiro.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <mystdint.h>
#include <functional>
#include <algorithm>
#include <iostream>

namespace dqrng {
template<size_t N>
Expand Down Expand Up @@ -107,7 +108,7 @@ template<>
inline void xoshiro<2>::do_jump(std::array<result_type, 2> JUMP) {
uint64_t s0 = 0;
uint64_t s1 = 0;
for(unsigned int i = 0; i < sizeof JUMP / sizeof JUMP.begin(); i++)
for(int i = 0; i < 2; i++)
for(int b = 0; b < 64; b++) {
if (JUMP[i] & UINT64_C(1) << b) {
s0 ^= s[0];
Expand All @@ -126,7 +127,7 @@ inline void xoshiro<4>::do_jump(std::array<result_type, 4> JUMP) {
uint64_t s1 = 0;
uint64_t s2 = 0;
uint64_t s3 = 0;
for(unsigned int i = 0; i < sizeof JUMP / sizeof JUMP.begin(); i++)
for(int i = 0; i < 4; i++)
for(int b = 0; b < 64; b++) {
if (JUMP[i] & UINT64_C(1) << b) {
s0 ^= s[0];
Expand Down
2 changes: 2 additions & 0 deletions src/dqrng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,10 @@ void dqRNGkind(std::string kind, const std::string& normal_kind = "ignored") {
rng = dqrng::generator<dqrng::xoshiro256plus>(seed);
} else if (kind == "xoshiro256++") {
rng = dqrng::generator<dqrng::xoshiro256plusplus>(seed);
#if !(defined(__APPLE__) && defined(__POWERPC__))
} else if (kind == "pcg64") {
rng = dqrng::generator<pcg64>(seed);
#endif
} else if (kind == "threefry") {
rng = dqrng::generator<sitmo::threefry_20_64>(seed);
} else {
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/helper.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
powerpc_apple <- grepl("powerpc-apple-darwin", R.version$platform)

safe_expect_error <- function(..., msg) {
os.type <- Sys.info()["sysname"]
if (os.type == "Darwin") {
expect_error(...)
} else {
expect_error(..., msg)
}
}
9 changes: 0 additions & 9 deletions tests/testthat/test-convert.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
context("conversion")

safe_expect_error <- function(..., msg) {
os.type <- Sys.info()["sysname"]
if (os.type == "Darwin") {
expect_error(...)
} else {
expect_error(..., msg)
}
}

Rcpp::sourceCpp("cpp/convert.cpp") # Warnings about shifts can be ignored.

test_that("conversion to 16-bit integers works correctly", {
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-external-generator.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ test_that("cloned external Xoshiro256++ gives different result only when a diffe
})

test_that("cloned external PCG64 gives different result", {
skip_if(powerpc_apple)
dqrng::dqRNGkind("PCG64")
dqset.seed(use_seed)
expect_true(cloned_calls(stream = 0))
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-generators.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test_that("Default generator: setting same seed but different stream produces di
})

test_that("PCG64: setting seed produces identical uniformly distributed numbers", {
skip_if(powerpc_apple)
dqRNGkind("pcg64")
dqset.seed(seed)
u1 <- dqrunif(10)
Expand All @@ -49,6 +50,7 @@ test_that("PCG64: setting seed produces identical uniformly distributed numbers"
})

test_that("PCG64: setting seed and stream produces identical uniformly distributed numbers", {
skip_if(powerpc_apple)
dqRNGkind("pcg64")
dqset.seed(seed, 1)
u1 <- dqrunif(10)
Expand All @@ -58,6 +60,7 @@ test_that("PCG64: setting seed and stream produces identical uniformly distribut
})

test_that("PCG64: saving state produces identical uniformly distributed numbers", {
skip_if(powerpc_apple)
dqRNGkind("pcg64")
dqset.seed(seed, 1)
state <- dqrng_get_state()
Expand All @@ -68,6 +71,7 @@ test_that("PCG64: saving state produces identical uniformly distributed numbers"
})

test_that("PCG64: setting same seed but different stream produces different uniformly distributed numbers", {
skip_if(powerpc_apple)
dqRNGkind("pcg64")
dqset.seed(seed, 1)
u1 <- dqrunif(10)
Expand Down

0 comments on commit d02120a

Please sign in to comment.