The OpenD Programming Language

unsqueeze

Constructs a view of an n-dimensional slice with a dimension added at axis. Used to unsqueeze a squeezed slice.

template unsqueeze(sizediff_t axis = 0)
Slice!(Iterator, N + 1, kind)
unsqueeze
(
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) slice
)

Parameters

slice

n-dimensional slice

axis

dimension to be unsqueezed (add new dimension), default values is 0, the first dimension

Return Value

unsqueezed n+1-dimensional slice of the same slice kind

Examples

// [0, 1, 2] -> [[0, 1, 2]]
assert([3].iota.unsqueeze == [1, 3].iota);

assert([3].iota.universal.unsqueeze == [1, 3].iota);
assert([3, 4].iota.unsqueeze == [1, 3, 4].iota);
assert([3, 4].iota.canonical.unsqueeze == [1, 3, 4].iota);
assert([3, 4].iota.universal.unsqueeze == [1, 3, 4].iota);

// [0, 1, 2] -> [[0], [1], [2]]
assert([3].iota.unsqueeze(-1) == [3, 1].iota);
assert([3].iota.unsqueeze!(-1) == [3, 1].iota);

assert([3].iota.universal.unsqueeze(-1) == [3, 1].iota);
assert([3].iota.universal.unsqueeze!(-1) == [3, 1].iota);
assert([3, 4].iota.unsqueeze(-1) == [3, 4, 1].iota);
assert([3, 4].iota.unsqueeze!(-1) == [3, 4, 1].iota);
assert([3, 4].iota.canonical.unsqueeze(-1) == [3, 4, 1].iota);
assert([3, 4].iota.canonical.unsqueeze!(-1) == [3, 4, 1].iota);
assert([3, 4].iota.universal.unsqueeze(-1) == [3, 4, 1].iota);
assert([3, 4].iota.universal.unsqueeze!(-1) == [3, 4, 1].iota);

See Also

Meta