Skip to content
fn

interpolate_nearest_2d_op

→TensorImplPtr
int interpolate_nearest_2d_op(const int & input, int H_out, int W_out)

Public 2-D nearest-neighbour resize with autograd.

Thin wrapper that delegates to InterpolateNearestBackward2D::forward. Each output pixel receives the value of the nearest input pixel:

y[i,j]=x ⁣[⌊i⋅Hin/Hout⌋,  ⌊j⋅Win/Wout⌋] y[i, j] = x\!\left[\lfloor i \cdot H_{\text{in}} / H_{\text{out}} \rfloor,\; \lfloor j \cdot W_{\text{in}} / W_{\text{out}} \rfloor\right]

(clamped to valid index ranges). A backward node is attached.

Parameters

inputTensorImplPtr
4-D input tensor (N, C, H_in, W_in).
H_outint
Desired output height.
W_outint
Desired output width.

Returns

TensorImplPtr

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