Giter Site home page Giter Site logo

eddelbuettel / rcppziggurat Goto Github PK

View Code? Open in Web Editor NEW
12.0 3.0 4.0 1.28 MB

Rcpp bindings for different Ziggurat RNG implementations

License: Other

R 13.14% Shell 0.26% C++ 79.91% C 2.50% TeX 4.19%
ziggurat random-number-generators r-package cran rcpp

rcppziggurat's People

Contributors

blaza avatar eddelbuettel avatar jeroen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

rcppziggurat's Issues

Unable to load dynamic library

Hi Dirk,

I am using the package Rfast, which imports RcppZiggurat. I got the following error when running Rfast on a Linux cluster (Red Hat 6.10)

unable to load shared object '/home/users/sutd/R/x86_64-pc-linux-gnu-library/3.6/RcppZiggurat/libs/RcppZiggurat.so':
  libgsl.so.0: cannot open shared object file: No such file or directory

The packages are installed on my local directory. Edited: I've done some diagnostic and found that this only happens when the Rfast functions are being called in parallel, in a foreach() loop. When they are called directly it is OK.

Below are something I've tried but failed:

I know that libgsl.so is located in /usr/lib64/, so I've added the following line at the beginning of my R script

Sys.setenv(LD_LIBRARY_PATH=paste("/usr/lib64/", Sys.getenv("LD_LIBRARY_PATH"), sep = ":"))

I have also try to do dyn.load('/usr/lib64/libgsl.so') but I get the following error

 Error in dyn.load("/usr/lib64/libgsl.so") :
  unable to load shared object '/usr/lib64/libgsl.so':
  /usr/lib64/libgsl.so: undefined symbol: cblas_ctrmv

On Windows everything works fine.

Is this an issue or am I doing something wrong?

Thank you so much.

Setting a seed to value of getSeed() doesn't produce expected draws

This is similar to Issue #7 , but I don't think quite the same:

My goal is to make a MCMC sampler reproducible even if it is stopped in the middle and then re-started.

As an example, I tried drawing 4 normal values, but stopping after two, getting the current seed, re-applying it to zsetseed(), and then drawing two more values. But I get a different output than drawing all 4 at once. Here is an example:

I can set the Ziggurat seed like this:

> zsetseed(bitXor(123456789,3))
> zgetseed()
[1] 3

Draw 4 normal values:

> zrnorm(4)
[1] -0.07785444  1.20543968  0.53777089  1.44539251
> zgetseed()
[1] 1909268553

Try doing this in two steps:
1 draw 2 values
2 get current seed
3 reset zsetseed() to saved seed
4 draw 2 more values

> zsetseed(bitXor(123456789,3))
> zrnorm(2)
[1] -0.07785444  1.20543968
> zgetseed()
[1] 201886211
> zsetseed(bitXor(123456789,201886211))
> zrnorm(2)
[1] -0.7090703  2.3388461
> zgetseed()
[1] 1909268553

As you can see, even though the seed as returned by zgetseed() is the same at the end, the two draws after re-starting are different than when I drew all 4 at once. In baseR, I can save .Random.seed and then reset it and restart where I left off.

Is this possible to do? Or is there a work-around?
I can't find in the code why this doesn't work, but I'm not very experienced at reading C++.

Thanks.

Compilation failure

When a package is compiled in Windows 10 environment using R 4.0.3, the following error appears:

  • installing source package 'RcppZiggurat' ...
    ** package 'RcppZiggurat' successfully unpacked and MD5 sums checked
    ** using staged installation
    ** libs

