Sort n-dimensional slice.
Sort for arrays
Sort for one-dimensional Series.
Sort for n-dimensional Series.
import mir.algorithm.iteration: all; import mir.ndslice.slice; import mir.ndslice.sorting: sort; import mir.ndslice.topology: pairwise; int[10] arr = [7,1,3,2,9,0,5,4,8,6]; auto data = arr[].sliced(arr.length); data.sort(); assert(data.pairwise!"a <= b".all);
one-dimensional series
import mir.series; auto index = [4, 2, 1, 3, 0].sliced; auto data = [5.6, 3.4, 2.1, 7.8, 0.1].sliced; auto series = index.series(data); series.sort; assert(series.index == [0, 1, 2, 3, 4]); assert(series.data == [0.1, 2.1, 3.4, 7.8, 5.6]); /// initial index and data are the same assert(index.iterator is series.index.iterator); assert(data.iterator is series.data.iterator); foreach(obs; series) { static assert(is(typeof(obs) == Observation!(int, double))); }
two-dimensional series
import mir.series; import mir.ndslice.allocation: uninitSlice; auto index = [4, 2, 3, 1].sliced; auto data = [2.1, 3.4, 5.6, 7.8, 3.9, 9.0, 4.0, 2.0].sliced(4, 2); auto series = index.series(data); series.sort( uninitSlice!size_t(series.length), // index buffer uninitSlice!double(series.length), // data buffer ); assert(series.index == [1, 2, 3, 4]); assert(series.data == [[4.0, 2.0], [5.6, 7.8], [3.9, 9.0], [2.1, 3.4]]); /// initial index and data are the same assert(index.iterator is series.index.iterator); assert(data.iterator is series.data.iterator);
Sorts ndslice, array, or series.