Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions test/code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,18 @@ nanmath_st.rewrites[:nanmath] = true

@test toexpr(a^2) == :($(^)(a, 2))
@test toexpr(a^2, nanmath_st) == :($(NaNMath.pow)(a, 2))
@test toexpr(NaNMath.pow(a, 2)) == :($(NaNMath.pow)(a, 2))
@test toexpr(NaNMath.pow(a, 2)) == :($(^)(a, 2))
@test toexpr(NaNMath.pow(a, 2), nanmath_st) == :($(NaNMath.pow)(a, 2))

@test toexpr(a^-1) == :($(/)(1, a))
@test toexpr(a^-1, nanmath_st) == :($(/)(1, a))
@test toexpr(NaNMath.pow(a, -1)) == :($(NaNMath.pow)(a, -1))
@test toexpr(NaNMath.pow(a, -1), nanmath_st) == :($(NaNMath.pow)(a, -1))
@test toexpr(NaNMath.pow(a, -1)) == :($(inv)(a))
@test toexpr(NaNMath.pow(a, -1), nanmath_st) == :($(inv)(a))

@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))
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member Author

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

@test toexpr(NaNMath.pow(a, -2), nanmath_st) == :($(NaNMath.pow)($(inv)(a), 2))

f = GlobalRef(NaNMath, :sin)
test_repr(toexpr(LiteralExpr(:(let x=1, y=2
Expand Down
Loading