88using namespace arma ;
99namespace fs = std::filesystem;
1010
11+ uvec shuffle_rcpp (const uvec& values_in) {
12+ ivec inds = Rcpp::sample (values_in.size (), values_in.size (), false ) - 1 ;
13+ return values_in (conv_to<uvec>::from (inds));
14+ }
15+
1116LatentRankingProposal sample_latent_rankings (
1217 const std::unique_ptr<Data>& data, unsigned int t, const Prior& prior,
1318 std::string latent_rank_proposal,
@@ -45,7 +50,7 @@ LatentRankingProposal sample_latent_rankings(
4550 uvec tmp = ndit->second .observation ;
4651
4752 if (latent_rank_proposal == " uniform" ) {
48- tmp (ndit->second .available_items ) = shuffle (ndit->second .available_rankings );
53+ tmp (ndit->second .available_items ) = shuffle_rcpp (ndit->second .available_rankings );
4954 proposal.proposal = join_horiz (proposal.proposal , tmp);
5055 proposal.log_probability = join_vert (
5156 proposal.log_probability , vec{-lgamma (ndit->second .available_rankings .size () + 1.0 )});
@@ -55,7 +60,7 @@ LatentRankingProposal sample_latent_rankings(
5560 }
5661 double logprob{0 };
5762
58- uvec available_items_shuffled = shuffle (ndit->second .available_items );
63+ uvec available_items_shuffled = shuffle_rcpp (ndit->second .available_items );
5964 uvec available_rankings = ndit->second .available_rankings ;
6065
6166 while (available_items_shuffled.size () > 1 ) {
@@ -135,7 +140,7 @@ LatentRankingProposal sample_latent_rankings(
135140 Rcpp::stop (" No files." );
136141 }
137142
138- int random_index = randi ( distr_param ( 0 , file_count - 1 )) ;
143+ int random_index = Rcpp::sample (file_count, 1 , false )[ 0 ] - 1 ;
139144
140145 fs::path random_file_path;
141146 size_t current_index = 0 ;
0 commit comments