JuliaStats / Distributions.jl

A Julia package for probability distributions and associated functions.
Other
1.12k stars 419 forks source link

Sampling from MvNormal fails on windows x86 #1174

Open ashryaagr opened 4 years ago

ashryaagr commented 4 years ago
mu1, sigma1 = [2., 2.],  [[5., 1.] [1., 5.]]
nv = Distributions.MvNormal(mu1, sigma1)
X = rand(nv, 5000)

gives the following error when I test it on Appveyor on windows x86. But it works perfectly with windows-x64 and Linux, macos.

  MethodError: no method matching rand(::Random._GLOBAL_RNG, ::Distributions.MvNormal{Float64,PDMats.PDMat{Float64,Array{Float64,2}},Array{Float64,1}}, ::Array{Array{Float64,1},1}, ::Bool)
  Closest candidates are:
    rand(::Random.AbstractRNG, ::Any, !Matched::Integer, ::Integer...) at D:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.5\Random\src\Random.jl:282
    rand(::Random.AbstractRNG, !Matched::Integer...) at D:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.5\Random\src\Random.jl:276
    rand(::Random.AbstractRNG, !Matched::Type{X}, !Matched::Integer, ::Integer...) where X at D:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.5\Random\src\Random.jl:291
    ...
  Stacktrace:
   [1] rand(::Random._GLOBAL_RNG, ::Distributions.MvNormal{Float64,PDMats.PDMat{Float64,Array{Float64,2}},Array{Float64,1}}, ::Tuple{Int32}) at C:\Users\appveyor\.julia\packages\Distributions\5UNuk\src\multivariates.jl:72
   [2] rand(::Distributions.MvNormal{Float64,PDMats.PDMat{Float64,Array{Float64,2}},Array{Float64,1}}, ::Tuple{Int32}) at C:\Users\appveyor\.julia\packages\Distributions\5UNuk\src\genericrand.jl:23
   [3] rand(::Distributions.MvNormal{Float64,PDMats.PDMat{Float64,Array{Float64,2}},Array{Float64,1}}, ::Int64) at D:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.5\Random\src\Random.jl:283
   [4] genGaussian(::Array{Float64,1}, ::Array{Float64,2}, ::Int32, ::Int64) at C:\projects\fairness-jl\src\datasets\synthetic.jl:13
   [5] genZafarData(::Int32, ::Float64) at C:\projects\fairness-jl\src\datasets\synthetic.jl:32
   [6] genZafarData() at C:\projects\fairness-jl\src\datasets\synthetic.jl:30
   [7] top-level scope at C:\projects\fairness-jl\test\datasets\synthetic.jl:2
   [8] top-level scope at D:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.5\Test\src\Test.jl:1115
   [9] top-level scope at C:\projects\fairness-jl\test\datasets\synthetic.jl:2
   [10] include(::String) at .\client.jl:457
   [11] top-level scope at C:\projects\fairness-jl\test\runtests.jl:15
   [12] top-level scope at D:\buildbot\worker\package_win32\build\usr\share\julia\stdlib\v1.5\Test\src\Test.jl:1115
   [13] top-level scope at C:\projects\fairness-jl\test\runtests.jl:14
   [14] include(::String) at .\client.jl:457
   [15] top-level scope at none:6
   [16] eval(::Module, ::Any) at .\boot.jl:331
   [17] exec_options(::Base.JLOptions) at .\client.jl:272
   [18] _start() at .\client.jl:506

I can see the test for rand(nv, n_samples) at https://github.com/JuliaStats/Distributions.jl/blob/master/test/mvnormal.jl#L41 and the test seems to pass on appveyor for Distributions.jl for windows-x86. I can't figure out how to fix this issue with the code snipped I wrote at the top of this issue.

jkbest2 commented 4 years ago

Right now your sigma1 is a vector of vectors, not a matrix. You want

sigma1 = [5.0 1.0; 1.0 5.0]