ggml_argsort: Argsort - Get Sorting Indices (Graph)

View source: R/operations.R

ggml_argsortR Documentation

Argsort - Get Sorting Indices (Graph)

Description

Returns indices that would sort the tensor rows. Each row is sorted independently.

Usage

ggml_argsort(ctx, a, order = GGML_SORT_ORDER_ASC)

Arguments

ctx

GGML context

a

Input tensor to sort (F32)

order

Sort order: GGML_SORT_ORDER_ASC (0) or GGML_SORT_ORDER_DESC (1)

Value

Tensor of I32 indices that would sort each row

Examples


ctx <- ggml_init(16 * 1024 * 1024)
# Create tensor with values to sort
a <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 5)
ggml_set_f32(a, c(3, 1, 4, 1, 5))
# Get indices for ascending sort
indices <- ggml_argsort(ctx, a, GGML_SORT_ORDER_ASC)
graph <- ggml_build_forward_expand(ctx, indices)
ggml_graph_compute(ctx, graph)
result <- ggml_get_i32(indices)
# result: [1, 3, 0, 2, 4] (0-indexed positions for sorted order)
ggml_free(ctx)


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