input slice
weights slice of the same length as xs
a minimum number of bins for the output array
slice like weights of weighted number of ocurrences TODO: support @nogc
import numir : bincount; import mir.ndslice : sliced, iota, fuse; auto ys = [0, 1, 1, 0, 1].sliced!size_t; assert(ys.bincount == [2, 3]); assert(ys.bincount(iota(ys.length)) == [0+3, 1+2+4]); assert(ys.bincount([[1, 0], [-1, 0], [-1, 0], [1, 0], [-1, 0]].fuse) == [[2, 0], [-3,0]]); assert([].sliced!size_t.bincount == [].sliced!size_t); assert([].sliced!size_t.bincount([].sliced!double) == [].sliced!double);
Count weighted number of occurrences of each value in slice of non-negative ints. Note that empty weight causes compiler error.