import mir.ndslice : map, alongDim, byDim, iota, slice, sliced; // sorted cases assert(iota(5).median == 2); // [[0,1], // [2,3], // [4,5]] assert(iota(3, 2).byDim!1.map!median == [2, 3]); assert(iota(3, 2).byDim!0.map!median == [0.5, 2.5, 4.5]); assert(iota(3, 2).alongDim!0.map!median == [2, 3]); assert(iota(3, 2).alongDim!1.map!median == [0.5, 2.5, 4.5]); // not sorted cases auto x = [1, 5, 1, 3, 4].sliced; assert(x.median == 3); auto y = [1, 5, 1, 3, 4, 4].sliced; assert(y.median == 3.5); auto z = [1, 5, 1, 2, 4, 2, 1, 5, 1, 2, 4, 3, 1, 5, 1, 3, 4, 3].sliced(3, 6); assert(z.byDim!1.map!median == [1, 5, 1, 2, 4, 3]); assert(z.byDim!0.map!median.slice == [2.0, 2.5, 3.0]); // FIXME remove .slice here assert(z.alongDim!0.map!median == [1, 5, 1, 2, 4, 3]); assert(z.alongDim!1.map!median == [2.0, 2.5, 3.0]);