ggml_concat: Concatenate Tensors (Graph)

View source: R/operations.R

ggml_concatR Documentation

Concatenate Tensors (Graph)

Description

Concatenates two tensors along a specified dimension. CRITICAL for KV-cache operations in transformers.

Usage

ggml_concat(ctx, a, b, dim = 0)

Arguments

ctx

GGML context

a

First tensor

b

Second tensor (must match a in all dimensions except the concat dim)

dim

Dimension along which to concatenate (0-3)

Value

Concatenated tensor

Examples


ctx <- ggml_init(16 * 1024 * 1024)
a <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 4, 3)
b <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 4, 2)
ggml_set_f32(a, rnorm(12))
ggml_set_f32(b, rnorm(8))
# Concatenate along dimension 1: result is 4x5
c <- ggml_concat(ctx, a, b, 1)
graph <- ggml_build_forward_expand(ctx, c)
ggml_graph_compute(ctx, graph)
ggml_free(ctx)


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