(tensor, left, right, dim=0)
| 162 | |
| 163 | |
| 164 | def pad_both_ends(tensor, left, right, dim=0): |
| 165 | no_dims = len(tensor.size()) |
| 166 | if dim == -1: |
| 167 | dim = no_dims - 1 |
| 168 | |
| 169 | padding = [0] * 2 * no_dims |
| 170 | padding[2 * (no_dims - dim - 1)] = left |
| 171 | padding[2 * (no_dims - dim - 1) + 1] = right |
| 172 | return F.pad(tensor, padding, "constant", 0) |
| 173 | |
| 174 | |
| 175 | def cut_n_stack(seq, snip_length, cut_dim=0, cutting_stride=None, pad_samples=0): |