use Base.sum instead of handrolled sum with poorly initialized accumulator#592
Merged
ararslan merged 3 commits intoJuliaStats:masterfrom Apr 13, 2017
Merged
use Base.sum instead of handrolled sum with poorly initialized accumulator#592ararslan merged 3 commits intoJuliaStats:masterfrom
ararslan merged 3 commits intoJuliaStats:masterfrom
Conversation
Member
|
It would be great if you could just remove the |
andreasnoack
approved these changes
Apr 13, 2017
ararslan
reviewed
Apr 16, 2017
| throw(DimensionMismatch("Inconsistent array dimensions.")) | ||
| _loglikelihood(d, X) | ||
| size(X, 1) == length(d) || throw(DimensionMismatch("Inconsistent array dimensions.")) | ||
| return sum(x -> _logpdf(d, x), X, 2) |
Member
There was a problem hiding this comment.
The problem with this is that x is a scalar, but _logpdf wants x to be an array. I guess that's why it was using a custom sum here, so it could take slices rather than individual elements. Ref JuliaLang/METADATA.jl#8848 (comment)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This results in better type stability in cases where the reduction output is not a
Float64. I found this while messing about with the code in this Discourse post and a branch of ForwardDiff which adds stack-allocated, low-dimensional gradients.Note that I found a bunch of places with the same problem throughout the codebase - all of these spots will likely kill performance with non-
Float64number types likeDual.Setup:
Before this PR:
After this PR: