Created
June 14, 2014 11:38
-
-
Save abinashpanda/d1273e12b3aa6886a5c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SGSparseVector<float64_t> hash_vector(SGSparseVector<float64_t> vec, int32_t dim, | |
uint32_t seed) | |
{ | |
SGVector<float64_t> h_vec(dim); | |
h_vec.zero(); | |
for (index_t i=0; i<vec.num_feat_entries; i++) | |
{ | |
uint32_t hash = CHash::MurmurHash3((uint8_t* ) &vec.features[i].feat_index, sizeof (index_t), | |
seed); | |
h_vec[hash % dim] += vec.features[i].entry; | |
} | |
int32_t num_nnz_features = 0; | |
for (index_t i=0; i<dim; i++) | |
{ | |
if (h_vec[i]!=0) | |
num_nnz_features++; | |
} | |
SGSparseVector<float64_t> sv(num_nnz_features); | |
int32_t sparse_index = 0; | |
for (index_t i=0; i<dim; i++) | |
{ | |
if (h_vec[i]!=0) | |
{ | |
sv.features[sparse_index].entry = h_vec[i]; | |
sv.features[sparse_index++].feat_index = i; | |
} | |
} | |
return sv; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment