Skip to content

Commit

Permalink
Drop C++11 specification in Makevars (#42)
Browse files Browse the repository at this point in the history
* Drop C++11 specification in Makevars
* Drop C++11 specification in DESCRIPTION
* NEWS
* std::random_shuffle > fisher-yates
  • Loading branch information
jwijffels authored Feb 22, 2024
1 parent 747fec4 commit ff56ab0
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
1 change: 0 additions & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,3 @@ Imports: Rcpp (>= 0.11.5), utils, graphics, stats
Suggests: udpipe, data.table
LinkingTo: Rcpp, BH
RoxygenNote: 7.1.2
SystemRequirements: C++11
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Docs of starspace and starspace_dictionary: fix use of {} in itemize items
- Remove compliance.cpp and compliance.h and move the abort/exit statements directly in the cpp files
- Drop C++11 specification in Makevars
- hereby replacing use of std::random_shuffle with the Fisher-Yates Shuffle Algorithm as indicated at https://gallery.rcpp.org/articles/stl-random-shuffle/ - as data is reshuffled, model training will give different results compared to previous versions due to different randomisations of the training data

## CHANGES IN ruimtehol VERSION 0.3.1

Expand Down
1 change: 0 additions & 1 deletion src/Makevars
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
CXX_STD = CXX11
PKG_LIBS = -pthread
PKG_CPPFLAGS = -pthread -DSTRICT_R_HEADERS -DBOOST_NO_AUTO_PTR -I./Starspace/src

Expand Down
12 changes: 11 additions & 1 deletion src/Starspace/src/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,17 @@ Real EmbedModel::train(shared_ptr<InternDataHandler> data,
int i = 0;
for (auto& idx: indices) idx = i++;
}
std::random_shuffle(indices.begin(), indices.end(), randWrapper);
// std::random_shuffle(indices.begin(), indices.end(), randWrapper);
// Rcpp::IntegerVector indices_r = Rcpp::sample(numSamples, numSamples, false, R_NilValue, true) - 1;
// for (auto ii = 0; ii < numSamples; ii++) {
// indices[ii] = indices_r[ii];
// }
// Fisher-Yates Shuffle Algorithm - https://gallery.rcpp.org/articles/stl-random-shuffle/
int j;
for (int i = 0; i < numSamples - 1; i++) {
j = i + randWrapper(numSamples - i);
std::swap(indices[i], indices[j]);
}

// Compute word negatives
if (args_->trainMode == 5 || args_->trainWord) {
Expand Down

0 comments on commit ff56ab0

Please sign in to comment.