| nn_build_permute_op | R Documentation |
Shared by the sequential and functional builds.
nn_build_permute_op(ctx, input_tensor, dims, input_shape)
ctx |
Compute context. |
input_tensor |
Input |
dims |
Permutation in ‘aperm' (source) order, over the sample’s axes. |
input_shape |
Per-sample input shape, used only to count the axes. |
The R per-sample shape maps onto ggml axes in order – R axis i is
ne[i - 1] – with the batch on the axis just past the sample's, so a
permutation of the sample's axes leaves the batch where it is.
Two conversions happen here, and both are easy to get backwards:
1-based R axes become 0-based ggml axes.
dims arrives in aperm (source) order, while
ggml_permute() takes destination positions: the argument at
position i says where source axis i lands. Inverting the
permutation is what bridges the two. A self-inverse permutation (a plain
two-axis swap, the common case) is unchanged by this step, which is
precisely why an error here can go unnoticed – see the test on a 3-D
non-symmetric permutation.
The result is passed through ggml_cont(): ggml_permute()
returns a non-contiguous view, and downstream ops (matmul, reshape) require
contiguous data.
A contiguous ggml_tensor with the axes reordered.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.