-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Closed
Labels
regressionRegression in behavior compared to a previous versionRegression in behavior compared to a previous versionsystem:32-bitAffects only 32-bit systemsAffects only 32-bit systems
Milestone
Description
In Julia 0.6.3, StatsBase.wmedian
gives incorrect results on 32-bit. In the simplified function below, the result is 8.5
on 0.6.2 and 0.7.0-alpha, but 10.0
on 0.6.3. Everything is OK on 64-bit.
FWIW, the bug goes away just by adding @show
statements.
function wmedian(v::AbstractVector{<:Real}, wt::AbstractVector{<:Real})
midpoint = sum(wt)/2
maxval, maxind = findmax(wt)
if maxval > midpoint
v[maxind]
else
permute = sortperm(v)
cumulative_weight = zero(eltype(wt))
i = 0
for (_i, p) in enumerate(permute)
i = _i
if cumulative_weight == midpoint
i += 1
break
elseif cumulative_weight > midpoint
cumulative_weight -= wt[p]
break
end
cumulative_weight += wt[p]
end
if cumulative_weight == midpoint
middle(v[permute[i-2]], v[permute[i-1]])
else
middle(v[permute[i-1]])
end
end
end
julia> wmedian([1, 2, 4, 7, 10, 15], [1/3, 1/3, 1/3, 1, 1, 1])
10.0
Metadata
Metadata
Assignees
Labels
regressionRegression in behavior compared to a previous versionRegression in behavior compared to a previous versionsystem:32-bitAffects only 32-bit systemsAffects only 32-bit systems