Fixed partition function for numElems < numSamples.

Still weirdly broken for numElems > numSamples.