Add stride to the last dimension of a tensor.
(t)
| 14 | |
| 15 | |
| 16 | def rand_stride(t): |
| 17 | """Add stride to the last dimension of a tensor.""" |
| 18 | stride = np.random.randint(2, 4) |
| 19 | ret = torch.stack([t] * stride, dim=-1)[..., 0] |
| 20 | ret = ret.detach() |
| 21 | if torch.is_floating_point(t): |
| 22 | ret.requires_grad_() |
| 23 | return ret |
| 24 | |
| 25 | |
| 26 | def rand_coo(shape, nnz, dev, nz_dim=None): |
no outgoing calls