Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override Base.sum! #368

Merged
merged 2 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside from this for-loop, I suggest to add a method for sum! with the signaturesum!(v::TaylorN{S}, a::AbstractArray{HomogeneousPolynomial{S}}), which is used in some evaluate and/or related functions.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the suggestion! I've added the corresponding method, although I don't know which method of evaluate will benefit the most from it.

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
Loading