Use nnz to implement sum over bool arrays

This minor change results in about 1.5x - 2x speedup and smaller memory footprint.