Skip to content

Commit

Permalink
Add missing methods for add! and subst! (#117)
Browse files Browse the repository at this point in the history
* Add missing in-place methods for unary +,-

* Add tests for new add!, subst! methods
  • Loading branch information
PerezHz authored and lbenet committed Aug 26, 2017
1 parent f97223f commit 840b042
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!)))
@inbounds v[k+1] = ($f)(a[k+1])
return nothing
end
function ($fc)(v::$T, a::NumberNotSeries, k::Int)
@inbounds v[k+1] = k==0 ? ($f)(a) : zero(v[k+1])
return nothing
end
function ($fc)(v::$T, a::$T, b::$T, k::Int)
@inbounds v[k+1] = ($f)(a[k+1], b[k+1])
return nothing
Expand Down
8 changes: 8 additions & 0 deletions test/manyvariables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,16 @@ using Base.Test
xx = 1.0*zeroT
TaylorSeries.add!(xx, 1.0*xT, 2yT, 1)
@test xx[2] == HomogeneousPolynomial([1,2])
TaylorSeries.add!(xx, 5.0, 0)
@test xx[1] == HomogeneousPolynomial([5.0])
TaylorSeries.add!(xx, -5.0, 1)
@test xx[2] == zero(xx[2])
TaylorSeries.subst!(xx, 1.0*xT, yT, 1)
@test xx[2] == HomogeneousPolynomial([1,-1])
TaylorSeries.subst!(xx, 5.0, 0)
@test xx[1] == HomogeneousPolynomial([-5.0])
TaylorSeries.subst!(xx, -5.0, 1)
@test xx[2] == zero(xx[2])
TaylorSeries.div!(xx, 1.0+xT, 1.0+xT, 0)
@test xx[1] == 1.0
TaylorSeries.pow!(xx, 1.0+xT, 1.5, 0)
Expand Down
8 changes: 8 additions & 0 deletions test/onevariable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,16 @@ using Base.Test
tt = zero(ut)
TaylorSeries.add!(tt, ut, ut, 1)
@test tt[2] == 2.0
TaylorSeries.add!(tt, -3.0, 0)
@test tt[1] == -3.0
TaylorSeries.add!(tt, -3.0, 1)
@test tt[2] == 0.0
TaylorSeries.subst!(tt, ut, ut, 1)
@test tt[2] == 0.0
TaylorSeries.subst!(tt, -3.0, 0)
@test tt[1] == 3.0
TaylorSeries.subst!(tt, -2.5, 1)
@test tt[2] == 0.0
iind, cind = TaylorSeries.divfactorization(ut, ut)
@test iind == 1
@test cind == 1.0
Expand Down

0 comments on commit 840b042

Please sign in to comment.