| 213 | |
| 214 | @Decoder.register(np.ndarray) |
| 215 | def decode(dct): |
| 216 | def load(mode="base64"): |
| 217 | if mode == "base64": |
| 218 | data = base64.b64decode(dct["array"].encode(), validate=True) |
| 219 | elif mode == "latin-1": |
| 220 | data = dct["array"].encode(mode) |
| 221 | else: |
| 222 | assert False, f"Unsupported mode: {mode}" |
| 223 | infile = io.BytesIO(data) |
| 224 | return np.load(infile, allow_pickle=False) |
| 225 | |
| 226 | try: |
| 227 | arr = load() |
| 228 | except: |
| 229 | arr = load("latin-1") # For backwards compatibility |
| 230 | if isinstance(arr, np.ndarray): |
| 231 | return arr |
| 232 | return list(arr.values())[0] # For backwards compatibility |
| 233 | |
| 234 | NUMPY_REGISTRATION_SUCCESS = True |
| 235 | |