Skip to content

Commit

Permalink
Override Base.sum! (#368)
Browse files Browse the repository at this point in the history
* Override Base.sum!

* Suggestion by @lbenet
  • Loading branch information
LuEdRaMo authored Aug 22, 2024
1 parent d9ca589 commit ae47f13
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/TaylorSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import Base: iterate, size, eachindex, firstindex, lastindex,
eltype, length, getindex, setindex!, axes, copyto!

import Base: zero, one, zeros, ones, isinf, isnan, iszero, isless,
convert, promote_rule, promote, show,
convert, promote_rule, promote, show, sum!,
real, imag, conj, adjoint,
rem, mod, mod2pi, abs, abs2,
sqrt, exp, expm1, log, log1p,
Expand Down
21 changes: 21 additions & 0 deletions src/arithmetic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,27 @@ for (f, fc) in ((:+, :(add!)), (:-, :(subst!)))
end
end

for T in (:Taylor1, :TaylorN)
@eval begin
function sum!(v::$T{S}, a::AbstractArray{$T{S}}) where {S <: Number}
for i in eachindex(a)
for k in eachindex(v)
add!(v, v, a[i], k)
end
end
return nothing
end
end
end

function sum!(v::TaylorN{S}, a::AbstractArray{HomogeneousPolynomial{S}}) where {S <: Number}
for i in eachindex(a)
for k in eachindex(v)
add!(v, v, a[i], k)
end
end
return nothing
end

## Multiplication ##
for T in (:Taylor1, :HomogeneousPolynomial, :TaylorN)
Expand Down

0 comments on commit ae47f13

Please sign in to comment.