Skip to content

Commit b622c44

Browse files
committed
Fix portability to windows by replacing std::itoa with std::generate
1 parent a72752d commit b622c44

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/fasttext.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,8 @@ std::vector<int32_t> FastText::selectEmbeddings(int32_t cutoff) const {
195195
Vector norms(input_->m_);
196196
input_->l2NormRow(norms);
197197
std::vector<int32_t> idx(input_->m_, 0);
198-
std::iota(idx.begin(), idx.end(), 0);
198+
int n = { 0 };
199+
std::generate(idx.begin(), idx.end(), [&n] {return ++n; });
199200
auto eosid = dict_->getId(Dictionary::EOS);
200201
std::sort(idx.begin(), idx.end(),
201202
[&norms, eosid] (size_t i1, size_t i2) {

src/productquantizer.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@ void ProductQuantizer::MStep(const real* x0, real* centroids,
112112

113113
void ProductQuantizer::kmeans(const real *x, real* c, int32_t n, int32_t d) {
114114
std::vector<int32_t> perm(n,0);
115-
std::iota(perm.begin(), perm.end(), 0);
115+
int gn = { 0 };
116+
std::generate(perm.begin(), perm.end(), [&gn] {return ++gn; });
116117
std::shuffle(perm.begin(), perm.end(), rng);
117118
for (auto i = 0; i < ksub_; i++) {
118119
memcpy (&c[i * d], x + perm[i] * d, d * sizeof(real));
@@ -131,7 +132,8 @@ void ProductQuantizer::train(int32_t n, const real * x) {
131132
exit(1);
132133
}
133134
std::vector<int32_t> perm(n, 0);
134-
std::iota(perm.begin(), perm.end(), 0);
135+
int gn = { 0 };
136+
std::generate(perm.begin(), perm.end(), [&gn] {return ++gn; });
135137
auto d = dsub_;
136138
auto np = std::min(n, max_points_);
137139
real* xslice = new real[np * dsub_];

0 commit comments

Comments
 (0)