# "clip_inplace" takes its bounds as a 2-element tensor, since a custom node
# carries no scalar parameters of its own.
ggml_set_n_threads(1L)
ctx <- ggml_init(16 * 1024 * 1024)
x <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 5)
ggml_set_f32(x, c(-3, -1, 0, 1, 3))
bounds <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 2)
ggml_set_f32(bounds, c(-1, 1))
y <- ggml_custom_inplace(ctx, x, "clip_inplace", args = list(bounds))
graph <- ggml_build_forward_expand(ctx, y)
ggml_graph_compute(ctx, graph)
ggml_get_f32(y) # -1, -1, 0, 1, 1
ggml_free(ctx)
Run the code above in your browser using DataLab