*** arch - i386
"C:/rtools40/mingw32/bin/"g++ -std=gnu++11 -I"C:/PROGRA1/R/R-401.3/include" -DNDEBUG -I. -I../inst/include -I'C:/Users/Paul von Nachtigall/Documents/R/win-library/4.0/Rcpp/include' -I'C:/Users/Paul von Nachtigall/Documents/R/win-library/4.0/RcppGSL/include' -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c RcppExports.cpp -o RcppExports.o
In file included from C:/Users/Paul von Nachtigall/Documents/R/win-library/4.0/RcppGSL/include/RcppGSL.h:25,
from RcppExports.cpp:4:
C:/Users/Paul von Nachtigall/Documents/R/win-library/4.0/RcppGSL/include/RcppGSLForward.h:25:10: fatal error: gsl/gsl_vector.h: No such file or directory
#include <gsl/gsl_vector.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
make: *** [C:/PROGRA1/R/R-401.3/etc/i386/Makeconf:229: RcppExports.o] Error 1
ERROR: compilation failed for package 'RcppZiggurat'

  • removing 'C:/Users/Paul von Nachtigall/Documents/R/win-library/4.0/RcppZiggurat'
    Warning in install.packages :
    installation of package ‘RcppZiggurat’ had non-zero exit status

sourceCpp seems to reset random state

Hi,

I found that when using sourceCpp, the random state is reset. For example, let's take this function:

#include <Rcpp.h>
#include <Ziggurat.h>

using namespace Rcpp;
static Ziggurat::Ziggurat::Ziggurat zigg;

// [[Rcpp::export]]
double rand_number() {
  zigg.norm();
  return zigg.norm();
}

If i then source via sourceCpp and run the function i get the same random number each time. Only when i re-run the function without re-sourcing, i get different numbers.

How can i change this behavior so that also upon resourcing i get a new random number rather than the same? Is this intentional? If so, whats the reasoning and how can i change it?

Kind regards,
Luc

Use .Random.seed

I have a question/feature request: is there any reason why RcppZiggurat does not use R's seeding mechanism? Consistent control of seeds seems to be important from reproducibility point of view. If there is any problem with using the R's seeds, I'd be interested in learning about it and potentially helping with solving it (if it is already described in the docs I must have missed it).

R integration

The ZigguratRgenerator allows to use the uniform RNG from R in conjunction with the much faster Ziggurat method. Now it would be great if one could use the Ziggurat method directly via rnorm() by specifying RNGkind(normal.kind = "user"). The code to support this seems to be already present:

