Skip to content

Commit

Permalink
Fix C tfidf hpp warning (#85)
Browse files Browse the repository at this point in the history
Co-authored-by: rofuyu <hsiangfu@amazon.com>
  • Loading branch information
weiliw-amz and rofuyu authored Oct 27, 2021
1 parent 6f9b000 commit 034d7d0
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pecos/core/utils/tfidf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,9 @@ class BaseVectorizer {
throw std::runtime_error("Unable to load tfidf model file to " + model_filename);
} else {
size_t total_features = 0;
fscanf(fp, "%ld", &total_features);
if (1 != fscanf(fp, "%ld", &total_features)) {
throw std::runtime_error("Invalid tfidf model file (total_features).");
}
feature_vocab.reserve(total_features);
idx_idf.reserve(total_features);

Expand All @@ -742,12 +744,16 @@ class BaseVectorizer {
int32_t idx = 0;
float32_t idf = 0.0;
uint64_t ngram_len = 0;
fscanf(fp, "%d%f%ld", &idx, &idf, &ngram_len);
if (3 != fscanf(fp, "%d%f%ld", &idx, &idf, &ngram_len)) {
throw std::runtime_error("Invalid tfidf model file (idx, idf, ngram_len).");
}
idx_idf[idx] = idf;
idx_vec_t ngram(ngram_len);
for(size_t tid = 0; tid < ngram_len; tid++) {
int32_t tok_idx;
fscanf(fp, "%d", &tok_idx);
if (1 != fscanf(fp, "%d", &tok_idx)) {
throw std::runtime_error("Invalid tfidf model file (tok_idx).");
}
ngram[tid] = tok_idx;
}
feature_vocab[ngram] = idx;
Expand Down

0 comments on commit 034d7d0

Please sign in to comment.