Skip to content

MethodError from sample with Float32 weights #695

@juliohm

Description

@juliohm

I think this code should work:

julia> using StatsBase

julia> sample(1:3, StatsBase.Weights(rand(Float32,3)), replace=true)
ERROR: MethodError: no method matching sample(::UnitRange{Int64}, ::Weights{Float32, Float32, Vector{Float32}}; replace=true)
Closest candidates are:
  sample(::AbstractArray, ::AbstractWeights) at /home/juliohm/.julia/packages/StatsBase/DU1bT/src/sampling.jl:561 got unsupported keyword argument "replace"
  sample(::AbstractArray, ::AbstractWeights, ::Integer; replace, ordered) at /home/juliohm/.julia/packages/StatsBase/DU1bT/src/sampling.jl:932
  sample(::AbstractArray, ::AbstractWeights, ::Tuple{Vararg{Int64, N}} where N; replace, ordered) at /home/juliohm/.julia/packages/StatsBase/DU1bT/src/sampling.jl:939

It works fine with Float64.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions