diff options
author | John Langford <jl@hunch.net> | 2009-09-20 03:17:28 +0400 |
---|---|---|
committer | John Langford <jl@hunch.net> | 2009-09-20 03:17:28 +0400 |
commit | f5e75687c8d6debdbdc38ba5cc023ecb209bd9af (patch) | |
tree | 84962846432895610bd575360634aa3663b46d37 /parse_regressor.cc | |
parent | 0bda878246f522418bdf71902fa45c8efab9347e (diff) |
first compiling (but not debugged) cluster version.
Diffstat (limited to 'parse_regressor.cc')
-rw-r--r-- | parse_regressor.cc | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/parse_regressor.cc b/parse_regressor.cc index 0a83ec3a..d40cf0ed 100644 --- a/parse_regressor.cc +++ b/parse_regressor.cc @@ -13,16 +13,16 @@ using namespace std; void initialize_regressor(regressor &r) { - size_t length = ((size_t)1) << r.global->num_bits; - r.global->thread_mask = (length >> r.global->thread_bits) - 1; - size_t num_threads = r.global->num_threads(); + size_t length = ((size_t)1) << global.num_bits; + global.thread_mask = (length >> global.thread_bits) - 1; + size_t num_threads = global.num_threads(); r.weight_vectors = (weight **)malloc(num_threads * sizeof(weight*)); for (size_t i = 0; i < num_threads; i++) { r.weight_vectors[i] = (weight *)calloc(length/num_threads, sizeof(weight)); if (r.weight_vectors[i] == NULL) { - cerr << r.global->program_name << ": Failed to allocate weight array: try decreasing -b <bits>" << endl; + cerr << global.program_name << ": Failed to allocate weight array: try decreasing -b <bits>" << endl; exit (1); } } @@ -55,10 +55,10 @@ void parse_regressor_args(po::variables_map& vm, regressor& r, string& final_reg size_t local_num_bits; regressor.read((char *)&local_num_bits, sizeof(local_num_bits)); if (!initialized){ - r.global->num_bits = local_num_bits; + global.num_bits = local_num_bits; } else - if (local_num_bits != r.global->num_bits) + if (local_num_bits != global.num_bits) { cout << "can't combine regressors with different feature number!" << endl; exit (1); @@ -67,10 +67,10 @@ void parse_regressor_args(po::variables_map& vm, regressor& r, string& final_reg size_t local_thread_bits; regressor.read((char*)&local_thread_bits, sizeof(local_thread_bits)); if (!initialized){ - r.global->thread_bits = local_thread_bits; + global.thread_bits = local_thread_bits; } else - if (local_thread_bits != r.global->thread_bits) + if (local_thread_bits != global.thread_bits) { cout << "can't combine regressors trained with different numbers of threads!" << endl; exit (1); @@ -89,19 +89,19 @@ void parse_regressor_args(po::variables_map& vm, regressor& r, string& final_reg } if (!initialized) { - r.global->pairs = local_pairs; + global.pairs = local_pairs; initialize_regressor(r); initialized = true; } else - if (local_pairs != r.global->pairs) + if (local_pairs != global.pairs) { cout << "can't combine regressors with different features!" << endl; for (size_t i = 0; i < local_pairs.size(); i++) cout << local_pairs[i] << " " << local_pairs[i].size() << " "; cout << endl; - for (size_t i = 0; i < r.global->pairs.size(); i++) - cout << r.global->pairs[i] << " " << r.global->pairs[i].size() << " "; + for (size_t i = 0; i < global.pairs.size(); i++) + cout << global.pairs[i] << " " << global.pairs[i].size() << " "; cout << endl; exit (1); } @@ -112,7 +112,7 @@ void parse_regressor_args(po::variables_map& vm, regressor& r, string& final_reg weight w = 0.; regressor.read((char *)&w, sizeof(float)); - size_t num_threads = r.global->num_threads(); + size_t num_threads = global.num_threads(); if (regressor.good()) r.weight_vectors[hash % num_threads][hash/num_threads] = r.weight_vectors[hash % num_threads][hash/num_threads] + w; @@ -130,7 +130,7 @@ void free_regressor(regressor &r) { if (r.weight_vectors != NULL) { - for (size_t i = 0; i < r.global->num_threads(); i++) + for (size_t i = 0; i < global.num_threads(); i++) if (r.weight_vectors[i] != NULL) free(r.weight_vectors[i]); free(r.weight_vectors); @@ -141,15 +141,15 @@ void dump_regressor(ofstream &o, regressor &r) { if (o.is_open()) { - o.write((char *)&r.global->num_bits, sizeof(r.global->num_bits)); - o.write((char *)&r.global->thread_bits, sizeof(r.global->thread_bits)); - int len = r.global->pairs.size(); + o.write((char *)&global.num_bits, sizeof(global.num_bits)); + o.write((char *)&global.thread_bits, sizeof(global.thread_bits)); + int len = global.pairs.size(); o.write((char *)&len, sizeof(len)); - for (vector<string>::iterator i = r.global->pairs.begin(); i != r.global->pairs.end();i++) + for (vector<string>::iterator i = global.pairs.begin(); i != global.pairs.end();i++) o << (*i)[0] << (*i)[1]; - uint32_t length = 1 << r.global->num_bits; - size_t num_threads = r.global->num_threads(); + uint32_t length = 1 << global.num_bits; + size_t num_threads = global.num_threads(); for(uint32_t i = 0; i < length; i++) { weight v = r.weight_vectors[i%num_threads][i/num_threads]; |