Skip to content

Commit

Permalink
Merge pull request #279 from JuliaStats/nl/appveyor
Browse files Browse the repository at this point in the history
Enable AppVeyor, remove randi()
  • Loading branch information
ararslan authored Jul 2, 2017
2 parents 6df21f0 + 9d54101 commit 37f392a
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 55 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
[![StatsBase](http://pkg.julialang.org/badges/StatsBase_0.6.svg)](http://pkg.julialang.org/?pkg=StatsBase)
- **Build & Testing Status:**
[![Build Status](https://travis-ci.org/JuliaStats/StatsBase.jl.svg?branch=master)](https://travis-ci.org/JuliaStats/StatsBase.jl)
[![Build status](https://ci.appveyor.com/api/projects/status/fsut3j3onulvws1w?svg=true)](https://ci.appveyor.com/project/nalimilan/statsbase-jl)
[![Coverage Status](https://coveralls.io/repos/JuliaStats/StatsBase.jl/badge.svg?branch=master)](https://coveralls.io/r/JuliaStats/StatsBase.jl?branch=master)

- **Documentation**: [![][docs-stable-img]][docs-stable-url] [![][docs-latest-img]][docs-latest-url]
Expand Down
42 changes: 42 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
environment:
matrix:
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe"
- JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe"
- JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe"

branches:
only:
- master
- /release-.*/

notifications:
- provider: Email
on_build_success: false
on_build_failure: false
on_build_status_changed: false

install:
- ps: "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
# If there's a newer build queued for the same PR, cancel this one
- ps: if ($env:APPVEYOR_PULL_REQUEST_NUMBER -and $env:APPVEYOR_BUILD_NUMBER -ne ((Invoke-RestMethod `
https://ci.appveyor.com/api/projects/$env:APPVEYOR_ACCOUNT_NAME/$env:APPVEYOR_PROJECT_SLUG/history?recordsNumber=50).builds | `
Where-Object pullRequestId -eq $env:APPVEYOR_PULL_REQUEST_NUMBER)[0].buildNumber) { `
throw "There are newer queued builds for this pull request, failing early." }
# Download most recent Julia Windows binary
- ps: (new-object net.webclient).DownloadFile(
$env:JULIA_URL,
"C:\projects\julia-binary.exe")
# Run installer silently, output to C:\projects\julia
- C:\projects\julia-binary.exe /S /D=C:\projects\julia

build_script:
# Need to convert from shallow to complete for Pkg.clone to work
- IF EXIST .git\shallow (git fetch --unshallow)
- C:\projects\julia\bin\julia -e "versioninfo();
Pkg.clone(pwd(), \"StatsBase\"); Pkg.build(\"StatsBase\")"

test_script:
- C:\projects\julia\bin\julia -e "Pkg.test(\"StatsBase\")"
1 change: 0 additions & 1 deletion src/StatsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ module StatsBase
include("toeplitzsolvers.jl")
include("rankcorr.jl")
include("signalcorr.jl")
include("rand.jl")
include("empirical.jl")
include("hist.jl")
include("misc.jl")
Expand Down
34 changes: 34 additions & 0 deletions src/deprecates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,37 @@ findat(a::AbstractArray, b::AbstractArray) = findat!(Array{Int}(size(b)), a, b)
@deprecate df_residual(obj::StatisticalModel) dof_residual(obj)

@deprecate_binding WeightVec Weights

immutable RandIntSampler # for generating Int samples in [0, K-1]
a::Int
Ku::UInt
U::UInt

function RandIntSampler(K::Int)
Base.depwarn("RandIntSampler is deprecated, use Base.Random.RangeGenerator instead",
:RandIntSampler)
Ku = UInt(K)
new(1, Ku, div(typemax(UInt), Ku) * Ku)
end
function RandIntSampler(a::Int, b::Int)
Base.depwarn("RandIntSampler is deprecated, use Base.Random.RangeGenerator instead",
:RandIntSampler)
Ku = UInt(b-a+1)
new(a, Ku, div(typemax(UInt), Ku) * Ku)
end
end

function rand(rng::AbstractRNG, s::RandIntSampler)
x = rand(rng, UInt)
while x >= s.U
x = rand(rng, UInt)
end
s.a + Int(rem(x, s.Ku))
end
rand(s::RandIntSampler) = rand(Base.GLOBAL_RNG, s)

@deprecate randi(rng::AbstractRNG, K::Int) rand(rng, 1:K)
@deprecate randi(K::Int) rand(1:K)
@deprecate randi(rng::AbstractRNG, a::Int, b::Int) rand(rng, a:b)
@deprecate randi(a::Int, b::Int) rand(a:b)

24 changes: 0 additions & 24 deletions src/rand.jl

This file was deleted.

22 changes: 12 additions & 10 deletions src/sampling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
#
###########################################################

using Base.Random: RangeGenerator

### Algorithms for sampling with replacement

function direct_sample!(rng::AbstractRNG, a::UnitRange, x::AbstractArray)
s = RandIntSampler(length(a))
s = RangeGenerator(1:length(a))
b = a[1] - 1
if b == 0
for i = 1:length(x)
Expand All @@ -32,7 +34,7 @@ and set `x[j] = a[i]`, with `n=length(a)` and `k=length(x)`.
This algorithm consumes `k` random numbers.
"""
function direct_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray)
s = RandIntSampler(length(a))
s = RangeGenerator(1:length(a))
for i = 1:length(x)
@inbounds x[i] = a[rand(rng, s)]
end
Expand All @@ -51,8 +53,8 @@ Optionally specify a random number generator `rng` as the first argument
(defaults to `Base.GLOBAL_RNG`).
"""
function samplepair(rng::AbstractRNG, n::Int)
i1 = randi(rng, n)
i2 = randi(rng, n-1)
i1 = rand(rng, 1:n)
i2 = rand(rng, 1:n-1)
return (i1, ifelse(i2 == i1, n, i2))
end
samplepair(n::Int) = samplepair(Base.GLOBAL_RNG, n)
Expand Down Expand Up @@ -95,7 +97,7 @@ function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray;
end
if initshuffle
@inbounds for j = 1:k
l = randi(rng, j, k)
l = rand(rng, j:k)
if l != j
t = x[j]
x[j] = x[l]
Expand All @@ -105,7 +107,7 @@ function knuths_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray;
end

# scan remaining
s = RandIntSampler(k)
s = RangeGenerator(1:k)
for i = k+1:n
if rand(rng) * i < k # keep it with probability k / i
@inbounds x[rand(rng, s)] = a[i]
Expand Down Expand Up @@ -151,7 +153,7 @@ function fisher_yates_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArr
end

@inbounds for i = 1:k
j = randi(rng, i, n)
j = rand(rng, i:n)
t = inds[j]
inds[j] = inds[i]
inds[i] = t
Expand Down Expand Up @@ -183,7 +185,7 @@ function self_avoid_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArray

s = Set{Int}()
sizehint!(s, k)
rgen = RandIntSampler(n)
rgen = RangeGenerator(1:n)

# first one
idx = rand(rng, rgen)
Expand Down Expand Up @@ -297,7 +299,7 @@ the weights given in `wv`, if provided.
Optionally specify a random number generator `rng` as the first argument
(defaults to `Base.GLOBAL_RNG`).
"""
sample(rng::AbstractRNG, a::AbstractArray) = a[randi(rng, length(a))]
sample(rng::AbstractRNG, a::AbstractArray) = a[rand(rng, 1:length(a))]
sample(a::AbstractArray) = sample(Base.GLOBAL_RNG, a)


Expand Down Expand Up @@ -531,7 +533,7 @@ function alias_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights,
make_alias_table!(values(wv), sum(wv), ap, alias)

# sampling
s = RandIntSampler(n)
s = RangeGenerator(1:n)
for i = 1:length(x)
j = rand(rng, s)
x[i] = rand(rng) < ap[j] ? a[j] : a[alias[j]]
Expand Down
24 changes: 4 additions & 20 deletions test/sampling.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using StatsBase
using Base.Test
import Base: maxabs
import StatsBase: norepeat, randi
import StatsBase: norepeat

srand(1234)

Expand All @@ -25,22 +25,6 @@ function test_rng_use(func, non_rng_args...)
@test x == y
end

#### randi

n = 10^5

x = [randi(10) for i = 1:n]
@test isa(x, Vector{Int})
@test extrema(x) == (1, 10)
@test isapprox(proportions(x, 1:10), fill(0.1, 10), atol=5.0e-3)
test_rng_use(randi, 1000)


x = [randi(3, 12) for i = 1:n]
@test isa(x, Vector{Int})
@test extrema(x) == (3, 12)
@test isapprox(proportions(x, 3:12), fill(0.1, 10), atol=5.0e-3)

#### sample with replacement

function check_sample_wrep(a::AbstractArray, vrgn, ptol::Real; ordered::Bool=false)
Expand Down Expand Up @@ -96,10 +80,10 @@ test_rng_use(sample, 1:10, 10)

srand(1);

@test samplepair(2) === (1, 2)
@test samplepair(10) === (7, 3)
@test samplepair(2) === (1, 2)
@test samplepair(10) === (10, 6)

@test samplepair([3, 4, 2, 6, 8]) === (4, 3)
@test samplepair([3, 4, 2, 6, 8]) === (6, 2)
@test samplepair([1, 2]) === (1, 2)

test_rng_use(samplepair, 1000)
Expand Down

0 comments on commit 37f392a

Please sign in to comment.