LogExpFunctions.jl icon indicating copy to clipboard operation
LogExpFunctions.jl copied to clipboard

`logsumexp(f, x)` (and `logsumexp!(f, out, x)`)

Open theogf opened this issue 3 years ago • 1 comments

How about having a version that takes a function to avoid allocation when doing logsumexp(f.(x)) ? Would you be open to a PR?

theogf avatar Jul 14 '22 09:07 theogf

Would it be just

logsumexp(f, x) = logsumexp(f(xi) for xi in x)

? Or maybe

logsumexp(f, x; dims=:) = logsumexp(Broadcast.instantiate(Broadcast.broadcasted(f, x)); dims=dims)
  • changing ::AbstractArray to ::Base.AbstractArrayOrBroadcasted?

In any case, I think it could be convenient even though at least the first alternative already works. So I guess a PR would be great 🙂

devmotion avatar Jul 14 '22 17:07 devmotion