extern "C" double *user_norm_rand() {

However, it does not work on my system:

library(RcppZiggurat)
is.loaded("user_norm_rand")
#> [1] FALSE
RNGkind(normal.kind = "user")
#> Error in RNGkind(normal.kind = "user"): 'user_norm_rand' not in load table

When I look at RcppZiggurat.so using nm, objectdump or readelf, it lists user_norm_rand among the available symbols.

The example from help(Random.user) works without problems.

Error in dyn.load(file, DLLpath = DLLpath, ...) : unable to load shared object '/usr/lib/R/library/RcppGSL/libs/RcppGSL.so': libgsl.so.23: cannot open shared object file: No such file or directory

:~$ sudo su - -c "R -e \"devtools::install_github('eddelbuettel/rcppziggurat', INSTALL_opts = '--no-lock', force = TRUE)\""
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> devtools::install_github('eddelbuettel/rcppziggurat', INSTALL_opts = '--no-lock', force = TRUE)
Downloading GitHub repo eddelbuettel/rcppziggurat@HEAD

   checking for file/tmp/RtmpSnAWxn/remotes13b82702c7e0f/eddelbuettel-rcppzigchecking for file/tmp/RtmpSnAWxn/remotes13b82702c7e0f/eddelbuettel-rcppziggurat-4903377/DESCRIPTION’
─  preparingRcppZiggurat:checking DESCRIPTION meta-information ...cleaning srcrunningcleanup’
─  checking for LF line-endings in source and make files and shell scriptschecking for empty or unneeded directoriesbuildingRcppZiggurat_0.1.6.1.tar.gz* installing *source* packageRcppZiggurat...
staged installation is only possible with locking
** using non-staged installation
** libs
g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include -I'/usr/lib/R/library/Rcpp/include' -I'/usr/lib/R/library/RcppGSL/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-apO4Ea/r-base-4.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c RcppExports.cpp -o RcppExports.o

g++ -std=gnu++14 -I"/usr/share/R/include" -DNDEBUG -I. -I../inst/include -I'/usr/lib/R/library/Rcpp/include' -I'/usr/lib/R/library/RcppGSL/include'    -fpic  -g -O2 -fdebug-prefix-map=/build/r-base-apO4Ea/r-base-4.2.0=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2  -c ziggurat.cpp -o ziggurat.o
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/usr/lib/R/library/RcppGSL/libs/RcppGSL.so':
  libgsl.so.23: cannot open shared object file: No such file or directory
Calls: loadNamespace -> library.dynam -> dyn.load
Execution halted
g++ -std=gnu++14 -shared -L/usr/lib/R/lib -Wl,-Bsymbolic-functions -Wl,-z,relro -o RcppZiggurat.so RcppExports.o ziggurat.o -L/usr/lib/R/lib -lR
Error in dyn.load(file, DLLpath = DLLpath, ...) : 
  unable to load shared object '/usr/lib/R/library/RcppGSL/libs/RcppGSL.so':
  libgsl.so.23: cannot open shared object file: No such file or directory
Calls: loadNamespace -> library.dynam -> dyn.load
Execution halted
installing to /usr/lib/R/library/RcppZiggurat/libs
** R
** demo
** inst
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** installing vignettes
** testing if installed package can be loaded
Error: package or namespace load failed forRcppZigguratin dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/usr/lib/R/library/RcppZiggurat/libs/RcppZiggurat.so':
  /usr/lib/R/library/RcppZiggurat/libs/RcppZiggurat.so: undefined symbol: gsl_rng_default
Error: loading failed
Execution halted
ERROR: loading failed
* removing/usr/lib/R/library/RcppZigguratWarning message:
In i.p(...) :
  installation of package/tmp/RtmpkdsY8z/file135db57b9647f/RcppZiggurat_0.1.6.1.tar.gzhad non-zero exit status

libgsl.so.27 not found for GSL local installation

I had a bit of trouble installing RcppZiggurat as GSL is installed locally in my home directory, since I don't have root access. However, the installation eventually appeared to be successful by adding -I/path/to/gsl/include to the Makevars file. But when I try to load the library in R, I get the error:

Error: package or namespace load failed for ‘RcppZiggurat’ in dyn.load(file, DLLpath = DLLpath, ...):
 unable to load shared object '/home/bklempay/R/x86_64-redhat-linux-gnu-library/4.3/RcppZiggurat/libs/RcppZiggurat.so':
  libgsl.so.27: cannot open shared object file: No such file or directory

I have verified that libgsl.so.27 exists in /home/bklempay/tools/gsl/lib and I have added that path to LD_LIBRARY_PATH in R:

> Sys.getenv("LD_LIBRARY_PATH")
[1] "/home/bklempay/tools/gsl/lib:/usr/lib64/R/lib:/lib:/usr/lib/jvm/jre/lib/amd64/server:/usr/lib/jvm/jre/lib/amd64:/usr/lib/jvm/java/lib/amd64:/usr/lib/jvm/jre/lib/server:/usr/java/packages/lib/amd64:/lib:/usr/lib"

Not an issue but a request

Hi. Thank you for this. Would love to be able to use the Ziggurat-based exponential deviates as well please. They were in the original code base, I believe.
Thanks,
Jae

rcppziggurat installation fails on linux

trying to install rcppziggurat on a linux machine, I get following error:

: No such file or directory
g++: error: R: No such file or directory
g++: error: version: No such file or directory
g++: error: 3.5.1: No such file or directory
g++: error: (2018-07-02): No such file or directory
g++: error: Feather: No such file or directory
g++: error: Spray: No such file or directory
/usr/share/R/share/make/shlib.mk:6: recipe for target 'RcppZiggurat.so' failed
make: *** [RcppZiggurat.so] Error 1
ERROR: compilation failed for package ‘RcppZiggurat’

somehow and somewhere in the process, an information-string about the R-version seems to be passed on to the installation routine...

demos throw errors Windows

When running the demos on Windows machine I get:

Error in mclapply(generators, FUN = function(g, seed) { : 
  'mc.cores' > 1 is not supported on Windows

Among simple solutions, future::future_lapply has a parallel backend for lapply that works out-of-the-box on any platform.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.