ged-lab/khmer — pull request #671 by camillescott (2014-11-24 00:48:23+00:00)
Title: Initial implementation of read-only buffer access to raw tables

This addresses #667: exposes the tables as a read-only buffer object. I've chosen read-only as there will be undefined behavior from writing directly to the tables outside of the `count` functions; of course, the idea is that you can still use the python-exposed hashtable object as you see fit, and the buffer view will update to reflect that.

For now, I've just exported a list of `N` buffers. Eventually I'd like this to properly define the buffer interface on the hashtable type object, exposing a single buffer or memoryview object with proper striding / offsets for the `N` dimension array, but... :effort:.

Some example usage:

```
In [1]: import khmer

In [2]: import numpy as np

In [3]: ht = khmer.new_counting_hash (20, 1e8, 4)

In [4]: tables = ht.get_raw_tables ()

In [5]: tables[0]
Out[5]:

In [6]: arr = np.frombuffer (tables[0], dtype=np.uint8)

In [7]: arr
Out[7]: array([0, 0, 0, ..., 0, 0, 0], dtype=uint8)

In [8]: arr.sum()
Out[8]: 0

In [9]: ht.consume_fasta('tests/test-data/test-reads.fa')
Out[9]: (25000, 1425000L)

In [10]: arr.sum()
Out[10]: 1424408
```