From ae47f132172157372afac86901e103fdf707a7c4 Mon Sep 17 00:00:00 2001 From: LuEdRaMo <73906617+LuEdRaMo@users.noreply.github.com> Date: Thu, 22 Aug 2024 09:09:47 -0600 Subject: [PATCH] Override Base.sum! (#368) * Override Base.sum! * Suggestion by @lbenet --- src/TaylorSeries.jl | 2 +- src/arithmetic.jl | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/TaylorSeries.jl b/src/TaylorSeries.jl index 8df08885..d8e446a5 100644 --- a/src/TaylorSeries.jl +++ b/src/TaylorSeries.jl @@ -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, diff --git a/src/arithmetic.jl b/src/arithmetic.jl index e44a856a..d822d7c4 100644 --- a/src/arithmetic.jl +++ b/src/arithmetic.jl @@ -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)