From cf9871f97e065c210b72251458c9649c10a778ce Mon Sep 17 00:00:00 2001 From: Alexander_Kabui Date: Tue, 24 Jan 2023 07:09:42 +0300 Subject: add array serialization/deserialization --- .../correlation/correlation_file_generator.py | 23 ++++++++++------------ 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/wqflask/wqflask/correlation/correlation_file_generator.py b/wqflask/wqflask/correlation/correlation_file_generator.py index e06c4123..ccc06f3c 100644 --- a/wqflask/wqflask/correlation/correlation_file_generator.py +++ b/wqflask/wqflask/correlation/correlation_file_generator.py @@ -5,6 +5,8 @@ import csv import lmdb import os import tempfile +import numpy as np +from io import BytesIO @@ -144,25 +146,20 @@ def generate_csv_file(conn,db_name,txt_dir,file_name): raise e - def lmdb_file_generator(): pass -"""" -import lmdb -import os -import tempfile -with tempfile.TemporaryDirectory() as tmpdirname: +def array_to_bytes(x:np.ndarray) -> bytes: + np_bytes = BytesIO() - tmp_file_path = os.path.join(tmpdirname,"img_lmdb") - breakpoint() - db = lmdb.open(tmp_file_path, map_size=int(1e12)) + np.save(np_bytes,x,allow_pickle =True) + return (np_bytes.getvalue()) - with db.begin(write=True) as in_txn: - - db.close() -""" + +def bytes_to_array(b: bytes) -> np.ndarray: + np_bytes = BytesIO(b) + return np.load(np_bytes, allow_pickle=True) \ No newline at end of file -- cgit v1.2.3