"Statistics with Rust" book ch. 3 issues
dxps opened this issue · comments
Continuing to capture the issues (and potential fixes, as in this case) as I previously started in #1 , in chapter 3 of the book I got into the following issue(s):
- In Calculate Measure of Central Tendency section,
sort_unstable()
cannot be performed on an array off64
.- This is a known behavior.
- The workaround is to use
data.sort_unstable_by(|a, b| a.partial_cmp(b).unwrap());
- The
mode(data: &[f64])
implementation cannot compile since you cannot use anf64
as a key of aHashMap
.- I used
ordered_float
crate and this implementation:pub fn mode(data: &[f64]) -> Option<f64> { let mut frequency_map = HashMap::<OrderedFloat<f64>, i32>::new(); for &value in data { let count = frequency_map.entry(OrderedFloat(value)).or_insert(0); *count += 1; } frequency_map .into_iter() .max_by_key(|&(_, count)| count) .map(|(value, _)| value.0) }
- I used
Hi.
Thank you for letting us know. We have forwarded the highlighted errata to
the author and shall be updated accordingly.
Will keep you posted with the progress.
Thanks & Regards
GitforGits
…On Thu, 13 Jul 2023, 19:09 Marius Ileana, ***@***.***> wrote:
Continuing to capture the issues (and potential fixes, as in this case) as
I previously started in #1
<#1> , in chapter
3 of the book I got into the following issue(s):
1. In *Calculate Measure of Central Tendency* section, sort_unstable()
cannot be performed on an array of f64.
- This is a known behavior.
- The workaround is to use data.sort_unstable_by(|a, b|
a.partial_cmp(b).unwrap());
—
Reply to this email directly, view it on GitHub
<#2>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/A5L7XPRU2ARGQILN4TVHIMDXP73CVANCNFSM6AAAAAA2I64B3A>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>