Apply causal left-padding to a tensor: zero-pad `amount` on the left of dim 2.
(x: &Tensor, amount: usize)
| 370 | |
| 371 | /// Apply causal left-padding to a tensor: zero-pad `amount` on the left of dim 2. |
| 372 | fn causal_pad(x: &Tensor, amount: usize) -> Result<Tensor> { |
| 373 | if amount == 0 { |
| 374 | return Ok(x.clone()); |
| 375 | } |
| 376 | let pad = Tensor::zeros((x.dim(0)?, x.dim(1)?, amount), x.dtype(), x.device())?; |
| 377 | Tensor::cat(&[&pad, x], 2) |
| 378 | } |
| 379 | |
| 380 | /// Trim causal ConvTranspose1d output to remove extra samples. |
| 381 | /// ConvTranspose1d with kernel=2*stride, stride=S, padding=0 produces: |