minmaxPos

Finds a positions (ndslices) such that position[0].first is minimal and position[1].first is maximal elements in the slice.

Position is sub-ndslice of the same dimension in the right-)down-)etc(( corner.

  1. Slice!(Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind)[2] minmaxPos(Slice!(Iterator, N, kind) slice)
    template minmaxPos(alias pred = "a < b")
    @optmath
    static if(__traits(isSame, naryFun!pred, pred))
    @optmath
    Slice!(Iterator, N,
    kind == Contiguous &&
    N > 1
    ? Canonical : kind)[2]
    minmaxPos
    (
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) slice
    )
  2. alias minmaxPos = .minmaxPos!(naryFun!pred)

Members

Aliases

minmaxPos
alias minmaxPos = .minmaxPos!(naryFun!pred)
Undocumented in source.

Functions

minmaxPos
Slice!(Iterator, N, kind == Contiguous && N > 1 ? Canonical : kind)[2] minmaxPos(Slice!(Iterator, N, kind) slice)

Parameters

pred

A predicate.

Examples

import mir.ndslice.slice: sliced;
auto s = [
    2, 6, 4, -3,
    0, -4, -3, 3,
    -3, -2, 7, 2,
    ].sliced(3, 4);

auto pos = s.minmaxPos;

assert(pos[0] == s[$ - 2 .. $, $ - 3 .. $]);
assert(pos[1] == s[$ - 1 .. $, $ - 2 .. $]);

assert(pos[0].first == -4);
assert(s.backward(pos[0].shape) == -4);
assert(pos[1].first ==  7);
assert(s.backward(pos[1].shape) ==  7);

See Also

minmaxIndex, minPos, maxPos, $(NDSLICEREF slice, Slice.backward).

Meta