ggml_scale_bias: Scale and Shift by Constants (Graph)

View source: R/operations.R

ggml_scale_biasR Documentation

Scale and Shift by Constants (Graph)

Description

Creates a graph node computing s * a + b for scalar s and b. Unlike ggml_add1() with ggml_new_f32(), this adds a constant without materialising a data-carrying tensor, so it is usable while building a graph in a no_alloc context.

Usage

ggml_scale_bias(ctx, a, s, b)

Arguments

ctx

GGML context

a

Input tensor

s

Scale factor (numeric scalar)

b

Bias added after scaling (numeric scalar)

Value

Tensor representing s * a + b

Examples


ctx <- ggml_init(16 * 1024 * 1024)
a <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 4)
ggml_set_f32(a, c(1, 2, 3, 4))
result <- ggml_scale_bias(ctx, a, 2.0, 1.0)
graph <- ggml_build_forward_expand(ctx, result)
ggml_graph_compute(ctx, graph)
output <- ggml_get_f32(result)  # [3, 5, 7, 9]
ggml_free(ctx)


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.