The OpenD Programming Language

squeeze

Constructs a new view of an n-dimensional slice with dimension axis removed.

template squeeze(sizediff_t axis = 0)
Slice!(Iterator, N - 1, kind != Canonical ? kind : ((
axis == N - 1 ||
axis == -1
)
? Universal : (N == 2 ? Contiguous : kind)
)
)
squeeze
(
Iterator
size_t N
SliceKind kind
)
(
Slice!(Iterator, N, kind) slice
)
if (
-sizediff_t(N) <= axis &&
axis < sizediff_t(N)
&&
N > 1
)

Parameters

axis

dimension to remove, if it is single-dimensional

slice

n-dimensional slice

Return Value

new view of a slice with dimension removed

Throws

AssertError if the length of the corresponding dimension doesn' equal 1.

Examples

import mir.ndslice.topology : iota;
import mir.ndslice.allocation : slice;

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

assert([1, 3].iota.canonical.squeeze == [3].iota);
assert([3, 1].iota.canonical.squeeze!1 == [3].iota);
assert([3, 1].iota.canonical.squeeze!(-1) == [3].iota);

assert([1, 3].iota.universal.squeeze == [3].iota);
assert([3, 1].iota.universal.squeeze!1 == [3].iota);
assert([3, 1].iota.universal.squeeze!(-1) == [3].iota);

assert([1, 3, 4].iota.squeeze == [3, 4].iota);
assert([3, 1, 4].iota.squeeze!1 == [3, 4].iota);
assert([3, 4, 1].iota.squeeze!(-1) == [3, 4].iota);

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

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

See Also

Meta