Trim causal ConvTranspose1d output to remove extra samples. ConvTranspose1d with kernel=2*stride, stride=S, padding=0 produces: out_len = (in_len - 1) * stride + kernel = in_len * stride + stride We want: in_len * stride, so trim `stride` from the right.
(x: &Tensor, trim: usize)
| 382 | /// out_len = (in_len - 1) * stride + kernel = in_len * stride + stride |
| 383 | /// We want: in_len * stride, so trim `stride` from the right. |
| 384 | fn causal_trim(x: &Tensor, trim: usize) -> Result<Tensor> { |
| 385 | if trim == 0 { |
| 386 | return Ok(x.clone()); |
| 387 | } |
| 388 | let len = x.dim(2)?; |
| 389 | if len > trim { |
| 390 | x.narrow(2, 0, len - trim) |
| 391 | } else { |
| 392 | Ok(x.clone()) |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /// Decode acoustic latents to audio waveform. |
| 397 | /// Input: (batch, vae_dim, frames) or (batch, frames, vae_dim) |