Precalculate float consts for RecursiveGaussian at build time #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
RecursiveGaussian::new
does calculations that are always based on the same constant values defined at compile-time. My first thought was to just inline these, but that would make maintaining the algorithm a lot more difficult.This PR adds a simple build script that does the same as
RecursiveGaussian::new
and writes the resulting values to const variables:The
RecursiveGaussian
can then use these consts instead ofself.asdf
in the blur algorithm.I understand that there is a reason that float calculations are not
const
in Rust (even though integer calculations are), but by my testing, even platforms without FMA produce the exact same variable values. Maybe more testing is needed on ARM and maybe Windows platforms (due to their x87 FPU shenanigans that might apply here). But I think that even if there are inconsistencies, they're probably smaller than the inaccuracies the algorithm itself would produce at runtime anyways.I have no clue why I never tested this before. The results are staggering for the amount of effort needed:
This also reduces the resulting library size (very roughly 20%), mostly because of nalgebra being removed from runtime.