Skip to content

Commit

Permalink
Skip set.seed() if NA_integer_ is given.
Browse files Browse the repository at this point in the history
This should address mlampros#52 but currently it does not work because
`NA_integer_` is implemented as the maximum negative value, and
a negative seed causes an error "negative length vectors are not allowed".
`base::set.seed()` accepts negative seeds without any problem,
which indicates ClusterR is doing something wrong with negative seeds.
  • Loading branch information
heavywatal committed Jun 19, 2024
1 parent d36fc17 commit f91395a
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 0 deletions.
1 change: 1 addition & 0 deletions inst/include/ClusterRHeader.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ namespace clustR {

void set_seed(int seed) {

if (Rcpp::all(Rcpp::is_na(Rcpp::IntegerVector(seed)))) return;
Rcpp::Environment base_env("package:base");
Rcpp::Function set_seed_r = base_env["set.seed"];
set_seed_r(seed);
Expand Down
1 change: 1 addition & 0 deletions inst/include/affinity_propagation.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class Affinity_Propagation {
//---------------------------------------------------------------------------------

void Affinity_Propagation::set_seed(int seed) {
if (Rcpp::all(Rcpp::is_na(Rcpp::IntegerVector(seed)))) return;
Rcpp::Environment base_env("package:base");
Rcpp::Function set_seed_r = base_env["set.seed"];
set_seed_r(seed);
Expand Down

0 comments on commit f91395a

Please sign in to comment.