Skip to content

Commit

Permalink
WIP: proof of concept: avoid allocations in inplace methods
Browse files Browse the repository at this point in the history
  • Loading branch information
PerezHz committed Jan 31, 2024
1 parent f5587a7 commit d8989a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ end
ones(::Type{HomogeneousPolynomial{T}}, order::Int) where {T<:Number} =
ones( HomogeneousPolynomial([one(T)], 0), order)

function zero!(a::Taylor1{T}) where {T<:NumberNotSeries}
a.coeffs .= zero.(a.coeffs)
return nothing
end

function zero!(a::HomogeneousPolynomial{T}) where {T<:NumberNotSeries}
a.coeffs .= zero.(a.coeffs)
return nothing
end

function zero!(a::TaylorN{T}) where {T<:NumberNotSeries}
for i in 0:a.order
zero!(a[i])
end
return nothing
end

function zero!(a::Taylor1{TaylorN{T}}) where {T<:NumberNotSeries}
for i in 0:a.order
zero!(a[i])
end
return nothing
end



## Addition and subtraction ##
Expand Down Expand Up @@ -479,10 +503,12 @@ for T in (:Taylor1, :TaylorN)
end
end

########

function mul!(res::Taylor1{TaylorN{T}}, a::Taylor1{TaylorN{T}}, b::Taylor1{TaylorN{T}},
ordT::Int) where {T<:NumberNotSeries}
# Sanity
zero!(res, a, ordT)
zero!(res[ordT])
for k in 0:ordT
@inbounds for ordQ in eachindex(a[ordT])
mul!(res[ordT], a[k], b[ordT-k], ordQ)
Expand Down
4 changes: 4 additions & 0 deletions test/mutatingfuncts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,8 @@ using Test
TS.abs2!(res, t1, 2)
@test res[2] == 1.0

t2 = Taylor1(Int,15)
TaylorSeries.zero!(t2)
@test TaylorSeries.iszero(t2)

end

0 comments on commit d8989a7

Please sign in to comment.