Skip to content

Commit

Permalink
Fix stack overflow on sum of large number of EinExprs
Browse files Browse the repository at this point in the history
  • Loading branch information
mofeing committed Feb 9, 2024
1 parent ef1192f commit b5df61a
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/SizedEinExpr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ parsuminds(sexpr::SizedEinExpr) = parsuminds(sexpr.path)
Base.sum!(sexpr::SizedEinExpr, inds) = sum!(sexpr.path, inds)
Base.sum(sexpr::SizedEinExpr, inds) = sum(sexpr.path, inds)

function Base.sum(sexpr::Vector{SizedEinExpr{L}}; skip = L[]) where {L}
function Base.sum(sexpr::Vector{SizedEinExpr{L}}; skip=L[]) where {L}
path = sum(map(x -> x.path, sexpr); skip)
size = @compat(allequal(Iterators.map(x -> x.size, sexpr))) ? first(sexpr).size : merge(map(x -> x.size, sexpr)...)
size = @compat(allequal(Iterators.map(x -> x.size, sexpr))) ? first(sexpr).size : mapreduce(x -> x.size, merge!, sexpr; init=Dict{L,Int}())
# size = merge(map(x -> x.size, sexpr)...)
SizedEinExpr(path, size)
end
Expand Down

0 comments on commit b5df61a

Please sign in to comment.