def load(filename, data_structure='sparsevec'): global data if data_structure == 'sparsevec': d, i = sparsevec(filename) data = {'data': d, 'index': i} elif data_structure == 'hash': data = hash(filename)
def __init__(self, filename, data_structure='sparsevec'): if data_structure == 'sparsevec': d, i = sparsevec(filename) self.data = {'data': d, 'index': i} self.sparsevec = d self.index = i elif data_structure == 'hash': self.hash = self.data = hash(filename)
def test_index(): from sv_func import sparsevec, hash, sparsevec_index, hash_index d, i = sparsevec('stream.dat') data_hash = hash('stream.dat') data = {'data': d, 'index': i} # Check one data item in the compressed structure and one zero assert sparsevec_index(3, d, i) == index(3, d) assert hash_index(3, data_hash) == index(3, data_hash) assert sparsevec_index(9, d, i) == index(9, d) assert hash_index(9, data_hash) == index(9, data_hash)