| ggml_custom_inplace | R Documentation |
Creates a custom-op node that writes into a view of a rather than into
a freshly allocated tensor. The output has the shape and type of a,
and a itself is the node's first source; tensors in args follow
it, so the kernel sees a as dst->src[0] and the first extra
argument as dst->src[1].
ggml_custom_inplace(ctx, a, name, args = NULL, n_tasks = GGML_N_TASKS_MAX)
ctx |
GGML context |
a |
Tensor to write into |
name |
Name of a registered custom op (character scalar) |
args |
List of additional input tensors, or NULL for none. At most 8
tensors, one fewer than |
n_tasks |
Number of threads the kernel may be split across, or
|
See ggml_custom for how kernels are registered and for the
CPU-only backend restriction, which applies here too.
Tensor pointer for the custom node (a view of a)
ggml_custom, ggml_custom_ops
# "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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.