From cf987e95b8c8b113cc102c54e59111f27e3ec862 Mon Sep 17 00:00:00 2001 From: raphaelDkhn Date: Fri, 3 May 2024 14:15:44 +0200 Subject: [PATCH] support ndarray in serializer --- osiris/cairo/serde/serialize.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osiris/cairo/serde/serialize.py b/osiris/cairo/serde/serialize.py index 41ca970..df1e08b 100644 --- a/osiris/cairo/serde/serialize.py +++ b/osiris/cairo/serde/serialize.py @@ -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): @@ -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")