Skip to content

Commit cecc0ca

Browse files
Merge pull request #692 from AayushSabharwal/as/fix-tests
test: update codegen tests
2 parents bf23a1d + f5611aa commit cecc0ca

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/code.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,18 +140,18 @@ end
140140

141141
function function_to_expr(op::typeof(^), O, st)
142142
args = arguments(O)
143-
if length(args) == 2 && args[2] isa Real && args[2] < 0
144-
ex = args[1]
145-
if args[2] == -1
146-
return toexpr(Term(inv, Any[ex]), st)
147-
else
148-
args = Any[Term(inv, Any[ex]), -args[2]]
149-
op = get(st.rewrites, :nanmath, false) ? op : NaNMath.pow
150-
return toexpr(Term(op, args), st)
151-
end
143+
if args[2] isa Real && args[2] < 0
144+
args[1] = Term(inv, Any[args[1]])
145+
args[2] = -args[2]
146+
end
147+
if isequal(args[2], 1)
148+
return toexpr(args[1], st)
149+
end
150+
if get(st.rewrites, :nanmath, false) === true && !(args[2] isa Integer)
151+
op = NaNMath.pow
152+
return toexpr(Term(op, args), st)
152153
end
153-
get(st.rewrites, :nanmath, false) === true || return nothing
154-
return toexpr(Term(NaNMath.pow, args), st)
154+
return nothing
155155
end
156156

157157
function function_to_expr(::typeof(SymbolicUtils.ifelse), O, st)

test/code.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,19 @@ nanmath_st.rewrites[:nanmath] = true
100100
@test toexpr(NaNMath.pow(a, b), nanmath_st) == :($(NaNMath.pow)(a, b))
101101

102102
@test toexpr(a^2) == :($(^)(a, 2))
103-
@test toexpr(a^2, nanmath_st) == :($(NaNMath.pow)(a, 2))
104-
@test toexpr(NaNMath.pow(a, 2)) == :($(NaNMath.pow)(a, 2))
105-
@test toexpr(NaNMath.pow(a, 2), nanmath_st) == :($(NaNMath.pow)(a, 2))
103+
@test toexpr(a^2, nanmath_st) == :($(^)(a, 2))
104+
@test toexpr(NaNMath.pow(a, 2)) == :($(^)(a, 2))
105+
@test toexpr(NaNMath.pow(a, 2), nanmath_st) == :($(^)(a, 2))
106106

107107
@test toexpr(a^-1) == :($(/)(1, a))
108108
@test toexpr(a^-1, nanmath_st) == :($(/)(1, a))
109-
@test toexpr(NaNMath.pow(a, -1)) == :($(NaNMath.pow)(a, -1))
110-
@test toexpr(NaNMath.pow(a, -1), nanmath_st) == :($(NaNMath.pow)(a, -1))
109+
@test toexpr(NaNMath.pow(a, -1)) == :($(inv)(a))
110+
@test toexpr(NaNMath.pow(a, -1), nanmath_st) == :($(inv)(a))
111111

112112
@test toexpr(a^-2) == :($(/)(1, $(^)(a, 2)))
113-
@test toexpr(a^-2, nanmath_st) == :($(/)(1, $(NaNMath.pow)(a, 2)))
114-
@test toexpr(NaNMath.pow(a, -2)) == :($(NaNMath.pow)(a, -2))
115-
@test toexpr(NaNMath.pow(a, -2), nanmath_st) == :($(NaNMath.pow)(a, -2))
113+
@test toexpr(a^-2, nanmath_st) == :($(/)(1, $(^)(a, 2)))
114+
@test toexpr(NaNMath.pow(a, -2)) == :($(^)($(inv)(a), 2))
115+
@test toexpr(NaNMath.pow(a, -2), nanmath_st) == :($(^)($(inv)(a), 2))
116116

117117
f = GlobalRef(NaNMath, :sin)
118118
test_repr(toexpr(LiteralExpr(:(let x=1, y=2

0 commit comments

Comments
 (0)