From 2edd7e65a373e3037c554af4b196016ace154d5a Mon Sep 17 00:00:00 2001 From: Arun Isaac Date: Wed, 8 Jun 2022 17:49:42 +0530 Subject: gn3: genodb: Support reading columns. * gn3/genodb.py (Matrix.__init__): Retrieve column pointers from database. (row): Abstract out vector access code to ... (Matrix.__vector): ... here. (Matrix.column): New method. --- gn3/genodb.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'gn3') 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) -- cgit v1.2.3