Skip to content

Instantly share code, notes, and snippets.

@psinger
Created March 18, 2018 13:54
Show Gist options
  • Save psinger/c6615508340583b20b81c9f90e48480a to your computer and use it in GitHub Desktop.
Save psinger/c6615508340583b20b81c9f90e48480a to your computer and use it in GitHub Desktop.
import numpy as np
f = tb.open_file('dot.h5', 'w')
filters = tb.Filters(complevel=5, complib='blosc')
out_data = f.create_earray(f.root, 'data', tb.Float32Atom(), shape=(0,), filters=filters)
out_indices = f.create_earray(f.root, 'indices', tb.Int32Atom(),shape=(0,), filters=filters)
out_indptr = f.create_earray(f.root, 'indptr', tb.Int32Atom(), shape=(0,), filters=filters)
out_indptr.append(np.array([0])) #this is needed as a first indptr
max_indptr = 0
for i in range(0, l, bl):
res = a[i:min(i+bl, l),:].dot(b)
out_data.append(res.data)
indices = res.indices
indptr = res.indptr
out_indices.append(indices)
out_indptr.append(max_indptr+indptr[1:])
max_indptr += indices.shape[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment