summaryrefslogtreecommitdiff
path: root/utils/weights.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2012-05-27 15:34:44 -0400
committerChris Dyer <cdyer@cs.cmu.edu>2012-05-27 15:34:44 -0400
commit71c4918f05a4b380dfaebfabcc1847c1c6d497dd (patch)
treecd2a0c9c9175ddf8100b1c64d689e540f50eeae9 /utils/weights.cc
parentab38dc57a6a64aa7ef60a845a4176e18e1ac7f27 (diff)
clean up
Diffstat (limited to 'utils/weights.cc')
-rw-r--r--utils/weights.cc16
1 files changed, 8 insertions, 8 deletions
diff --git a/utils/weights.cc b/utils/weights.cc
index 39c18474..f56e2a20 100644
--- a/utils/weights.cc
+++ b/utils/weights.cc
@@ -45,11 +45,11 @@ void Weights::InitFromFile(const string& filename,
}
for (int i = buf.size() - 1; i > 0; --i)
if (buf[i] == '=' || buf[i] == '\t') { buf[i] = ' '; break; }
- int start = 0;
+ unsigned start = 0;
while(start < buf.size() && buf[start] == ' ') ++start;
- int end = 0;
+ unsigned end = 0;
while(end < buf.size() && buf[end] != ' ') ++end;
- const int fid = FD::Convert(buf.substr(start, end - start));
+ const unsigned fid = FD::Convert(buf.substr(start, end - start));
if (feature_list) { feature_list->push_back(buf.substr(start, end - start)); }
while(end < buf.size() && buf[end] == ' ') ++end;
val = strtod(&buf.c_str()[end], NULL);
@@ -73,7 +73,7 @@ void Weights::InitFromFile(const string& filename,
} else { // !read_text
char buf[6];
in.read(buf, 5);
- size_t num_keys;
+ int num_keys;
in.read(reinterpret_cast<char*>(&num_keys), sizeof(size_t));
if (num_keys != FD::NumFeats()) {
cerr << "Hash function reports " << FD::NumFeats() << " keys but weights file contains " << num_keys << endl;
@@ -102,8 +102,8 @@ void Weights::WriteToFile(const string& fname,
if (write_text) {
if (extra) { o << "# " << *extra << endl; }
o.precision(17);
- const int num_feats = FD::NumFeats();
- for (int i = 1; i < num_feats; ++i) {
+ const unsigned num_feats = FD::NumFeats();
+ for (unsigned i = 1; i < num_feats; ++i) {
const weight_t val = (i < weights.size() ? weights[i] : 0.0);
if (hide_zero_value_features && val == 0.0) continue;
o << FD::Convert(i) << ' ' << val << endl;
@@ -126,7 +126,7 @@ void Weights::InitSparseVector(const vector<weight_t>& dv,
}
void Weights::SanityCheck(const vector<weight_t>& w) {
- for (int i = 0; i < w.size(); ++i) {
+ for (unsigned i = 0; i < w.size(); ++i) {
assert(!isnan(w[i]));
assert(!isinf(w[i]));
}
@@ -142,7 +142,7 @@ struct FComp {
void Weights::ShowLargestFeatures(const vector<weight_t>& w) {
vector<int> fnums(w.size());
- for (int i = 0; i < w.size(); ++i)
+ for (unsigned i = 0; i < w.size(); ++i)
fnums[i] = i;
int nf = FD::NumFeats();
if (nf > 10) nf = 10;