# "row_median" is one of ggmlR's built-in kernels; see ggml_custom_ops().
ggml_set_n_threads(1L)
ctx <- ggml_init(16 * 1024 * 1024)
x <- ggml_new_tensor_2d(ctx, GGML_TYPE_F32, 5, 2)
ggml_set_f32(x, c(5, 1, 3, 2, 4,
9, 7, 8, 6, 10))
# One median per row: the output collapses ne[1] to 1.
med <- ggml_custom(ctx, "row_median", args = list(x), ne = c(1, 2))
graph <- ggml_build_forward_expand(ctx, med)
ggml_graph_compute(ctx, graph)
ggml_get_f32(med) # 3, 8
ggml_free(ctx)
Run the code above in your browser using DataLab