Skip to content
class

InterpolateTrilinearBackward

InterpolateTrilinearBackward

Autograd node for 3-D trilinear interpolation.

Resizes a 5-D tensor of shape (N, C, D_in, H_in, W_in) to (N, C, D_out, H_out, W_out) by linearly interpolating between the eight neighbouring input voxels. Conceptually the trilinear weights are the product of three 1-D linear weights (one per spatial axis), giving

y[d,i,j]=∑a,b,c∈{0,1}wda wib wjc x[d0+a,i0+b,j0+c] y[d, i, j] = \sum_{a, b, c \in \{0, 1\}} w_{d}^{a} \, w_{i}^{b} \, w_{j}^{c} \, x[d_0 + a, i_0 + b, j_0 + c]

where the per-axis source coordinates follow the same align_corners rule described in the file header.

Math

Output size formula (per axis S∈{D,H,W}S \in \{D, H, W\}):

Sout=user-specified,sin(k)={k⋅(Sin−1)/(Sout−1)align_corners(k+0.5)⋅Sin/Sout−0.5otherwise S_{\text{out}} = \text{user-specified}, \quad s_{\text{in}}^{(k)} = \begin{cases} k \cdot (S_{\text{in}} - 1) / (S_{\text{out}} - 1) & \text{align\_corners} \\ (k + 0.5) \cdot S_{\text{in}} / S_{\text{out}} - 0.5 & \text{otherwise} \end{cases}

Attributes

schema_v1OpSchema
"interpolate_trilinear", AmpPolicy::Promote.
D_in_, H_in_, W_in_int
Saved input spatial dimensions.
D_out_, H_out_, W_out_int
Requested output spatial dimensions.
align_corners_bool
Coordinate mapping mode.
orig_shape_Shape
Full (N, C, D_in, H_in, W_in) shape for backward reconstruction.

Static methods

1
static

forward

→TensorImplPtr
int forward(const int & input, int D_out, int H_out, int W_out, bool align_corners)

Compute the trilinear resize with autograd wiring.

Parameters

inputTensorImplPtr
5-D input tensor of shape (N, C, D_in, H_in, W_in).
D_outint
Desired output depth.
H_outint
Desired output height.
W_outint
Desired output width.
align_cornersbool
Coordinate mapping mode.

Returns

TensorImplPtr

Resampled tensor of shape (N, C, D_out, H_out, W_out).

Raises

ShapeMismatch
If input is not 5-D.

Methods

2
fn

apply

int apply(int grad_out)

Backward pass: scatters grad_out to source voxels using the same trilinear weights as the forward.

fn

apply_for_graph

int apply_for_graph(const int & grad_out)

Graph-mode backward: one matmul per axis against the 1-D resampling matrices, so it can be differentiated again.