Skip to content

Commit

Permalink
Use Int instead of Int64 in function signatures and test integer input (
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack authored Jan 18, 2017
1 parent c80fc2c commit d6edd54
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/rmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@ function _import_rmath(rname::Symbol, jname::Symbol, pargs)

# function implementation
quote
$pdf($(pdecls...), x::Union{Float64,Int64}) =
$pdf($(pdecls...), x::Union{Float64,Int}) =
ccall(($dfun, libRmath), Float64, $dtypes, x, $(pargs...), 0)

$logpdf($(pdecls...), x::Union{Float64,Int64}) =
$logpdf($(pdecls...), x::Union{Float64,Int}) =
ccall(($dfun, libRmath), Float64, $dtypes, x, $(pargs...), 1)

$cdf($(pdecls...), x::Real) =
Expand Down
18 changes: 16 additions & 2 deletions test/rmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ rmathcomp_tests("beta", [
((1.0, 1.0), 0.01:0.01:0.99),
((2.0, 3.0), 0.01:0.01:0.99),
((10.0, 2.0), 0.01:0.01:0.99),
((10, 2), 0.01:0.01:0.99),
])

rmathcomp_tests("binom", [
Expand All @@ -126,12 +127,14 @@ rmathcomp_tests("binom", [
((8, 0.6), 0.0:8.0),
((20, 0.1), 0.0:20.0),
((20, 0.9), 0.0:20.0),
((20, 0.9), 0:20),
])

rmathcomp_tests("chisq", [
((1,), 0.0:0.1:8.0),
((4,), 0.0:0.1:8.0),
((9,), 0.0:0.1:8.0),
((9,), 0:8),
])

rmathcomp_tests("fdist", [
Expand All @@ -140,6 +143,7 @@ rmathcomp_tests("fdist", [
((5, 2), (0.0:0.1:5.0)),
((10, 1), (0.0:0.1:5.0)),
((10, 3), (0.0:0.1:5.0)),
((10, 3), (0:5)),
])

rmathcomp_tests("gamma", [
Expand All @@ -148,63 +152,73 @@ rmathcomp_tests("gamma", [
((3.0, 1.0), (0.05:0.05:12.0)),
((9.0, 1.0), (0.05:0.05:12.0)),
((2.0, 3.0), (0.05:0.05:12.0)),
((2, 3), (1:12)),
])

rmathcomp_tests("hyper", [
((2, 3, 4), 0.0:4.0)
((2, 3, 4), 0.0:4.0),
((2, 3, 4), 0:4)
])

rmathcomp_tests("nbeta", [
((1.0, 1.0, 0.0), 0.01:0.01:0.99),
((2.0, 3.0, 0.0), 0.01:0.01:0.99),
((1.0, 1.0, 2.0), 0.01:0.01:0.99),
((3.0, 4.0, 2.0), 0.01:0.01:0.99),
((3, 4, 2), 0.01:0.01:0.99),
])

rmathcomp_tests("nbinom", [
((1, 0.5), 0.0:20.0),
((3, 0.5), 0.0:20.0),
((3, 0.2), 0.0:20.0),
((3, 0.8), 0.0:20.0),
((3, 0.8), 0:20),
])

rmathcomp_tests("nchisq", [
((2, 1), 0.0:0.2:8.0),
((2, 3), 0.0:0.2:8.0),
((4, 1), 0.0:0.2:8.0),
((4, 3), 0.0:0.2:8.0),
((4, 3), 0:8),
])

rmathcomp_tests("nfdist", [
((1.0, 1.0, 0.0), 0.1:0.1:10.0),
((1.0, 1.0, 2.0), 0.1:0.1:10.0),
((2.0, 3.0, 1.0), 0.1:0.1:10.0),
((2, 3, 1), 1:10),
])

rmathcomp_tests("norm", [
((0.0, 1.0), -6.0:0.01:6.0),
((2.0, 1.0), -3.0:0.01:7.0),
((0.0, 0.5), -3.0:0.01:3.0),
((0, 1), -3.0:3.0),
((0, 1), -3.0:0.01:3.0)
((0, 1), -3.0:0.01:3.0),
((0, 1), -3:3)
])

rmathcomp_tests("ntdist", [
((0, 1), -4.0:0.1:10.0),
((0, 4), -4.0:0.1:10.0),
((2, 1), -4.0:0.1:10.0),
((2, 4), -4.0:0.1:10.0),
((2, 4), -4:10),
])

rmathcomp_tests("pois", [
((0.5,), 0.0:20.0),
((1.0,), 0.0:20.0),
((2.0,), 0.0:20.0),
((10.0,), 0.0:20.0),
((10,), 0:20),
])

rmathcomp_tests("tdist", [
((1,), -5.0:0.1:5.0),
((2,), -5.0:0.1:5.0),
((5,), -5.0:0.1:5.0),
((5,), -5:5),
])

0 comments on commit d6edd54

Please sign in to comment.