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_cubic
def resize_cubic[in_dtype: DType, out_dtype: DType, //](input: ImmTileTensor[in_dtype, Engine=input.Engine, address_space=input.address_space, linear_idx_type=input.linear_idx_type], output: MutTileTensor[out_dtype, Engine=output.Engine, address_space=output.address_space, linear_idx_type=output.linear_idx_type])
Resizes the height and width of an [outer, H, W, inner] tensor with antialiased cubic interpolation.
The filter is the Keys cubic with a = -0.5, stretched by the downscale
factor. Taps outside the input are dropped, and the remaining weights are
normalized to a sum of one. This is the filter of torch's CPU
interpolate(mode="bicubic", antialias=True, align_corners=False), and
the result matches it to float32 rounding.
A uint8 input with a uint8 output resizes as Pillow's BICUBIC resizes a
uint8 image, bit for bit, rather than as torch does: the same filter, its
weights computed in float64 and rounded to 22-bit fixed point, and each
pass summing in int32 and rounding half up and clamping to uint8.
An NHWC batch is [N, H, W, C], and an NCHW batch is [N * C, H, W, 1].
W is resampled before H, and each output adds up its taps in order with
FMAs, so every shape gives the same bits for the same pixels. The resize
runs on the CPU, on the calling thread, in float32 or, for a uint8
output, in fixed point.
Constraints:
Both tensors are rank 4. The input is float32 or an integer type. The output is float32, or uint8 for a uint8 input.
Parameters:
- βin_dtype (
DType): The type of the input: float32, or an integer type such as uint8. With a float32 output, the result is the same as when you convert the input to float32 first. - βout_dtype (
DType): The type of the output: float32, or uint8 for a uint8 input, which resizes as Pillow does.
Args:
- βinput (
ImmTileTensor[in_dtype, Engine=input.Engine, address_space=input.address_space, linear_idx_type=input.linear_idx_type]): The input to be resized, contiguous and row-major. - βoutput (
MutTileTensor[out_dtype, Engine=output.Engine, address_space=output.address_space, linear_idx_type=output.linear_idx_type]): The output containing the resized input, contiguous and row-major, with the outer and inner sizes of the input. It must not overlap the input.