Feature/generic floats - #329
Conversation
|
@bglid This is mostly done, so you can have a look already. I'll probably just add some type aliases to make syntax less cumbersome, e.g.: type FilterBase32<A> = FilterBase<A, f32>;
type FilterBase64<A> = FilterBase<A, f64>;(also have to figure out if I need to make sure that the algorithm uses the same float type as the filter base) Also want to hear your preference for the ordering of the |
|
Another thing I forgot: |
Yeah I agree, I prefer the second one too. Much more readable. Worthy tradeoff too |
Hmmm without thinking too hard on this, my gut reaction is Algorithm then Float. But, I think the second one does look maybe a bit more legible because it has the Algorithm serving as a delineator between the two floats.
Oh yeah I think this is worth doing then. Plus could be fun to do too |
|
Gave the approval cause I'll be away from my computer for most of the day. I trust that once you finish this it'll be good to merge |
|
We might not need the aliases after all. This works just fine: let lms = Lms::new(1.0_f32).unwrap();
let filter = FilterBase::new(lms, 1024).unwrap();The compiler can figure out that Also I checked and the compiler ensures that the float type for the algorithm and for the filter have to be the same. |
Oh swweet that's great |
Description
Replaces the explicit
f64s with generics that implement theFloattrait from thenum_traitscrate (or, more specifically, a supertrait that requiresnum_traits::Floatplus some other traits needed for common ops), to allow the code to be used withf32s as well.This has several advantages: Single-precision floats take up less memory, which makes them more suited to resource-constrained devices. They may also lead to increased performance, since twice as many of them can fit in the same cache line, which should, in theory, reduce the number of cache misses.
One small downside is that arithmetic operations can no longer automatically dereference floats.
For instance, previously we had:
We now have to manually dereference:
Or use a copied iterator:
I prefer the second one because it's easier to read, and floats are so small that the copies are free.