Learn R Programming

ggmlR (version 0.6.1)

ggml_upscale: Upscale Tensor (Graph)

Description

Upscales tensor by multiplying ne0 and ne1 by scale factor. Supports different interpolation modes for image upscaling.

Usage

ggml_upscale(ctx, a, scale_factor, mode = 0L)

GGML_SCALE_MODE_NEAREST

GGML_SCALE_MODE_BILINEAR

GGML_SCALE_MODE_BICUBIC

Value

Upscaled tensor with dimensions multiplied by scale_factor

Format

An object of class integer of length 1.

An object of class integer of length 1.

An object of class integer of length 1.

Arguments

ctx

GGML context

a

Input tensor (typically 2D or 4D for images)

scale_factor

Integer scale factor (e.g., 2 = double size)

mode

Scale mode constant (see details)

Details

Scale mode constants:

  • GGML_SCALE_MODE_NEAREST (0): Nearest neighbor interpolation - fastest, pixelated

  • GGML_SCALE_MODE_BILINEAR (1): Bilinear interpolation - smooth, good balance

  • GGML_SCALE_MODE_BICUBIC (2): Bicubic interpolation - smoothest, most compute

Examples

Run this code
# \donttest{
ctx <- ggml_init(16 * 1024 * 1024)
img <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 8, 8)
ggml_set_f32(img, rnorm(64))

# Nearest neighbor (fastest, pixelated)
up_nearest <- ggml_upscale(ctx, img, 2, GGML_SCALE_MODE_NEAREST)

# Bilinear (smooth)
up_bilinear <- ggml_upscale(ctx, img, 2, GGML_SCALE_MODE_BILINEAR)

# Bicubic (smoothest)
up_bicubic <- ggml_upscale(ctx, img, 2, GGML_SCALE_MODE_BICUBIC)

graph <- ggml_build_forward_expand(ctx, up_nearest)
ggml_graph_compute(ctx, graph)
# Result is 16x16
ggml_free(ctx)
# }

Run the code above in your browser using DataLab