Skip to content

Commit

Permalink
support ndarray in serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelDkhn committed May 3, 2024
1 parent 06dc8a0 commit cf987e9
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions osiris/cairo/serde/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Tensor,
)
from osiris.cairo.serde.utils import int_to_felt

import numpy as np

def serializer(data):
if isinstance(data, bool):
Expand All @@ -16,10 +16,11 @@ def serializer(data):
elif isinstance(data, (list, tuple)):
joined_elements = ' '.join(serializer(e) for e in data)
return f"[{joined_elements}]"
elif isinstance(data, np.ndarray):
return f"{serializer(data.tolist())}"
elif isinstance(data, Tensor):
return f"{serializer(data.shape)} {serializer(data.data)}"
elif isinstance(data, FixedPoint):
return f"{serializer(data.mag)} {serializer(data.sign)}"

else:
raise ValueError("Unsupported data type for serialization")

0 comments on commit cf987e9

Please sign in to comment.