Skip to content

@safe ndslice; shortcuts; topology.pairwise instead of isSorted and isStrictlyMonotonic

Compare
Choose a tag to compare
@9il 9il released this 13 May 07:58
· 1269 commits to master since this release

Slice is safe now

User-defined iterators must care about their safety except bounds checks.
Bounds are checked in ndslice code.

Deprecations

  • tuple was renamed to refTuple
  • isSorted and isStrictlyMonotonic are deprecated. Use pairwise and all instead.

[float.nan, 1].isSorted is true both for Mir and Phobos, but it must be false.
*.pairwise!"a <= b".all solves this issue explicitly.

import mir.ndslice.algorithm: all;
import mir.ndslice.slice;
import mir.ndslice.sorting: sort;
import mir.ndslice.topology: pairwise;

auto arr = [1, 1, 2].sliced;

assert(arr.pairwise!"a <= b".all);
assert(!arr.pairwise!"a < b".all);

arr = [4, 3, 2, 1].sliced;

assert(!arr.pairwise!"a <= b".all);
assert(!arr.pairwise!"a < b".all);

sort(arr);

assert(arr.pairwise!"a <= b".all);
assert(arr.pairwise!"a < b".all);

New API

  • pairwise - pairwise map for vectors. It is shortcut for topology.slide.
  • Slice.field - returns underlying array for contiguous ndslices
  • Definition shortcuts for Slice
    • UniversalVector
    • ContiguousMatrix
    • CanonicalMatrix
    • UniversalMatrix
    • ContiguousTensor
    • CanonicalTensor
    • UniversalTensor