summaryrefslogtreecommitdiff
path: root/utils/weights.cc
diff options
context:
space:
mode:
authorChris Dyer <cdyer@cs.cmu.edu>2011-09-13 18:33:08 +0100
committerChris Dyer <cdyer@cs.cmu.edu>2011-09-13 18:33:08 +0100
commitdffebff1a33e581a4a36ba060faf5a2ba8e87faa (patch)
treeab3f83d4da4339c8d44a5c52c2a1c9739d2f7780 /utils/weights.cc
parentbff9f7f6e3ed777c9379c0373657eeaf43a6a213 (diff)
fix weight serialization bug
Diffstat (limited to 'utils/weights.cc')
-rw-r--r--utils/weights.cc18
1 files changed, 10 insertions, 8 deletions
diff --git a/utils/weights.cc b/utils/weights.cc
index c49000be..ac407dfb 100644
--- a/utils/weights.cc
+++ b/utils/weights.cc
@@ -23,7 +23,7 @@ void Weights::InitFromFile(const string& filename,
istream& hi = *hdrrf.stream();
assert(hi);
char buf[10];
- hi.get(buf, 6);
+ hi.read(buf, 5);
assert(hi.good());
if (strncmp(buf, "_PHWf", 5) == 0) {
read_text = false;
@@ -72,18 +72,20 @@ void Weights::InitFromFile(const string& filename,
}
} else { // !read_text
char buf[6];
- in.get(buf, 6);
- size_t num_keys[2];
- in.get(reinterpret_cast<char*>(&num_keys[0]), sizeof(size_t) + 1);
- if (num_keys[0] != FD::NumFeats()) {
- cerr << "Hash function reports " << FD::NumFeats() << " keys but weights file contains " << num_keys[0] << endl;
+ in.read(buf, 5);
+ size_t 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;
abort();
}
- weights.resize(num_keys[0]);
- in.get(reinterpret_cast<char*>(&weights[0]), num_keys[0] * sizeof(weight_t));
+ weights.resize(num_keys);
+ in.read(reinterpret_cast<char*>(&weights.front()), num_keys * sizeof(weight_t));
if (!in.good()) {
cerr << "Error loading weights!\n";
abort();
+ } else {
+ cerr << " Successfully loaded " << (num_keys * sizeof(weight_t)) << " bytes\n";
}
}
}