3 ms·
If you want to go the newtype + Sum impl route, you don't have to make it `#[repr(transparent)]` or transmute the slice. You can just `impl Sum<FastFloat> for f
by Arnavion 4y ago
If you want to go the newtype + Sum impl route, you don't have to make it `#[repr(transparent)]` or transmute the slice. You can just `impl Sum<FastFloat> for f32` and do `f.iter().copied().map(FastFloat).sum()`
https://rust.godbolt.org/z/b9s3dna6r https://rust.godbolt.org/z/b9s3dna6r
- tialaramex 4y agoOh, I didn't think of that, clever. EtA: The attraction of a New Type plus trait impl is that is re-usable. You could imagine (particularly if it was stable which your approach isn't yet) packaging up several speed-ups like this in a crate, enabling people to get faster arithmetic where they can afford any accuracy trade off without them needing to know anything about SIMD and without (like the C or C++ compiler flags) affecting unrelated code where accuracy may be critical.
- Arnavion 4y agohttps://crates.io/crates/fast-floats https://crates.io/crates/fast-floats
- tialaramex 4y agoNice, although I notice it doesn't implement Sum or Product :D