reduce implementation fix for sparse arrays
