ggml_pad: Pad Tensor with Zeros (Graph)

View source: R/operations.R

ggml_padR Documentation

Pad Tensor with Zeros (Graph)

Description

Pads tensor dimensions with zeros on the right side. Useful for aligning tensor sizes in attention operations.

Usage

ggml_pad(ctx, a, p0 = 0L, p1 = 0L, p2 = 0L, p3 = 0L)

Arguments

ctx

GGML context

a

Input tensor to pad

p0

Padding for dimension 0 (default 0)

p1

Padding for dimension 1 (default 0)

p2

Padding for dimension 2 (default 0)

p3

Padding for dimension 3 (default 0)

Value

Padded tensor with shape [ne0+p0, ne1+p1, ne2+p2, ne3+p3]

Examples


ctx <- ggml_init(16 * 1024 * 1024)
a <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 5, 3)
ggml_set_f32(a, 1:15)
# Pad to 8x4
b <- ggml_pad(ctx, a, 3, 1)  # Add 3 zeros to dim0, 1 to dim1
graph <- ggml_build_forward_expand(ctx, b)
ggml_graph_compute(ctx, graph)
# Result shape: [8, 4]
ggml_free(ctx)


ggmlR documentation built on July 14, 2026, 1:08 a.m.