-
Notifications
You must be signed in to change notification settings - Fork 40
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
Allow Real
arguments in R functions and use Julia implementations only
#125
Conversation
Codecov Report
@@ Coverage Diff @@
## master #125 +/- ##
==========================================
+ Coverage 30.23% 37.41% +7.17%
==========================================
Files 12 12
Lines 377 417 +40
==========================================
+ Hits 114 156 +42
+ Misses 263 261 -2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable. I guess that switching progressively to Julia implementations can also make the process easier than waiting for a complete switch. I'll leave @andreasnoack comment on these implementations though.
((1f0, 1f0), 0f0:0.01f0:1f0), | ||
((1.0, 1.0), 0f0:0.01f0:1f0), | ||
((Float16(1), Float16(1)), Float16(0):Float16(0.01):Float16(1)), | ||
((1f0, 1f0), Float16(0):Float16(0.01):Float16(1)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also test other types such as integers, rationals and/or a big type. Also, do we have tests somewhere mixing different input types to check that promotion works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll add integers and rationals as well. Promotions are already tested, e.g. here Float32 and Float16 and Float32 and Float64 above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added more tests with integers and rationals. I also added tests for the values outside of the support.
Bump 🙂 It would also be nice to merge this PR since it fixes the remaining test errors in JuliaStats/Distributions.jl#1387. |
@andreasnoack it would be great if you could have a look at this PR 🙂 |
This PR is based on #124 and contains some parts of @andreasnoack's PR #113. I thought it would be cleaner to open a new PR instead of adding commits to #124.
The main motivation for this PR is that I am not satisfied with the approach in #124. I agree with @nalimilan that the type union is somewhat arbitrary and ideally we would just allow
Real
and letconvert(Float64, ...)
(implicitly in theccall
) handle the arguments when we call into Rmath. The main issue is that currently some generic Julia implementations exist in StatsFuns that already allowReal
but they are used only as fallbacks and not for arguments of typeFloat64
orInt
.In this PR,
Real
,RFunctions
submodule anymore but are separate functions of the same name to which alsoFloat64
andInt
are dispatched.The second point makes it also a bit easier to ensure that we actually compare the R with the Julia implementations in the tests since currently e.g.
RFunctions.betalogpdf
andbetalogpdf
are the same function and for arguments of typeUnion{Float64,Int}
always the R implementation is used.Currently, the Julia implementations do not correspond to the R versions exactly, e.g.
betapdf
errors for values ofx
outside of[0, 1]
whereasRFunctions.betapdf
returns 0. I used some of @andreasnoack's changes in #113 and tried to handle values outside of the support in this PR. I also extended the tests similar to #113, in addition to the tests with Float16 and Float32 from #124, to make sure that the Julia implementations are accurate enough. Maybe some additional tests should be added though.The main difference from #113 is that this PR does not add any new Julia implementations (e.g. for CDF or other distributions). It only updates the existing implementations such that they can be used instead of the R functions also with
Float64
andInt
.A positive side-effect of using the Julia implementation for
Float64
is that it seems to improve performance. The example below is motivated by @cscherrer's observation (https://twitter.com/ChadScherrer/status/1433143576943337477) that MeasureTheory's pdf for student t distributions is faster thantdistpdf
.Current release
This PR