-
Notifications
You must be signed in to change notification settings - Fork 22
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
logstatsexp #77
base: master
Are you sure you want to change the base?
logstatsexp #77
Conversation
These functions are usually useful for me, thought it'd be nice to have them here. Not sure why CI is failing on Julia 1.0 ? |
function logmeanexp(A::AbstractArray; dims=:) | ||
R = logsumexp(A; dims) | ||
N = length(A) ÷ length(R) | ||
return R .- log(N) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will cause undesired promotions and allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems you adressed my comment about promotions but not the allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@devmotion you might argue that unless there's a way to modify logsumexp
to directly take log(N)
into account, an in-place operation might create issues with AD systems which do not support it?
R = logsumexp(2logsubexp.(A, logmean); dims) | ||
N = length(A) ÷ length(R) | ||
if corrected | ||
return R .- log(N - 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again this causes undesired promotions and allocations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I think it's better now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The unnecessary allocations are still present.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I'm not sure what you are referring to?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
R .- log(N - 1)
creates a new array. But if R
is e.g. of type Array
this causes unnecessary allocations.
I don't have an strong opinion on this, but Is it possible to implement this as an extension? This package is a really low level one, and adding a new dependency could have effects on downstream packages? |
@longemen3000 The PR is not introducing any dependencies. |
|
Ohhh, nvm, my error, in that case, no comment at all |
@longemen3000 Yes but |
CI passing now. @devmotion I agree the implementation is not optimal but I don't have time to tune it now. Could we merge as it is now? |
I think we can merge now and work on optimization later. Honestly, it's just a huge pain trying to optimize for allocations without having Transducers.jl, laziness, or good functional primitives in Julia. |
@ParadaCarleton as far as I know you've never contributed to this package, so I really think that you should let the maintainers of this package decide when a PR is ready and can be merged. In my opinion, being a member of JuliaStats doesn't mean that you are able and should merge PRs in repos that you haven't contributed to and/or are not familiar with. For instance, there are many JuliaStats packages where I don't think it's appropriate for me to merge PRs. |
Clearly, we should not over-optimize this PR. But at the same time we should hold off merging PRs if reviewer comments that can be addressed without too much effort are not resolved. For instance, I think currently the following things are missing in this PR:
|
Adds the functions logmeanexp, logvarexp, logstdexp