Skip to content

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

@oxinabox

Description

@oxinabox
Contributor

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.

Activity

palday

palday commented on Apr 23, 2021

@palday
Member

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

palday

palday commented on Apr 23, 2021

@palday
Member

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
linked a pull request that will close this issue on Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @palday@oxinabox@ParadaCarleton

      Issue actions

        std(::AbstractVector{Float32}, ::AnalyticWeights{Float32}) gives a Float64 · Issue #680 · JuliaStats/StatsBase.jl