Suppose that I write a package in which I would like to give the user the option to use fast math inside the package, but not necessarily elsewhere. What would be the best way of accomplishing that?
The following is one possibility (for addition), but I doubt that it’s optimal. Thoughts?
if haskey( ENV, "foomath" )
import Base.FastMath.add_fast as +
else
import Base.+ as +
end
While at first glance such a switch seems like good solution, it has one major drawback: dependencies you use in your code won’t be affected by it. That is, functions like sum or various BLAS library functions (* on matrices, for example) will still use the non-fastmath versions. So unless you want to code everything yourself, this will likely result in confusing differences in performance & semantics (“fast math” makes some assumptions about the input data, like not having NaN or Inf, among others).
So, what effect would you like such a switch to have? As is, I’m not sure there is enough information here to give a meaningful answer.