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

Sampling with WeightVec and Float32 #158

Closed
tomblaze opened this issue May 4, 2016 · 1 comment · Fixed by #499
Closed

Sampling with WeightVec and Float32 #158

tomblaze opened this issue May 4, 2016 · 1 comment · Fixed by #499

Comments

@tomblaze
Copy link

tomblaze commented May 4, 2016

I encountered a bug when wanting to sample from weight vec of single-precision floats. Below is a minimal working example.

prob_32 = rand(Float32, 1000);
prob_64 = rand(Float64, 1000);
sample(1:1000, WeightVec(prob_64), 31);
sample(1:1000, WeightVec(prob_32), 31);  #both work
sample(1:1000, WeightVec(prob_64), 32); #this works
sample(1:1000, WeightVec(prob_32), 32); #this throws error

ERROR: MethodError: `make_alias_table!` has no method matching make_alias_table!(::Array{Float32,1}, ::Float32, ::Array{Float64,1}, ::Array{Int64,1})
Closest candidates are:
  make_alias_table!(::AbstractArray{Float64,1}, ::Float64, ::AbstractArray{Float64,1}, ::AbstractArray{Int64,1})
 in alias_sample! at /HOME/.julia/v0.4/StatsBase/src/sampling.jl:424
 in sample! at /HOME/.julia/v0.4/StatsBase/src/sampling.jl:515

I can get around this problem by sampling one item at a time, but seems like a bug to fix.

@andreasnoack
Copy link
Member

Historically, the functions in StatsBase and Distributions have mainly been defined for Float64. We are in a process of making the methods more generic with respect to element type but there is still much work to do. A PR to handle this would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants