Return a zero-copy view of the array collapsed to 1-D. Only supported for contiguous arrays.
(self)
| 4242 | return warp.clone(self, device=device, requires_grad=requires_grad) |
| 4243 | |
| 4244 | def flatten(self): |
| 4245 | """Return a zero-copy view of the array collapsed to 1-D. Only supported for contiguous arrays.""" |
| 4246 | if self.ndim == 1: |
| 4247 | return self |
| 4248 | |
| 4249 | if not self.is_contiguous: |
| 4250 | raise RuntimeError("Flattening non-contiguous arrays is unsupported.") |
| 4251 | |
| 4252 | a = array( |
| 4253 | ptr=self.ptr, |
| 4254 | dtype=self.dtype, |
| 4255 | shape=(self.size,), |
| 4256 | device=self.device, |
| 4257 | pinned=self.pinned, |
| 4258 | copy=False, |
| 4259 | grad=None if self.grad is None else self.grad.flatten(), |
| 4260 | ) |
| 4261 | |
| 4262 | # transfer read flag |
| 4263 | a._is_read = self._is_read |
| 4264 | |
| 4265 | # store back-ref to stop data being destroyed |
| 4266 | a._ref = self |
| 4267 | return a |
| 4268 | |
| 4269 | def reshape(self, shape): |
| 4270 | """Return a reshaped array. Only supported for contiguous arrays. |