Skip to main content

ClikaRT::ops::flatten

function

flatten()

Tensor flatten(
    Tensor x,
    int64_t start_dim = 0,
    int64_t end_dim = -1
)

Collapse the INCLUSIVE dim range [start_dim, end_dim] into one dim; the defaults collapse everything to 1-D.

Returns a view sharing storage when the input's stride layout factors into the merged shape (contiguous inputs always do); copies into a fresh dense tensor otherwise.

Throws

  • ClikaRT::Error: (INVALID_ARGUMENT) when the dim range is invalid (code_name() carries the reason).

Returns: the flattened tensor, a view when the layout permits.

auto tokens = ClikaRT::ops::flatten(x, 0, 1); // [B, S, D] -> [B*S, D]

Declared in ClikaRT/compute/ops.h, line 3186