IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /get-started.md).

Mojo function

resize_nearest_neighbor

def resize_nearest_neighbor[coordinate_transformation_mode: CoordinateTransformationMode, round_mode: RoundMode, dtype: DType](input: TileTensor[dtype, Engine=input.Engine, address_space=input.address_space, linear_idx_type=input.linear_idx_type], output: TileTensor[dtype, Engine=output.Engine, address_space=output.address_space, linear_idx_type=output.linear_idx_type], ctx: DeviceContext)

Resizes input to output shape using nearest-neighbor interpolation.

When every axis scales by an exact integer factor and the transform and round modes collapse to floor division at whole factors (asymmetric + floor, half_pixel + half_down, half_pixel + half_up), the kernel skips the coordinate arithmetic entirely and gathers from out_coord // scale. Models used to hand-roll this case with reshape + broadcast to avoid the coordinate math; the fast path makes the standard op just as cheap.

Parameters:

  • ​coordinate_transformation_mode (CoordinateTransformationMode): How to map a coordinate in output to a coordinate in input.
  • ​round_mode (RoundMode): How to round fractional input coordinates to integer indices.
  • ​dtype (DType): Type of input and output.

Args:

Was this page helpful?