Skip to content

Commit cde9b6f

Browse files
committed
save 1 alloc
1 parent c2d3afd commit cde9b6f

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/mathfuns.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,8 @@ for (meth, libnm, modu) in [
102102
end
103103

104104
function abs2!(a::Basic, x::Basic)
105-
TWO = Basic(2) # put in init
106-
a = abs!(a, x)
107-
a = pow!(a, x, TWO)
105+
abs!(a, x)
106+
mul!(a, a, a)
108107
a
109108
end
110109
function Base.abs2(x::Basic)

test/runtests.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -355,12 +355,12 @@ end
355355
@test deserialized == data
356356
end
357357

358-
@vars a x y
358+
@vars x y
359+
a = Basic()
359360
@testset "non-allocating(ish) methods" begin
360-
SymEngine.sin!(a,x); SymEngine.cos!(a,x); SymEngine.abs!(a,x)
361-
SymEngine.pow!(a,x,x);
362-
SymEngine.add!(a,x,x);SymEngine.mul!(a,x,x)
363-
SymEngine.sub!(a,x,x);SymEngine.div!(a,x,x)
361+
sin(x), cos(x), abs(x)
362+
x^x, x + x, x*x, x-x, x/x # warm up
363+
364364
@test (@allocations SymEngine.sin!(a,x)) == 0
365365
@test (@allocations SymEngine.cos!(a,x)) == 0
366366
@test (@allocations SymEngine.pow!(a,x,x)) == 0

0 commit comments

Comments
 (0)