Learn R Programming

ggmlR (version 0.6.1)

ggml_pool_1d: 1D Pooling (Graph)

Description

Applies 1D pooling operation for downsampling.

Usage

ggml_pool_1d(ctx, a, op, k0, s0 = k0, p0 = 0L)

GGML_OP_POOL_MAX

GGML_OP_POOL_AVG

Value

Pooled tensor with reduced dimensions

Format

An object of class integer of length 1.

An object of class integer of length 1.

Arguments

ctx

GGML context

a

Input tensor

op

Pool operation constant (see details)

k0

Kernel size (window size)

s0

Stride (default = k0 for non-overlapping windows)

p0

Padding (default 0)

Details

Pool operation constants:

  • GGML_OP_POOL_MAX (0): Max pooling - takes maximum value in each window

  • GGML_OP_POOL_AVG (1): Average pooling - takes mean of values in each window

Examples

Run this code
# \donttest{
ctx <- ggml_init(16 * 1024 * 1024)
a <- ggml_new_tensor_1d(ctx, GGML_TYPE_F32, 8)
ggml_set_f32(a, c(1, 3, 2, 4, 5, 2, 8, 1))

# Max pooling with kernel 2, stride 2
max_pool <- ggml_pool_1d(ctx, a, GGML_OP_POOL_MAX, k0 = 2)
# Result: [3, 4, 5, 8] (max of each pair)

# Average pooling with kernel 2, stride 2
avg_pool <- ggml_pool_1d(ctx, a, GGML_OP_POOL_AVG, k0 = 2)
# Result: [2, 3, 3.5, 4.5] (mean of each pair)

ggml_free(ctx)
# }

Run the code above in your browser using DataLab