nn_build_reshape_op: Build reshape forward pass

View source: R/nn_layers.R

nn_build_reshape_opR Documentation

Build reshape forward pass

Description

Shared by the sequential and functional builds.

Usage

nn_build_reshape_op(ctx, input_tensor, shape, input_shape)

Arguments

ctx

Compute context.

input_tensor

Input ggml_tensor.

shape

Resolved per-sample output shape (no '-1' left).

input_shape

Per-sample input shape.

Details

The batch is appended as the trailing ggml axis, and is derived from the element count rather than from ggml_n_dims(): ggml reports a trailing unit dimension as absent, so a batch of 1 would otherwise be read off a real axis (the same reasoning as in [nn_build_flatten()]).

ggml_reshape_*() asserts that its input is contiguous, and an assert aborts the process instead of raising an R error, so a non-contiguous input (a permute that was not followed by ggml_cont(), say) is made contiguous first.

Value

A ggml_tensor viewing the input under the new shape.


ggmlR documentation built on Oct. 23, 2026, 1:07 a.m.