minIndex

Finds an index such that slice[index] is minimal(maximal).

  1. size_t[N] minIndex(Slice!(Iterator, N, kind) slice)
    template minIndex(alias pred = "a < b")
    @optmath
    static if(__traits(isSame, naryFun!pred, pred))
    @optmath
    size_t[N]
    minIndex
    (
    Iterator
    size_t N
    SliceKind kind
    )
    (
    Slice!(Iterator, N, kind) slice
    )
  2. alias minIndex = .minIndex!(naryFun!pred)

Members

Aliases

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

Functions

minIndex
size_t[N] minIndex(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, 8,
    ].sliced(3, 4);

auto index = s.minIndex;

assert(index == [1, 1]);
assert(s[index] == -4);

index = s.maxIndex;

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

auto index = s.minIndex;

assert(index == [0, 0]);
assert(s[index] == -8);

See Also

Meta