Skip to content

Commit

Permalink
Allow init argument for sum
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Oct 10, 2024
1 parent 93c7e3b commit a548208
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

abstract type AbstractMutable end

function Base.sum(a::AbstractArray{<:AbstractMutable})
return operate(sum, a)
function Base.sum(a::AbstractArray{<:AbstractMutable}; kws...)
return operate(sum, a; kws...)
end

# When doing `x'y` where the elements of `x` and/or `y` are arrays, redirecting
Expand Down
13 changes: 6 additions & 7 deletions src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ function fused_map_reduce(op::F, args::Vararg{Any,N}) where {F<:Function,N}
return accumulator
end

function operate(::typeof(sum), a::AbstractArray)
return mapreduce(
identity,
add!!,
a;
init = zero(promote_operation(+, eltype(a), eltype(a))),
)
function operate(
::typeof(sum),
a::AbstractArray;
init = zero(promote_operation(+, eltype(a), eltype(a))),
)
return mapreduce(identity, add!!, a; init)
end

0 comments on commit a548208

Please sign in to comment.