I'm trying to construct an array of Dicts (Dict{Symbol,Any}, to be used as 
initial values for MCMC chains by the Mamba package). The following problem 
doesn't appear to have anything to do with Mamba, though.


julia> using Distributions

The following works, i.e. autoamatic conversion works: rand(Binomial(50, 
0.75)) will returns an Int64 and 34.3 is a Float64

julia> inits = [[:k => rand(Binomial(50, 0.75)), :j => 34.3] for i in 1:2]
2-element Array{Dict{Symbol,Any},1}:
 [:j=>34.3,:k=>39]
 [:j=>34.3,:k=>42]


This also works:

julia> k= rand(Binomial(50, 0.75))
42

julia> typeof(k)
Int64

julia> inits = [[:k => k, :j => 34.3]]
1-element Array{Dict{Symbol,Any},1}:
 [:j=>34.3,:k=>42]

But this doesn't, i.e. automatic type conversion doesn't work:

julia> inits = [[:k => k, :j => 34.3] for i in 1:nchains]
3-element Array{Union(Dict{Symbol,Float64},Dict{Symbol,Any}),1}:
 [:j=>34.3,:k=>42]
 [:j=>34.3,:k=>42]
 [:j=>34.3,:k=>42]


If I specify the type, it works:
julia> inits = [(Symbol => Any)[:k => k, :j => 34.3] for i in 1:nchains]

I'm using:

julia> versioninfo()
Julia Version 0.3.3
Commit b24213b* (2014-11-23 20:19 UTC)
Platform Info:
  System: Darwin (x86_64-apple-darwin13.3.0)
  CPU: Intel(R) Core(TM) i7-4558U CPU @ 2.80GHz
  WORD_SIZE: 64
  BLAS: libopenblas (DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas
  LIBM: libopenlibm
  LLVM: libLLVM-3.3

Am I doing anything wrong?

Cheers,
Andrew

Reply via email to