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

Arguments typed as Number #38

Open
dmbates opened this issue Mar 14, 2018 · 3 comments
Open

Arguments typed as Number #38

dmbates opened this issue Mar 14, 2018 · 3 comments

Comments

@dmbates
Copy link
Contributor

dmbates commented Mar 14, 2018

In many method definitions arguments are typed as Number. For example, in src/distrs/chisq.jl

# pdf for numbers with generic types
function chisqpdf(k::Real, x::Number)
  hk = k / 2  # half k
  1 / (2^(hk) * gamma(hk)) * x^(hk - 1) * exp(-x / 2)
end

# logpdf for numbers with generic types
function chisqlogpdf(k::Real, x::Number)
  hk = k / 2  # half k
  -hk * log(oftype(hk, 2)) - lgamma(hk) + (hk - 1) * log(x) - x / 2
end

It appears that the only difference between Number and Real is that Number includes Complex

julia> subtypes(Number)
2-element Array{Union{DataType, UnionAll},1}:
 Complex
 Real   

I don't see the purpose in allowing complex numbers in these cases. Any objection to my changing these to Real?

@ararslan
Copy link
Member

ararslan commented Mar 14, 2018

For negative complex x do the values correspond to the generalized chi squared distribution?

@andreasnoack
Copy link
Member

I think many of these were relaxed at a time when we discussed the proper location in the type tree for dual numbers. Initially, they were not Real so to allow for autodiff, we relaxed the methods here to Number. Eventually, it was concluded that it was easier to make dual numbers Real so we can probably restrict most of the signatures again. However, I there might be a few specificity issues. In https://github.com/JuliaStats/StatsFuns.jl/pull/35/files we actually defined the promotion method for Number to avoid ambiguity issues.

@dmbates
Copy link
Contributor Author

dmbates commented Mar 15, 2018

@andreasnoack I suspected that the use of Number was related to autodiff. I will change those in the promotions branch that I am working on.

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

No branches or pull requests

3 participants