Skip to main content

ruda_tensor/api/
spatial_interpolate.rs

1use super::{Tensor, TensorPrimitive, backend::Backend, ops::InterpolateOptions};
2
3/// Resize native `[batch, channels, length]` activations.
4///
5/// Applies the existing interpolation kernel along the length axis, preserving
6/// its coordinate mapping, mode, storage and differentiable backward operation.
7pub fn interpolate1d<B: Backend>(
8    input: Tensor<B, 3>,
9    output_size: usize,
10    options: InterpolateOptions,
11) -> Tensor<B, 3> {
12    Tensor::new(TensorPrimitive::Float(B::interpolate1d(input.into_primitive().tensor(), output_size, options)))
13}
14
15/// Resize native `[batch, channels, depth, height, width]` activations.
16///
17/// Factors interpolation into native height/width and depth passes. `Bilinear`
18/// therefore applies linear interpolation in all three axes; cubic and Lanczos
19/// apply their existing filters separably. Both passes use the supplied corner
20/// alignment, without host resampling or detaching the gradient graph.
21pub fn interpolate3d<B: Backend>(
22    input: Tensor<B, 5>,
23    output_size: [usize; 3],
24    options: InterpolateOptions,
25) -> Tensor<B, 5> {
26    Tensor::new(TensorPrimitive::Float(B::interpolate3d(input.into_primitive().tensor(), output_size, options)))
27}