Skip to content
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

std(::AbstractVector{Float32}, ::AnalyticWeights{Float32}) gives a Float64 #680

Open
oxinabox opened this issue Apr 7, 2021 · 2 comments · May be fixed by #688
Open

std(::AbstractVector{Float32}, ::AnalyticWeights{Float32}) gives a Float64 #680

oxinabox opened this issue Apr 7, 2021 · 2 comments · May be fixed by #688
Labels

Comments

@oxinabox
Copy link
Contributor

oxinabox commented Apr 7, 2021

Setup:

julia> using StatsBase, Statistics

julia> xs = Float32[1, 2, 3, 4, 5];

julia> ws = AnalyticWeights(Float32[1, 1, 1, 1, 1]);

julia> eltype(ws)
Float32

Now trying some operations

julia> typeof(std(xs))  # As expected
Float32


julia> typeof(mean(xs, ws))  # as expected
Float32

julia> typeof(std(xs, ws))  # Not expected Should be a Float32
Float64

I was pretty sure this used to work to give a Float32
if so, I can't work-out when it changed.

@palday
Copy link
Member

palday commented Apr 23, 2021

The underlying problem seems to come from var, because sqrt preserves type and std is defined as sqrt.(var(...)))

@palday
Copy link
Member

palday commented Apr 23, 2021

Oh, and here's the problem:

function var(A::RealArray, w::AbstractWeights, dim::Int; mean=nothing,
                  corrected::DepBool=nothing)
    corrected = depcheck(:var, corrected)
    var!(similar(A, Float64, Base.reduced_indices(axes(A), dim)), A, w, dim;
         mean=mean, corrected=corrected)
end

@palday palday linked a pull request Apr 23, 2021 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants