-
Notifications
You must be signed in to change notification settings - Fork 116
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
test: update codegen tests #692
test: update codegen tests #692
Conversation
ba863c5
to
da3bd6d
Compare
test/code.jl
Outdated
|
||
@test toexpr(a^-2) == :($(/)(1, $(^)(a, 2))) | ||
@test toexpr(a^-2, nanmath_st) == :($(/)(1, $(NaNMath.pow)(a, 2))) | ||
@test toexpr(NaNMath.pow(a, -2)) == :($(NaNMath.pow)(a, -2)) | ||
@test toexpr(NaNMath.pow(a, -2), nanmath_st) == :($(NaNMath.pow)(a, -2)) | ||
@test toexpr(NaNMath.pow(a, -2)) == :($(NaNMath.pow)($(inv)(a), 2)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NaNMath.pow(a, -2)
turns into a ^ (-2)
. Codegen adds the NaNMath.pow
back in https://github.com/JuliaSymbolics/SymbolicUtils.jl/blob/master/src/code.jl#L141.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll make it not do that if the exponent is an integer
src/code.jl
Outdated
@@ -146,11 +146,13 @@ function function_to_expr(op::typeof(^), O, st) | |||
return toexpr(Term(inv, Any[ex]), st) | |||
else | |||
args = Any[Term(inv, Any[ex]), -args[2]] | |||
op = get(st.rewrites, :nanmath, false) ? op : NaNMath.pow | |||
op = get(st.rewrites, :nanmath, false) || args[2] isa Integer ? op : NaNMath.pow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this at all, see #689? In any case, the existing check is wrong and should be
op = get(st.rewrites, :nanmath, false) || args[2] isa Integer ? op : NaNMath.pow | |
op = get(st.rewrites, :nanmath, false) === true && !(args[2] isa Integer) ? NaNMath.pow : op |
src/code.jl
Outdated
return toexpr(Term(op, args), st) | ||
end | ||
end | ||
get(st.rewrites, :nanmath, false) === true || return nothing | ||
if !get(st.rewrites, :nanmath, false) || args[2] isa Integer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit safer:
if !get(st.rewrites, :nanmath, false) || args[2] isa Integer | |
if get(st.rewrites, :nanmath, false) !== true || args[2] isa Integer |
Additionally, I guess it would be more efficient to move this to the beginning of the function body?
5f43d01
to
194aa85
Compare
No description provided.