scalanlp / breeze

Breeze is/was a numerical processing library for Scala.
https://www.scalanlp.org
Apache License 2.0
3.45k stars 692 forks source link

Factor out DescriptiveStats.percentileInPlace #721

Closed jklukas closed 5 years ago

jklukas commented 6 years ago

The percentile function always copies and sorts the input data, which provides good safety for the general case. This is inefficient, however, in cases where data already happens to be sorted or where the user wants to calculate a series of percentiles on a single dataset.

We factor out the sorting step and the percentile calculation step here and make a public percentileInPlace function that takes in a pre-sorted array so that users can opt in to the responsibility of array creation and sorting on their own.

Note that I'm relatively new to scala breeze, so very open to feeback on naming, documentation conventions, etc. If this simply doesn't fit in with the overall API you want to present to users, that's a perfectly fine outcome as well. Thanks for your work on this library!

dlwh commented 5 years ago

thank you for doing this. sorry for being slow

jklukas commented 5 years ago

Thanks, @dlwh!