MCPcopy Create free account
hub / github.com/RLinf/LaWAM / pack_array

Function pack_array

deployment/model_server/tools/msgpack_numpy.py:21–40  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

19
20
21def pack_array(obj):
22 if (isinstance(obj, (np.ndarray, np.generic))) and obj.dtype.kind in ("V", "O", "c"):
23 raise ValueError(f"Unsupported dtype: {obj.dtype}")
24
25 if isinstance(obj, np.ndarray):
26 return {
27 b"__ndarray__": True,
28 b"data": obj.tobytes(),
29 b"dtype": obj.dtype.str,
30 b"shape": obj.shape,
31 }
32
33 if isinstance(obj, np.generic):
34 return {
35 b"__npgeneric__": True,
36 b"data": obj.item(),
37 b"dtype": obj.dtype.str,
38 }
39
40 return obj
41
42
43def unpack_array(obj):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected