| 303 | f"bytes={self.array.tobytes()})") |
| 304 | |
| 305 | def __reduce_ex__(self, protocol): |
| 306 | if not self.array.contiguous: |
| 307 | raise NotImplementedError("Reconstructing a non-contiguous " |
| 308 | "ndarray does not seem possible") |
| 309 | ndarray_kwargs = {"shape": self.array.shape, |
| 310 | "strides": self.array.strides, |
| 311 | "format": self.array.format, |
| 312 | "flags": (0 if self.readonly |
| 313 | else _testbuffer.ND_WRITABLE)} |
| 314 | pb = pickle.PickleBuffer(self.array) |
| 315 | if protocol >= 5: |
| 316 | return (type(self)._reconstruct, |
| 317 | (pb, ndarray_kwargs)) |
| 318 | else: |
| 319 | # Need to serialize the bytes in physical order |
| 320 | with pb.raw() as m: |
| 321 | return (type(self)._reconstruct, |
| 322 | (m.tobytes(), ndarray_kwargs)) |
| 323 | |
| 324 | @classmethod |
| 325 | def _reconstruct(cls, obj, kwargs): |