aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gn3/genodb.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/gn3/genodb.py b/gn3/genodb.py
index 96bded6..c2decb8 100644
--- a/gn3/genodb.py
+++ b/gn3/genodb.py
@@ -24,10 +24,16 @@ class Matrix():
def __init__(self, db, hash):
self.nrows = int.from_bytes(db.get_metadata(hash, 'nrows'), byteorder='little')
self.ncols = int.from_bytes(db.get_metadata(hash, 'ncols'), byteorder='little')
- self.row_pointers = db.get(hash)
+ row_column_pointers = db.get(hash)
+ self.row_pointers = row_column_pointers[0 : self.nrows*db.hash_length]
+ self.column_pointers = row_column_pointers[self.nrows*db.hash_length :]
self.db = db
- def row(self, index):
+ def __vector(self, index, pointers):
start = index * self.db.hash_length
end = start + self.db.hash_length
- return np.frombuffer(self.db.get(self.row_pointers[start:end]),
+ return np.frombuffer(self.db.get(pointers[start:end]),
dtype=np.uint8)
+ def row(self, index):
+ return self.__vector(index, self.row_pointers)
+ def column(self, index):
+ return self.__vector(index, self.column_pointers)