Learn R Programming

ggmlR (version 0.8.4)

ggml_scale_bias: 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)

Value

Tensor representing s * a + b

Arguments

ctx

GGML context

a

Input tensor

s

Scale factor (numeric scalar)

b

Bias added after scaling (numeric scalar)

Examples

Run this code
# \donttest{
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)
# }

Run the code above in your browser using DataLab