| ggml_scatter_elements | R Documentation |
Copies 'data', then writes each element of 'updates' into the copy at the position given by the matching element of 'indices' along 'axis'. Every other coordinate is the element's own, so 'updates' and 'indices' share a shape and only their position along 'axis' is redirected.
ggml_scatter_elements(ctx, data, updates, indices, reduction = 0L, axis = 0L)
ctx |
A ggml context |
data |
Base tensor (F32); the result starts as a copy of it |
updates |
Values to write (F32), same shape as 'indices' |
indices |
Destination positions along 'axis' (I32) |
reduction |
0 to overwrite, 1 to add |
axis |
Axis to scatter along, in ggml dim order (0 = ne[0]) |
A new tensor with the shape of 'data'
ctx <- ggml_init(16 * 1024 * 1024)
base <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 3, 4) # 4 rows of 3
ggml_set_f32(base, rep(0, 12))
upd <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 3, 2)
ggml_set_f32(upd, c(1, 2, 3, 4, 5, 6))
idx <- ggml_new_tensor_2d(ctx, GGML_TYPE_I32, 3, 2)
ggml_set_i32(idx, c(3L, 3L, 3L, 0L, 0L, 0L)) # rows 3 and 0
out <- ggml_scatter_elements(ctx, base, upd, idx, 0L, 1L)
ggml_free(ctx)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.