Skip to content

Commit

Permalink
testing dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
tschm committed Dec 25, 2023
1 parent 6ac79fa commit 53740cb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions cvx/bson/file.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def write_bson(file: FILE, data: MATRICES) -> int:

def to_bson(data: MATRICES) -> bytes:
"""
Convert a dictionary of numpy arrays into a bson string
Convert a dictionary of data into a bson string
Args:
data: dictionary of numpy arrays
data: dictionary of data
"""
return bytes(bson.dumps({name: encode(matrix) for name, matrix in data.items()}))

Expand Down
23 changes: 23 additions & 0 deletions experiment/demo2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import bson as bson
import numpy as np

from cvx.bson.io import encode

if __name__ == "__main__":
file = "xxx2.bson"
d = dict()

array = np.random.rand(5, 3)
d["aa"] = encode(array)

array = np.random.rand(500, 300)
d["bb"] = encode(array)

with open(file=file, mode="wb") as bson_file:
bson_file.write(bson.dumps(d))

with open(file=file, mode="rb") as bson_file:
# bbb = bson_file.read()
xxx = bson.loads(bson_file.read())
print(type(xxx))
print(xxx.keys())

0 comments on commit 53740cb

Please sign in to comment.