-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Use NaNMath instead of abs
#109
Comments
I can take a look at this. I'm not too familiar with the whole code base yet, but right now it seems to more or less to trace the use of the operations defined in I also wanted to ask, I just did a quick naive benchmark on julia> using NaNMath
julia> function log_nan(x)
x < 0.0 && return NaN
return log(x)
end
log_nan (generic function with 1 method)
julia> X = rand(50_000_000) .* 2 .- 1;
julia> @time NaNMath.log.(X);
0.661889 seconds (132.60 k allocations: 388.716 MiB, 0.80% gc time, 6.57% compilation time)
julia> @time NaNMath.log.(X);
0.685413 seconds (4 allocations: 381.470 MiB)
julia> @time NaNMath.log.(X);
0.614610 seconds (4 allocations: 381.470 MiB)
julia> @time log_nan.(X);
0.644774 seconds (117.23 k allocations: 387.860 MiB, 12.58% gc time, 11.42% compilation time)
julia> @time log_nan.(X);
0.543851 seconds (4 allocations: 381.470 MiB)
julia> @time log_nan.(X);
0.477451 seconds (4 allocations: 381.470 MiB, 3.61% gc time) Comparing the two best times above, |
Thanks, I appreciate the help, @johanbluecreek! Very curious result. It might be worth raising on issue on the Also, a couple points:
function log_nan(x::T)::T where {T<:Real}
x <= T(0) && return T(NaN)
return log(x)
end
Thanks again! |
Also, after defining new operators with custom names like SymbolicRegression.jl/src/Equation.jl Line 204 in 29f6bf1
|
Also, if the user passes SymbolicRegression.jl/src/Options.jl Lines 86 to 120 in 29f6bf1
|
…ts (issue MilesCranmer#109) This commit also removes the regularization terms present in the logs. This is a first step in resolving issue MilesCranmer#109.
…ad_of_math_issue_109 Use functions returning NaN on branch cuts instead of abs (issue #109)
This was completed with #123 . (Thanks again!) |
Operators should be default use NaNMath https://github.com/mlubin/NaNMath.jl, instead of my versions which simply map input to the valid domain like
log(abs(x))
. Since the evaluator already detects NaNs by default, this should work well and expressions will automatically try to avoid having improper inputs.The text was updated successfully, but these errors were encountered: