Comments (2)
Ok, a few things:
- Try formatting your posts. It makes it easier for other people to read your posts, and hence more likely they will help you. I formatted it for you.
- You were using the older inline approach. Rcpp Attributes is nicer. A new version is below.
- RcppArmadillo is used from R. R has very good and extremely well-tested statistical algorithms. I would use R's RNG. In fact, that is what we do here as I recall...
- For me it all works.
New file:
#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
// [[Rcpp::export]]
arma::mat foo(int n) {
arma::mat f = arma::join_rows(arma::randu(n),
arma::randn(n));
return f;
}
/*** R
set.seed(123)
foo(5)
*/
which we simple feed to sourceCpp()
which will also run the code:
R> set.seed(123)
R> foo(5)
[,1] [,2]
[1,] 0.2875775 -0.61079930
[2,] 0.7883051 0.03777546
[3,] 0.4089769 0.95877582
[4,] 0.8830174 0.12566834
[5,] 0.9404673 -0.05538708
R>
Best of all, the seed is linked to R as we (as I recall) use R's RNG by default. Calling again gives different numbers; resetting the seed gives (as expected) what we just got:
R> foo(5)
[,1] [,2]
[1,] 0.4533342 -0.1193901
[2,] 0.6775706 0.3153385
[3,] 0.5726334 0.6708789
[4,] 0.1029247 0.3320531
[5,] 0.8998250 0.9669271
R> set.seed(123)
R> foo(5)
[,1] [,2]
[1,] 0.2875775 -0.61079930
[2,] 0.7883051 0.03777546
[3,] 0.4089769 0.95877582
[4,] 0.8830174 0.12566834
[5,] 0.9404673 -0.05538708
R>
Strictly no issue here. I suspect that the cause may have been your use of cxxfunction()
AND the random generator WITHOUT setting RNGState (see Writing R Extensions). The Rcpp Attributes approach does that automatically for you, and I no longer recall if we did that for inline too.
from rcpparmadillo.
Superb! Thanks for the detailed correction and broad lesson. This now works on RcppArmadillo 0.6.5.
from rcpparmadillo.
Related Issues (20)
- Problems in installing RcppArmadillo on macOS Monterey HOT 3
- Missing distr_param argument in randu HOT 8
- no matching function for call to βarma::Cube<double>::insert_slices(arma::uword&, arma::mat&) HOT 2
- Deprecating old initialization code in packages using RcppArmadillo HOT 17
- Is `ARMA_64BIT_WORD` supported in RcppArmadillo? HOT 4
- NaN output from arma::uvec compared to arma::vec HOT 4
- Planning to potentially (re)move some legacy internal header files
- Deprecating old stderr stream setting code in packages using RcppArmadillo HOT 12
- Fails to compile vs HOT 3
- Question about SIMD Optimization HOT 3
- package compilation failure HOT 20
- Two failures in test_cube.R on PowerPC HOT 33
- Armadillo 12.0.0 regressions HOT 2
- `RCPP_ARMADILLO_RETURN_ANYVEC_AS_VECTOR` in an R package? HOT 2
- using namespace arma; HOT 1
- Issue on call by reference with a NA matrix HOT 1
- Update indMatrix->arma::SpMat and pMatrix->arma::SpMat for Matrix 1.5-5 HOT 2
- install issue HOT 3
- [DOCS] - Review DESCRIPTION's Date HOT 2
- Failed to install RcppArmadillo on Linux Hyper Cluster HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rcpparmadillo.