Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unchecked Vector methods #50

Open
chrissimpkins opened this issue Dec 25, 2021 · 1 comment
Open

Add unchecked Vector methods #50

chrissimpkins opened this issue Dec 25, 2021 · 1 comment

Comments

@chrissimpkins
Copy link
Owner

chrissimpkins commented Dec 25, 2021

The data validity checks that were used in the default implementation (added in #49) significantly slow the calculation of a harmonic mean with f32 and f64 data (Criterion benchmarks added in the same PR).

Consider adding an unchecked version that is more performant and assumes data validation by the user. Perhaps under an optional feature and not part of the default crate distribution. Panics will occur with zero values. Use of values < 0.0 will not panic, but return f32 or f64 values that are not valid geometric means.

A refactor to:

let sum_of_reciprocal = self.components.iter().copied().map(|x| x.powi(-1)).sum::<T>();

in place of the #49 approach improves execution time from:

Vector mean_harmonic method: f64 5D Vector
                        time:   [4.6057 ns 4.6161 ns 4.6294 ns]
                        change: [+0.0120% +0.2572% +0.5116%] (p = 0.04 < 0.05)
                        Change within noise threshold.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high severe

to:

Vector mean_harmonic method: f64 5D Vector
                        time:   [542.75 ps 543.07 ps 543.48 ps]
                        change: [-88.222% -88.193% -88.164%] (p = 0.00 < 0.05)
                        Performance has improved.
Found 11 outliers among 100 measurements (11.00%)
  3 (3.00%) high mild
  8 (8.00%) high severe

The f32 benchmark changes are comparable.

Test environment:

MBP 16" 2021
Apple M1 Max
32GB RAM
macOS 12.1

related #44
related #8

@chrissimpkins chrissimpkins changed the title Add unchecked Vector mean_harmonic method Add unchecked Vector methods Dec 29, 2021
@chrissimpkins
Copy link
Owner Author

This likely applies to methods other than mean_harmonic. I generalized the title and will look into this. Perhaps under an optional feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant