def store_vector(self, hash_name, bucket_key, v, data):
mongo_key = self._format_mongo_key(hash_name, bucket_key)<EOL>val_dict = {}<EOL>val_dict['<STR_LIT>'] = mongo_key<EOL>if scipy.sparse.issparse(v):<EOL><INDENT>if not scipy.sparse.isspmatrix_coo(v):<EOL><INDENT>v = scipy.sparse.coo_matrix(v)<EOL><DEDENT>encoded_values = []<EOL>for k in range(v.data.size):<EOL><INDENT>row_index = v.row[k]<EOL>value = v.data[k]<EOL>encoded_values.append([int(row_index), value])<EOL><DEDENT>val_dict['<STR_LIT>'] = <NUM_LIT:1><EOL>val_dict['<STR_LIT>'] = encoded_values<EOL>val_dict['<STR_LIT>'] = v.shape[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>v = numpy.reshape(v, v.shape[<NUM_LIT:0>])<EOL>val_dict['<STR_LIT>'] = v.tostring()<EOL><DEDENT>val_dict['<STR_LIT>'] = v.dtype.name<EOL>if data is not None:<EOL><INDENT>val_dict['<STR_LIT:data>'] = data<EOL><DEDENT>self.mongo_object.insert_one(val_dict)<EOL>
Stores vector and JSON-serializable data in MongoDB with specified key.