Skip to content

Commit

Permalink
Merge pull request #189 from JuliaStats/aa/rmath
Browse files Browse the repository at this point in the history
Use StatsFuns rather than libRmath
  • Loading branch information
andreasnoack committed Jul 15, 2016
2 parents 7b260fb + e36d5c4 commit 30356e3
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 13 deletions.
12 changes: 7 additions & 5 deletions .travis.yml
Expand Up @@ -7,10 +7,12 @@ julia:
- nightly
notifications:
email: false
before_install:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
script:
- julia --check-bounds=yes -e 'Pkg.clone(pwd())'
- julia --check-bounds=yes -e 'Pkg.test("StatsBase"; coverage=true)'
# Work around a Travis bug
git:
depth: 999999
# Uncomment the following lines to override the default test script
#script:
# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
# - julia -e 'Pkg.clone(pwd()); Pkg.build("Primes"); Pkg.test("Primes"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("StatsBase")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
2 changes: 1 addition & 1 deletion REQUIRE
@@ -1,3 +1,3 @@
julia 0.4
Compat 0.8.4
StatsFuns 0.1.0
StatsFuns 0.3.0
2 changes: 2 additions & 0 deletions src/StatsBase.jl
Expand Up @@ -18,6 +18,8 @@ module StatsBase
softplus, invsoftplus,
logsumexp, softmax, softmax!

import StatsFuns: RFunctions.binomrand

export

## mathfuns (TODO: removed after a certain period)
Expand Down
5 changes: 0 additions & 5 deletions src/rand.jl
Expand Up @@ -19,8 +19,3 @@ end

randi(K::Int) = rand(RandIntSampler(K))
randi(a::Int, b::Int) = rand(RandIntSampler(a, b))

# draw a number from a binomial distribution

rand_binom(n::Real, p::Real) =
@compat Int(ccall((:rbinom, "libRmath-julia"), Float64, (Float64, Float64), n, p))
4 changes: 2 additions & 2 deletions src/sampling.jl
Expand Up @@ -57,7 +57,7 @@ function xmultinom_sample!(a::AbstractArray, x::AbstractArray)
end
offset = k
else
m = rand_binom(rk, 1.0 / (n - i + 1))
m = Int(binomrand(rk, 1.0 / (n - i + 1)))
if m > 0
@inbounds ai = a[i]
for j = 1:m
Expand Down Expand Up @@ -504,7 +504,7 @@ function xmultinom_sample!(a::AbstractArray, wv::WeightVec, x::AbstractArray)
end
offset = k
else
m = rand_binom(rk, wi / wsum)
m = Int(binomrand(rk, wi / wsum))
for j = 1 : m
@inbounds x[offset + j] = a[i]
end
Expand Down

0 comments on commit 30356e3

Please sign in to comment.