| ggml_layer_reshape | R Documentation |
Reinterpret a sample's shape without moving any data. The batch axis is not
part of shape and is never reshaped – shape describes one
sample, exactly as input_shape does.
ggml_layer_reshape(
model,
shape,
input_shape = NULL,
name = NULL,
trainable = TRUE
)
model |
A ggml_sequential_model object, or a |
shape |
Integer vector, the new per-sample shape. At most one entry may
be |
input_shape |
Input shape, required for the first layer only. |
name |
Optional character name for the layer. |
trainable |
Logical; reserved for API consistency (no weights). |
The model object with the reshape layer appended (invisibly), or a
ggml_tensor_node in the functional API.
One entry of shape may be -1, in which case it is computed
from the element count: ggml_layer_reshape(c(-1, 32)) on a
c(4, 8, 16) input gives c(16, 32). At most one axis may be
-1, and the remaining sizes must divide the element count exactly.
Reshape only relabels the axes; the elements keep their memory order. To
actually reorder axes – swapping c(a, b) into c(b, a), say –
use ggml_layer_permute. Using reshape for that silently
interleaves the data instead.
ggml_reshape_*() requires contiguous data, and a permuted tensor is
not contiguous. The layer inserts ggml_cont when needed, so it
works after a permute; the cost is one copy.
ggml_layer_permute to reorder axes,
ggml_layer_flatten to collapse them all.
# Split a flat feature vector into a sequence of 32-wide steps.
model <- ggml_model_sequential() |>
ggml_layer_dense(512, input_shape = 128) |>
ggml_layer_reshape(c(-1, 32))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.