use burn::{
Tensor,
tensor::kind::Basic,
};
pub fn drop_last_frame<K>(stream: Tensor<3, K>) -> Tensor<3, K>
where
K: Basic,
{
let frames = stream.dims()[1];
assert!(
frames >= 2,
"package_mels needs at least 2 frames, got {frames}: one is dropped, \
and the clamp reduces over what remains",
);
stream.slice_dim(1, 0..frames as isize - 1)
}
#[cfg(test)]
mod test {
use burn::{
Tensor,
prelude::s,
tensor::Int,
};
use super::*;
use crate::support::testing::cpu_device;
#[test]
fn test_drop_last_frame() {
let device = cpu_device();
let stream: Tensor<3, Int> = Tensor::<1, Int>::arange(0..24, &device).reshape([2, 3, 4]);
let actual: Tensor<3, Int> = drop_last_frame(stream.clone());
let expected: Tensor<3, Int> = stream.slice(s![.., ..-1, ..]);
actual
.to_data_as::<i32>()
.assert_eq(&expected.to_data_as::<i32>(), true);
}
}