| 11 | |
| 12 | |
| 13 | class NumpyEncoder(json.JSONEncoder): |
| 14 | def default(self, obj): |
| 15 | if isinstance(obj, (np.int_, np.intc, np.intp, np.int8, |
| 16 | np.int16, np.int32, np.int64, np.uint8, |
| 17 | np.uint16, np.uint32, np.uint64)): |
| 18 | return int(obj) |
| 19 | elif isinstance(obj, (np.float_, np.float16, np.float32, np.float64)): |
| 20 | return float(obj) |
| 21 | elif isinstance(obj, (np.complex_, np.complex64, np.complex128)): |
| 22 | return {'real': obj.real, 'imag': obj.imag} |
| 23 | elif isinstance(obj, (np.ndarray,)): |
| 24 | return obj.tolist() |
| 25 | elif isinstance(obj, (np.bool_)): |
| 26 | return bool(obj) |
| 27 | elif isinstance(obj, (np.void)): |
| 28 | return None |
| 29 | return json.JSONEncoder.default(self, obj) |
| 30 | |
| 31 | def dump(data, f, **kwargs): |
| 32 | def dump_pkl(data, pth, **kwargs): |
nothing calls this directly
no outgoing calls
no test coverage detected