The OpenD Programming Language

reversed

Reverses the direction of iteration for selected dimensions.

  1. template reversed(Dimensions...)
  2. Slice!(Iterator, N, Universal) reversed(Slice!(Iterator, N, kind) _slice, size_t[M] dimensions)
    @trusted
    Slice!(Iterator, N, Universal)
    reversed
    (
    Iterator
    size_t N
    SliceKind kind
    size_t M
    )
    (
    Slice!(Iterator, N, kind) _slice
    ,
    size_t[M] dimensions...
    )
    if (
    M
    )
  3. auto reversed(Slice!(Iterator, N, kind) slice)

Parameters

_slice Slice!(Iterator, N, kind)

input slice

dimensions size_t[M]

indices of dimensions to reverse order of iteration

Return Value

Type: Slice!(Iterator, N, Universal)

n-dimensional slice

Examples

import mir.ndslice.topology: iota;

auto slice = iota([2, 2], 1);
assert(slice                    == [[1, 2], [3, 4]]);

// Default
assert(slice.reversed           == [[3, 4], [1, 2]]);

// Template
assert(slice.reversed! 0        == [[3, 4], [1, 2]]);
assert(slice.reversed! 1        == [[2, 1], [4, 3]]);
assert(slice.reversed!(0, 1)    == [[4, 3], [2, 1]]);
assert(slice.reversed!(1, 0)    == [[4, 3], [2, 1]]);
assert(slice.reversed!(1, 1)    == [[1, 2], [3, 4]]);
assert(slice.reversed!(0, 0, 0) == [[3, 4], [1, 2]]);

// Function
assert(slice.reversed (0)       == [[3, 4], [1, 2]]);
assert(slice.reversed (1)       == [[2, 1], [4, 3]]);
assert(slice.reversed (0, 1)    == [[4, 3], [2, 1]]);
assert(slice.reversed (1, 0)    == [[4, 3], [2, 1]]);
assert(slice.reversed (1, 1)    == [[1, 2], [3, 4]]);
assert(slice.reversed (0, 0, 0) == [[3, 4], [1, 2]]);
import mir.ndslice.topology: iota, canonical;
auto slice = iota([2, 2], 1).canonical;
assert(slice                    == [[1, 2], [3, 4]]);

// Template
assert(slice.reversed! 0        == [[3, 4], [1, 2]]);
assert(slice.reversed!(0, 0, 0) == [[3, 4], [1, 2]]);

// Function
assert(slice.reversed (0)       == [[3, 4], [1, 2]]);
assert(slice.reversed (0, 0, 0) == [[3, 4], [1, 2]]);

Meta