{"action":"opened","issue":{"url":"https://api.github.com/repos/mschauer/GaussianDistributions.jl/issues/14","repository_url":"https://api.github.com/repos/mschauer/GaussianDistributions.jl","labels_url":"https://api.github.com/repos/mschauer/GaussianDistributions.jl/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/mschauer/GaussianDistributions.jl/issues/14/comments","events_url":"https://api.github.com/repos/mschauer/GaussianDistributions.jl/issues/14/events","html_url":"https://github.com/mschauer/GaussianDistributions.jl/issues/14","id":371155190,"node_id":"MDU6SXNzdWUzNzExNTUxOTA=","number":14,"title":"Support units","user":{"login":"cstjean","id":8622776,"node_id":"MDQ6VXNlcjg2MjI3NzY=","avatar_url":"https://avatars0.githubusercontent.com/u/8622776?v=4","gravatar_id":"","url":"https://api.github.com/users/cstjean","html_url":"https://github.com/cstjean","followers_url":"https://api.github.com/users/cstjean/followers","following_url":"https://api.github.com/users/cstjean/following{/other_user}","gists_url":"https://api.github.com/users/cstjean/gists{/gist_id}","starred_url":"https://api.github.com/users/cstjean/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cstjean/subscriptions","organizations_url":"https://api.github.com/users/cstjean/orgs","repos_url":"https://api.github.com/users/cstjean/repos","events_url":"https://api.github.com/users/cstjean/events{/privacy}","received_events_url":"https://api.github.com/users/cstjean/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-10-17T16:08:14Z","updated_at":"2018-10-17T16:08:14Z","closed_at":null,"author_association":"COLLABORATOR","body":"We started using units everywhere in our code, and it would be nice to have them inside GaussianDistributions too:\r\n\r\n```julia\r\njulia> using Unitful, GaussianDistributions\r\n\r\njulia> rand(Gaussian(1.0u\"m\", 1.0u\"m^2\"))\r\nERROR: MethodError: no method matching randn(::Random.MersenneTwister, ::Type{Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)},Unitful.FreeUnits{(Unitful.Unit{:Meter,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}(0, 1//1),),Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}}})\r\nClosest candidates are:\r\n  randn(::Random.AbstractRNG, ::Type{T}, ::Tuple{Vararg{Int64,N}} where N) where T at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/normal.jl:179\r\n  randn(::Random.AbstractRNG, ::Type{T}, ::Integer, ::Integer...) where T at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/normal.jl:182\r\n  randn(::Random.AbstractRNG) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/normal.jl:37\r\n  ...\r\nStacktrace:\r\n [1] randn(::Type{Quantity{Float64,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)},Unitful.FreeUnits{(Unitful.Unit{:Meter,Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}(0, 1//1),),Unitful.Dimensions{(Unitful.Dimension{:Length}(1//1),)}}}}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/normal.jl:166\r\n```\r\n\r\nThe current definition is `rand(P::Gaussian{<:Number}) = P.μ + randn(typeof(P.μ)) * sqrt(P.Σ)`. I believe the easiest way to do this would be to add `Base.randn(::Quantity{T}) = randn(T)`. Then GaussianDistrubtions wouldn't have to import Unitful.\r\n\r\n@ajkeller34 what do you think? Initially, I felt like `randn(typeof(u\"1.0m\"))` should return a quantity in meter. That would match the randn docstring\r\n\r\n>   Generate a normally-distributed random number of type T with mean 0 and standard deviation 1.\r\n\r\nHowever, I believe that the `P.μ + randn(typeof(P.μ)) * sqrt(P.Σ)` is very mathematically fundamental, and it expects `randn(typeof(u\"1.0m\"))` to be dimensionless."}}
{"actor":{"display_login":"cstjean"}}