Skip to content

Commit 117f60c

Browse files
committed
version getter is now more robust to armadillo and compilers
1 parent 023e97e commit 117f60c

File tree

2 files changed

+26
-20
lines changed

2 files changed

+26
-20
lines changed

ChangeLog

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2020-10-26 Dirk Eddelbuettel <[email protected]>
2+
3+
* src/RcppArmadillo.cpp: Rewrite version number accessors to be more
4+
rebust of upstream and compiler settings
5+
16
2020-10-24 Condrad Sanderson <[email protected]>
27

38
* inst/include/RcppArmadilloForward.h: Switch to quoted #include

src/RcppArmadillo.cpp

+21-20
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,25 @@
3232
// [[Rcpp::export]]
3333
Rcpp::IntegerVector armadillo_version(bool single) {
3434

35+
// These are declared as constexpr in Armadillo which actually does not define them
36+
// They are also defined as macros in arma_version.hpp so we just use that
37+
const unsigned int major = ARMA_VERSION_MAJOR;
38+
const unsigned int minor = ARMA_VERSION_MINOR;
39+
const unsigned int patch = ARMA_VERSION_PATCH;
40+
3541
if (single) {
36-
return Rcpp::wrap(10000*arma::arma_version::major +
37-
100*arma::arma_version::minor +
38-
arma::arma_version::patch) ;
42+
return Rcpp::wrap(10000 * major + 100 * minor + patch) ;
43+
} else {
44+
return Rcpp::IntegerVector::create(Rcpp::Named("major") = major,
45+
Rcpp::Named("minor") = minor,
46+
Rcpp::Named("patch") = patch);
3947
}
40-
41-
Rcpp::IntegerVector version =
42-
Rcpp::IntegerVector::create(Rcpp::Named("major") = arma::arma_version::major,
43-
Rcpp::Named("minor") = arma::arma_version::minor,
44-
Rcpp::Named("patch") = arma::arma_version::patch);
45-
46-
return version ;
4748
}
4849

4950
// Per request of Gábor Csárdi in https://github.com/RcppCore/RcppArmadillo/issues/11
5051
//
5152
//' Set the Armadillo Random Number Generator to a random value
52-
//'
53+
//'
5354
//' @details
5455
//' Depending on whether RcppArmadillo was compiled for the C++98 standard
5556
//' (currently the default) or for C++11 (optional), two different RNGs may be used.
@@ -60,32 +61,32 @@ Rcpp::IntegerVector armadillo_version(bool single) {
6061
//' @return The function is invoked for its side effect and has no return value.
6162
//' @note This has been found to not work as espected in \pkg{RStudio}
6263
//' as its code also uses the system RNG library. You may have to either
63-
//' not run within \pkg{RStudio} or change your code to use a different RNG such
64+
//' not run within \pkg{RStudio} or change your code to use a different RNG such
6465
//' as the one from R.
65-
//' @seealso The R documentation on its RNGs all of which are accessible via \pkg{Rcpp}.
66+
//' @seealso The R documentation on its RNGs all of which are accessible via \pkg{Rcpp}.
6667
// [[Rcpp::export]]
6768
void armadillo_set_seed_random() {
6869
arma::arma_rng::set_seed_random(); // set the seed to a random value
69-
}
70+
}
7071

7172
//' Set the Armadillo Random Number Generator to the given value
72-
//'
73+
//'
7374
//' @param val The seed used to initialize Armadillo's random number generator.
74-
//' @details
75+
//' @details
7576
//' Depending on whether RcppArmadillo was compiled for the C++98 standard
7677
//' (currently the default) or for C++11 (optional), two different RNGs may be used.
7778
//' This function resets either. For C++98, the R programming language's RNG is used.
7879
//' For C++11, the RNG included in the \code{<random>} library is used only when
7980
//' \code{#define ARMA_USE_CXX11_RNG} is placed before \code{#include <RcppArmadillo.h>}.
8081
//' Otherwise, the R programming language's RNG will be used.
81-
//' @return The function is invoked for its side effect and has no return value.
82+
//' @return The function is invoked for its side effect and has no return value.
8283
//' @note This has been found to not work as espected in \pkg{RStudio}
8384
//' as its code also uses the system RNG library. You may have to either
84-
//' not run within \pkg{RStudio} or change your code to use a different RNG such
85+
//' not run within \pkg{RStudio} or change your code to use a different RNG such
8586
//' as the one from R.
86-
//' @seealso The R documentation on its RNGs all of which are accessible via \pkg{Rcpp}.
87+
//' @seealso The R documentation on its RNGs all of which are accessible via \pkg{Rcpp}.
8788
// [[Rcpp::export]]
8889
void armadillo_set_seed(unsigned int val) {
8990
//Rcpp::Rcout << "Setting value " << val << std::endl;
9091
arma::arma_rng::set_seed(val); // set the seed to given value
91-
}
92+
}

0 commit comments

Comments
 (0)