diff options
author | Chris Dyer <cdyer@cs.cmu.edu> | 2011-09-13 18:33:08 +0100 |
---|---|---|
committer | Chris Dyer <cdyer@cs.cmu.edu> | 2011-09-13 18:33:08 +0100 |
commit | deb054ab7fb92e18fb1e3a7adb96577ad8e91a86 (patch) | |
tree | 7f125f6a79e0ab5d3891ffb1e5d37752bcf18cc5 /utils | |
parent | 409165b237b571a8b9e4108639667301b7243147 (diff) |
fix weight serialization bug
Diffstat (limited to 'utils')
-rw-r--r-- | utils/weights.cc | 18 |
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"; } } } |