diff --git a/REQUIRE b/REQUIRE index a2166e076..f2267e11a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,4 +1,4 @@ julia 0.6 DataStructures 0.5.0 SpecialFunctions 0.1.0 -Compat 0.32 +Compat 0.39.0 diff --git a/src/StatsBase.jl b/src/StatsBase.jl index 2f44a2060..add9197c0 100644 --- a/src/StatsBase.jl +++ b/src/StatsBase.jl @@ -11,6 +11,10 @@ module StatsBase using Compat, SortingAlgorithms + if VERSION >= v"0.7.0-DEV.3052" + using Printf + end + ## tackle compatibility issues export diff --git a/src/counts.jl b/src/counts.jl index eb16ad53b..58381fec6 100644 --- a/src/counts.jl +++ b/src/counts.jl @@ -8,6 +8,12 @@ const IntUnitRange{T<:Integer} = UnitRange{T} +if isdefined(Base, :ht_keyindex2) + const ht_keyindex2! = Base.ht_keyindex2 +else + using Base: ht_keyindex2! +end + #### functions for counting a single list of integers (1D) """ addcounts!(r, x, levels::UnitRange{<:Int}, [wv::AbstractWeights]) @@ -267,7 +273,7 @@ end """Dict-based addcounts method""" function addcounts_dict!(cm::Dict{T}, x::AbstractArray{T}) where T for v in x - index = Base.ht_keyindex2(cm, v) + index = ht_keyindex2!(cm, v) if index > 0 @inbounds cm.vals[index] += 1 else diff --git a/src/deprecates.jl b/src/deprecates.jl index 4a1f61cf5..ece343fec 100644 --- a/src/deprecates.jl +++ b/src/deprecates.jl @@ -42,7 +42,7 @@ end For each element in `b`, find its first index in `a`. If the value does not occur in `a`, the corresponding index is 0. """ -findat(a::AbstractArray, b::AbstractArray) = findat!(Array{Int}(size(b)), a, b) +findat(a::AbstractArray, b::AbstractArray) = findat!(Array{Int}(uninitialized, size(b)), a, b) @deprecate df(obj::StatisticalModel) dof(obj) @deprecate df_residual(obj::StatisticalModel) dof_residual(obj) diff --git a/src/empirical.jl b/src/empirical.jl index c1fd5c3b0..654ea616c 100644 --- a/src/empirical.jl +++ b/src/empirical.jl @@ -20,7 +20,7 @@ function ecdf(X::RealVector{T}) where T<:Real function ef(v::RealVector) ord = sortperm(v) m = length(v) - r = Vector{T}(m) + r = Vector{T}(uninitialized, m) r0 = 0 i = 1 diff --git a/src/misc.jl b/src/misc.jl index 93100fe2c..40666c2ec 100644 --- a/src/misc.jl +++ b/src/misc.jl @@ -72,7 +72,7 @@ function inverse_rle(vals::AbstractVector{T}, lens::IntegerVector) where T m = length(vals) length(lens) == m || raise_dimerror() - r = Vector{T}(sum(lens)) + r = Vector{T}(uninitialized, sum(lens)) p = 0 @inbounds for i = 1 : m j = lens[i] @@ -192,7 +192,7 @@ function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T m = length(c) n = length(x) - rinds = Vector{Int}(n) + rinds = Vector{Int}(uninitialized, n) @inbounds for i = 1 : n rinds[i] = d[x[i]] end diff --git a/src/ranking.jl b/src/ranking.jl index 0a4ec4716..8130260aa 100644 --- a/src/ranking.jl +++ b/src/ranking.jl @@ -39,7 +39,7 @@ Return the [ordinal ranking](https://en.wikipedia.org/wiki/Ranking#Ordinal_ranki All items in `x` are given distinct, successive ranks based on their position in `sort(x)`. """ -ordinalrank(x::RealArray) = ordinalrank!(Array{Int}(size(x)), x, sortperm(x)) +ordinalrank(x::RealArray) = ordinalrank!(Array{Int}(uninitialized, size(x)), x, sortperm(x)) # Competition ranking ("1224" ranking) -- resolve tied ranks using min @@ -77,7 +77,7 @@ Return the [standard competition ranking](http://en.wikipedia.org/wiki/Ranking#S array. Items that compare equal are given the same rank, then a gap is left in the rankings the size of the number of tied items - 1. """ -competerank(x::RealArray) = competerank!(Array{Int}(size(x)), x, sortperm(x)) +competerank(x::RealArray) = competerank!(Array{Int}(uninitialized, size(x)), x, sortperm(x)) # Dense ranking ("1223" ranking) -- resolve tied ranks using min @@ -115,7 +115,7 @@ Return the [dense ranking](http://en.wikipedia.org/wiki/Ranking#Dense_ranking_.2 compare equal receive the same ranking, and the next subsequent rank is assigned with no gap. """ -denserank(x::RealArray) = denserank!(Array{Int}(size(x)), x, sortperm(x)) +denserank(x::RealArray) = denserank!(Array{Int}(uninitialized, size(x)), x, sortperm(x)) # Tied ranking ("1 2.5 2.5 4" ranking) -- resolve tied ranks using average @@ -161,5 +161,5 @@ also called fractional or "1 2.5 2.5 4" ranking, of a real-valued array. Items that compare equal receive the mean of the rankings they would have been assigned under ordinal ranking. """ -tiedrank(x::RealArray) = tiedrank!(Array{Float64}(size(x)), x, sortperm(x)) +tiedrank(x::RealArray) = tiedrank!(Array{Float64}(uninitialized, size(x)), x, sortperm(x)) diff --git a/src/sampling.jl b/src/sampling.jl index 8247afb81..fdbef5f4b 100644 --- a/src/sampling.jl +++ b/src/sampling.jl @@ -147,7 +147,7 @@ function fisher_yates_sample!(rng::AbstractRNG, a::AbstractArray, x::AbstractArr k = length(x) k <= n || error("length(x) should not exceed length(a)") - inds = Vector{Int}(n) + inds = Vector{Int}(uninitialized, n) for i = 1:n @inbounds inds[i] = i end @@ -370,7 +370,7 @@ Optionally specify a random number generator `rng` as the first argument """ function sample(rng::AbstractRNG, a::AbstractArray{T}, n::Integer; replace::Bool=true, ordered::Bool=false) where T - sample!(rng, a, Vector{T}(n); replace=replace, ordered=ordered) + sample!(rng, a, Vector{T}(uninitialized, n); replace=replace, ordered=ordered) end sample(a::AbstractArray, n::Integer; replace::Bool=true, ordered::Bool=false) = sample(Base.GLOBAL_RNG, a, n; replace=replace, ordered=ordered) @@ -390,7 +390,7 @@ Optionally specify a random number generator `rng` as the first argument """ function sample(rng::AbstractRNG, a::AbstractArray{T}, dims::Dims; replace::Bool=true, ordered::Bool=false) where T - sample!(rng, a, Array{T}(dims), rng; replace=replace, ordered=ordered) + sample!(rng, a, Array{T}(uninitialized, dims), rng; replace=replace, ordered=ordered) end sample(a::AbstractArray, dims::Dims; replace::Bool=true, ordered::Bool=false) = sample(Base.GLOBAL_RNG, a, dims; replace=replace, ordered=ordered) @@ -477,8 +477,8 @@ function make_alias_table!(w::AbstractVector{Float64}, wsum::Float64, @inbounds a[i] = w[i] * ac end - larges = Vector{Int}(n) - smalls = Vector{Int}(n) + larges = Vector{Int}(uninitialized, n) + smalls = Vector{Int}(uninitialized, n) kl = 0 # actual number of larges ks = 0 # actual number of smalls @@ -528,8 +528,8 @@ function alias_sample!(rng::AbstractRNG, a::AbstractArray, wv::AbstractWeights, length(wv) == n || throw(DimensionMismatch("Inconsistent lengths.")) # create alias table - ap = Vector{Float64}(n) - alias = Vector{Int}(n) + ap = Vector{Float64}(uninitialized, n) + alias = Vector{Int}(uninitialized, n) make_alias_table!(values(wv), sum(wv), ap, alias) # sampling @@ -560,7 +560,7 @@ function naive_wsample_norep!(rng::AbstractRNG, a::AbstractArray, length(wv) == n || throw(DimensionMismatch("Inconsistent lengths.")) k = length(x) - w = Vector{Float64}(n) + w = Vector{Float64}(uninitialized, n) copy!(w, values(wv)) wsum = sum(wv) @@ -784,14 +784,14 @@ sample!(a::AbstractArray, wv::AbstractWeights, x::AbstractArray) = sample(rng::AbstractRNG, a::AbstractArray{T}, wv::AbstractWeights, n::Integer; replace::Bool=true, ordered::Bool=false) where {T} = - sample!(rng, a, wv, Vector{T}(n); replace=replace, ordered=ordered) + sample!(rng, a, wv, Vector{T}(uninitialized, n); replace=replace, ordered=ordered) sample(a::AbstractArray, wv::AbstractWeights, n::Integer; replace::Bool=true, ordered::Bool=false) = sample(Base.GLOBAL_RNG, a, wv, n; replace=replace, ordered=ordered) sample(rng::AbstractRNG, a::AbstractArray{T}, wv::AbstractWeights, dims::Dims; replace::Bool=true, ordered::Bool=false) where {T} = - sample!(rng, a, wv, Array{T}(dims); replace=replace, ordered=ordered) + sample!(rng, a, wv, Array{T}(uninitialized, dims); replace=replace, ordered=ordered) sample(a::AbstractArray, wv::AbstractWeights, dims::Dims; replace::Bool=true, ordered::Bool=false) = sample(Base.GLOBAL_RNG, a, wv, dims; replace=replace, ordered=ordered) @@ -845,7 +845,7 @@ Optionally specify a random number generator `rng` as the first argument """ wsample(rng::AbstractRNG, a::AbstractArray{T}, w::RealVector, n::Integer; replace::Bool=true, ordered::Bool=false) where {T} = - wsample!(rng, a, w, Vector{T}(n); replace=replace, ordered=ordered) + wsample!(rng, a, w, Vector{T}(uninitialized, n); replace=replace, ordered=ordered) wsample(a::AbstractArray, w::RealVector, n::Integer; replace::Bool=true, ordered::Bool=false) = wsample(Base.GLOBAL_RNG, a, w, n; replace=replace, ordered=ordered) @@ -862,7 +862,7 @@ Optionally specify a random number generator `rng` as the first argument """ wsample(rng::AbstractRNG, a::AbstractArray{T}, w::RealVector, dims::Dims; replace::Bool=true, ordered::Bool=false) where {T} = - wsample!(rng, a, w, Array{T}(dims); replace=replace, ordered=ordered) + wsample!(rng, a, w, Array{T}(uninitialized, dims); replace=replace, ordered=ordered) wsample(a::AbstractArray, w::RealVector, dims::Dims; replace::Bool=true, ordered::Bool=false) = wsample(Base.GLOBAL_RNG, a, w, dims; replace=replace, ordered=ordered) diff --git a/src/scalarstats.jl b/src/scalarstats.jl index 408ab23ab..8b70b8cfe 100644 --- a/src/scalarstats.jl +++ b/src/scalarstats.jl @@ -373,13 +373,13 @@ In particular, when `μ` and `σ` are arrays, they should have the same size, an """ function zscore(X::AbstractArray{T}, μ::Real, σ::Real) where T<:Real ZT = typeof((zero(T) - zero(μ)) / one(σ)) - _zscore!(Array{ZT}(size(X)), X, μ, σ) + _zscore!(Array{ZT}(uninitialized, size(X)), X, μ, σ) end function zscore(X::AbstractArray{T}, μ::AbstractArray{U}, σ::AbstractArray{S}) where {T<:Real,U<:Real,S<:Real} _zscore_chksize(X, μ, σ) ZT = typeof((zero(T) - zero(U)) / one(S)) - _zscore!(Array{ZT}(size(X)), X, μ, σ) + _zscore!(Array{ZT}(uninitialized, size(X)), X, μ, σ) end zscore(X::AbstractArray{<:Real}) = ((μ, σ) = mean_and_std(X); zscore(X, μ, σ)) diff --git a/src/signalcorr.jl b/src/signalcorr.jl index 99a0c9fa1..44daf4c3e 100644 --- a/src/signalcorr.jl +++ b/src/signalcorr.jl @@ -79,7 +79,7 @@ function autocov!(r::RealMatrix, x::AbstractMatrix{T}, lags::IntegerVector; deme size(r) == (m, ns) || throw(DimensionMismatch()) check_lags(lx, lags) - z = Vector{T}(lx) + z = Vector{T}(uninitialized, lx) for j = 1 : ns demean_col!(z, x, j, demean) for k = 1 : m @@ -107,11 +107,11 @@ When left unspecified, the lags used are the integers from 0 to The output is not normalized. See [`autocor`](@ref) for a function with normalization. """ function autocov(x::AbstractVector{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - autocov!(Vector{fptype(T)}(length(lags)), float(x), lags; demean=demean) + autocov!(Vector{fptype(T)}(uninitialized, length(lags)), float(x), lags; demean=demean) end function autocov(x::AbstractMatrix{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - autocov!(Matrix{fptype(T)}(length(lags), size(x,2)), float(x), lags; demean=demean) + autocov!(Matrix{fptype(T)}(uninitialized, length(lags), size(x,2)), float(x), lags; demean=demean) end autocov(x::AbstractVecOrMat{<:Real}; demean::Bool=true) = autocov(x, default_autolags(size(x,1)); demean=demean) @@ -153,7 +153,7 @@ function autocor!(r::RealMatrix, x::AbstractMatrix{T}, lags::IntegerVector; deme size(r) == (m, ns) || throw(DimensionMismatch()) check_lags(lx, lags) - z = Vector{T}(lx) + z = Vector{T}(uninitialized, lx) for j = 1 : ns demean_col!(z, x, j, demean) zz = dot(z, z) @@ -183,11 +183,11 @@ The output is normalized by the variance of `x`, i.e. so that the lag 0 autocorrelation is 1. See [`autocov`](@ref) for the unnormalized form. """ function autocor(x::AbstractVector{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - autocor!(Vector{fptype(T)}(length(lags)), float(x), lags; demean=demean) + autocor!(Vector{fptype(T)}(uninitialized, length(lags)), float(x), lags; demean=demean) end function autocor(x::AbstractMatrix{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - autocor!(Matrix{fptype(T)}(length(lags), size(x,2)), float(x), lags; demean=demean) + autocor!(Matrix{fptype(T)}(uninitialized, length(lags), size(x,2)), float(x), lags; demean=demean) end autocor(x::AbstractVecOrMat{<:Real}; demean::Bool=true) = autocor(x, default_autolags(size(x,1)); demean=demean) @@ -243,7 +243,7 @@ function crosscov!(r::RealMatrix, x::AbstractMatrix{T}, y::AbstractVector{T}, la (length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch()) check_lags(lx, lags) - zx = Vector{T}(lx) + zx = Vector{T}(uninitialized, lx) zy::Vector{T} = demean ? y .- mean(y) : y for j = 1 : ns demean_col!(zx, x, j, demean) @@ -262,7 +262,7 @@ function crosscov!(r::RealMatrix, x::AbstractVector{T}, y::AbstractMatrix{T}, la check_lags(lx, lags) zx::Vector{T} = demean ? x .- mean(x) : x - zy = Vector{T}(lx) + zy = Vector{T}(uninitialized, lx) for j = 1 : ns demean_col!(zy, y, j, demean) for k = 1 : m @@ -294,8 +294,8 @@ function crosscov!(r::AbstractArray{T,3}, x::AbstractMatrix{T}, y::AbstractMatri push!(zxs, xj) end - zx = Vector{T}(lx) - zy = Vector{T}(lx) + zx = Vector{T}(uninitialized, lx) + zy = Vector{T}(uninitialized, lx) for j = 1 : ny demean_col!(zy, y, j, demean) for i = 1 : nx @@ -326,19 +326,19 @@ When left unspecified, the lags used are the integers from The output is not normalized. See [`crosscor`](@ref) for a function with normalization. """ function crosscov(x::AbstractVector{T}, y::AbstractVector{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscov!(Vector{fptype(T)}(length(lags)), float(x), float(y), lags; demean=demean) + crosscov!(Vector{fptype(T)}(uninitialized, length(lags)), float(x), float(y), lags; demean=demean) end function crosscov(x::AbstractMatrix{T}, y::AbstractVector{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscov!(Matrix{fptype(T)}(length(lags), size(x,2)), float(x), float(y), lags; demean=demean) + crosscov!(Matrix{fptype(T)}(uninitialized, length(lags), size(x,2)), float(x), float(y), lags; demean=demean) end function crosscov(x::AbstractVector{T}, y::AbstractMatrix{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscov!(Matrix{fptype(T)}(length(lags), size(y,2)), float(x), float(y), lags; demean=demean) + crosscov!(Matrix{fptype(T)}(uninitialized, length(lags), size(y,2)), float(x), float(y), lags; demean=demean) end function crosscov(x::AbstractMatrix{T}, y::AbstractMatrix{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscov!(Array{fptype(T),3}(length(lags), size(x,2), size(y,2)), float(x), float(y), lags; demean=demean) + crosscov!(Array{fptype(T),3}(uninitialized, length(lags), size(x,2), size(y,2)), float(x), float(y), lags; demean=demean) end crosscov(x::AbstractVecOrMat{T}, y::AbstractVecOrMat{T}; demean::Bool=true) where {T<:Real} = crosscov(x, y, default_crosslags(size(x,1)); demean=demean) @@ -383,7 +383,7 @@ function crosscor!(r::RealMatrix, x::AbstractMatrix{T}, y::AbstractVector{T}, la (length(y) == lx && size(r) == (m, ns)) || throw(DimensionMismatch()) check_lags(lx, lags) - zx = Vector{T}(lx) + zx = Vector{T}(uninitialized, lx) zy::Vector{T} = demean ? y .- mean(y) : y yy = dot(zy, zy) for j = 1 : ns @@ -404,7 +404,7 @@ function crosscor!(r::RealMatrix, x::AbstractVector{T}, y::AbstractMatrix{T}, la check_lags(lx, lags) zx::Vector{T} = demean ? x .- mean(x) : x - zy = Vector{T}(lx) + zy = Vector{T}(uninitialized, lx) xx = dot(zx, zx) for j = 1 : ns demean_col!(zy, y, j, demean) @@ -427,7 +427,7 @@ function crosscor!(r::AbstractArray{T,3}, x::AbstractMatrix{T}, y::AbstractMatri # cached (centered) columns of x zxs = Vector{Vector{T}}(0) sizehint!(zxs, nx) - xxs = Vector{T}(nx) + xxs = Vector{T}(uninitialized, nx) for j = 1 : nx xj = x[:,j] @@ -441,8 +441,8 @@ function crosscor!(r::AbstractArray{T,3}, x::AbstractMatrix{T}, y::AbstractMatri xxs[j] = dot(xj, xj) end - zx = Vector{T}(lx) - zy = Vector{T}(lx) + zx = Vector{T}(uninitialized, lx) + zy = Vector{T}(uninitialized, lx) for j = 1 : ny demean_col!(zy, y, j, demean) yy = dot(zy, zy) @@ -475,19 +475,19 @@ The output is normalized by `sqrt(var(x)*var(y))`. See [`crosscov`](@ref) for th unnormalized form. """ function crosscor(x::AbstractVector{T}, y::AbstractVector{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscor!(Vector{fptype(T)}(length(lags)), float(x), float(y), lags; demean=demean) + crosscor!(Vector{fptype(T)}(uninitialized, length(lags)), float(x), float(y), lags; demean=demean) end function crosscor(x::AbstractMatrix{T}, y::AbstractVector{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscor!(Matrix{fptype(T)}(length(lags), size(x,2)), float(x), float(y), lags; demean=demean) + crosscor!(Matrix{fptype(T)}(uninitialized, length(lags), size(x,2)), float(x), float(y), lags; demean=demean) end function crosscor(x::AbstractVector{T}, y::AbstractMatrix{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscor!(Matrix{fptype(T)}(length(lags), size(y,2)), float(x), float(y), lags; demean=demean) + crosscor!(Matrix{fptype(T)}(uninitialized, length(lags), size(y,2)), float(x), float(y), lags; demean=demean) end function crosscor(x::AbstractMatrix{T}, y::AbstractMatrix{T}, lags::IntegerVector; demean::Bool=true) where T<:Real - crosscor!(Array{fptype(T),3}(length(lags), size(x,2), size(y,2)), float(x), float(y), lags; demean=demean) + crosscor!(Array{fptype(T),3}(uninitialized, length(lags), size(x,2), size(y,2)), float(x), float(y), lags; demean=demean) end crosscor(x::AbstractVecOrMat{T}, y::AbstractVecOrMat{T}; demean::Bool=true) where {T<:Real} = crosscor(x, y, default_crosslags(size(x,1)); demean=demean) @@ -520,7 +520,7 @@ function pacf_regress!(r::RealMatrix, X::AbstractMatrix{T}, lags::IntegerVector, end function pacf_yulewalker!(r::RealMatrix, X::AbstractMatrix{T}, lags::IntegerVector, mk::Integer) where T<:RealFP - tmp = Vector{T}(mk) + tmp = Vector{T}(uninitialized, mk) for j = 1 : size(X,2) acfs = autocor(X[:,j], 1:mk) for i = 1 : length(lags) @@ -574,7 +574,7 @@ If `x` is a matrix, return a matrix of size `(length(lags), size(x, 2))`, where each column in the result corresponds to a column in `x`. """ function pacf(X::AbstractMatrix{T}, lags::IntegerVector; method::Symbol=:regression) where T<:Real - pacf!(Matrix{fptype(T)}(length(lags), size(X,2)), float(X), lags; method=method) + pacf!(Matrix{fptype(T)}(uninitialized, length(lags), size(X,2)), float(X), lags; method=method) end function pacf(x::AbstractVector{T}, lags::IntegerVector; method::Symbol=:regression) where T<:Real diff --git a/src/weights.jl b/src/weights.jl index d9169d8fc..7bb90ae52 100644 --- a/src/weights.jl +++ b/src/weights.jl @@ -1,3 +1,6 @@ +if !isdefined(Base, :axes) + const axes = Base.indices +end ###### Weight vector ##### @@ -416,7 +419,7 @@ end function wsum(A::AbstractArray{T}, w::AbstractVector{W}, dim::Int) where {T<:Number,W<:Real} length(w) == size(A,dim) || throw(DimensionMismatch("Inconsistent array dimension.")) - _wsum!(similar(A, wsumtype(T,W), Base.reduced_indices(indices(A), dim)), A, w, dim, true) + _wsum!(similar(A, wsumtype(T,W), Base.reduced_indices(axes(A), dim)), A, w, dim, true) end # extended sum! and wsum @@ -467,7 +470,7 @@ wmeantype(::Type{T}, ::Type{W}) where {T,W} = typeof((zero(T)*zero(W) + zero(T)* wmeantype(::Type{T}, ::Type{T}) where {T<:BlasReal} = T Base.mean(A::AbstractArray{T}, w::AbstractWeights{W}, dim::Int) where {T<:Number,W<:Real} = - mean!(similar(A, wmeantype(T, W), Base.reduced_indices(indices(A), dim)), A, w, dim) + mean!(similar(A, wmeantype(T, W), Base.reduced_indices(axes(A), dim)), A, w, dim) ###### Weighted median ##### @@ -593,7 +596,7 @@ function quantile(v::RealVector{V}, w::AbstractWeights{W}, p::RealVector) where # prepare out vector N = length(vw) - out = Vector{typeof(zero(V)/1)}(length(p)) + out = Vector{typeof(zero(V)/1)}(uninitialized, length(p)) fill!(out, vw[end][1]) # start looping on quantiles diff --git a/test/counts.jl b/test/counts.jl index 3e1fb17ce..e8a030fdd 100644 --- a/test/counts.jl +++ b/test/counts.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test n = 5000 diff --git a/test/cov.jl b/test/cov.jl index f66e1044e..8c9dcf93f 100644 --- a/test/cov.jl +++ b/test/cov.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test @testset "StatsBase.Covariance" begin weight_funcs = (weights, aweights, fweights, pweights) diff --git a/test/deviation.jl b/test/deviation.jl index 297dc9564..badf31d3c 100644 --- a/test/deviation.jl +++ b/test/deviation.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test a = [1, 2, 3, 4, 5, 6, 7] b = [1, 3, 3, 4, 6, 7, 8] diff --git a/test/empirical.jl b/test/empirical.jl index 8dcdbc824..39b7727ca 100644 --- a/test/empirical.jl +++ b/test/empirical.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test fnecdf = ecdf(randn(10000000)) @test isapprox(fnecdf([-1.96, -1.644854, -1.281552, -0.6744898, 0, 0.6744898, 1.281552, 1.644854, 1.96]), diff --git a/test/hist.jl b/test/hist.jl index 5a009cc00..c4caf2f9a 100644 --- a/test/hist.jl +++ b/test/hist.jl @@ -1,7 +1,12 @@ # See src/hist.jl for meaning of "FIXME: closed" comments. using StatsBase -using Base.Test +using Compat +using Compat.Test + +if !isdefined(Base, :axes) + const axes = Base.indices +end @testset "StatsBase.Histogram" begin @@ -16,8 +21,8 @@ using Base.Test @test @inferred StatsBase.binindex(h1, -0.5) == 4 @test @inferred StatsBase.binindex(h2, (1.5, 2)) == (8, 3) - @test [StatsBase.binvolume(h1, i) for i in indices(h1.weights, 1)] ≈ diff(edg1) - @test [StatsBase.binvolume(h2, (i,j)) for i in indices(h2.weights, 1), j in indices(h2.weights, 2)] ≈ diff(edg1) * diff(edg2)' + @test [StatsBase.binvolume(h1, i) for i in axes(h1.weights, 1)] ≈ diff(edg1) + @test [StatsBase.binvolume(h2, (i,j)) for i in axes(h2.weights, 1), j in axes(h2.weights, 2)] ≈ diff(edg1) * diff(edg2)' @test typeof(@inferred(StatsBase.binvolume(h2, (1,1)))) == Float64 @test typeof(@inferred(StatsBase.binvolume(h3, (1,1)))) == Float32 diff --git a/test/misc.jl b/test/misc.jl index a96777eda..cfd095f4c 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test # rle & inverse_rle diff --git a/test/moments.jl b/test/moments.jl index 488641cda..3325a97c7 100644 --- a/test/moments.jl +++ b/test/moments.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test @testset "StatsBase.Moments" begin weight_funcs = (weights, aweights, fweights, pweights) diff --git a/test/rankcorr.jl b/test/rankcorr.jl index f82e31a5f..7f74365a5 100644 --- a/test/rankcorr.jl +++ b/test/rankcorr.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test X = Float64[1 0; 2 1; 3 0; 4 1; 5 10] diff --git a/test/ranking.jl b/test/ranking.jl index 4eec13c22..686acaad1 100644 --- a/test/ranking.jl +++ b/test/ranking.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test a = [1.0, 2.0, 2.0, 3.0, 4.0, 4.0, 4.0, 5.0] x = [3.0, 1.0, 2.0, 4.0, 4.0, 2.0, 5.0, 4.0] # x is a permutated version of a diff --git a/test/robust.jl b/test/robust.jl index 46bc34f8f..09a238c98 100644 --- a/test/robust.jl +++ b/test/robust.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test ### Trimming outliers diff --git a/test/sampling.jl b/test/sampling.jl index 34861c581..38dc486a7 100644 --- a/test/sampling.jl +++ b/test/sampling.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test import Base: maxabs import StatsBase: norepeat diff --git a/test/scalarstats.jl b/test/scalarstats.jl index 6952ae289..fa3004a7e 100644 --- a/test/scalarstats.jl +++ b/test/scalarstats.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test ##### Location diff --git a/test/signalcorr.jl b/test/signalcorr.jl index 24f5d22be..a8cbd2e7d 100644 --- a/test/signalcorr.jl +++ b/test/signalcorr.jl @@ -5,7 +5,8 @@ # using StatsBase -using Base.Test +using Compat +using Compat.Test # random data for testing diff --git a/test/statmodels.jl b/test/statmodels.jl index 794ea07b3..252d238c0 100644 --- a/test/statmodels.jl +++ b/test/statmodels.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test srand(10) v1 = rand(3) diff --git a/test/statquiz.jl b/test/statquiz.jl index 7b824d38c..35502f130 100644 --- a/test/statquiz.jl +++ b/test/statquiz.jl @@ -1,10 +1,15 @@ # Test taken from http://www.stanford.edu/~clint/bench/wilk.txt -using Base.Test +using Compat +using Compat.Test using DataFrames using StatsBase using GLM +if VERSION >= v"0.7.0-DEV.3052" + using Printf +end + testeps = sqrt(eps()) nasty = DataFrame( label = ["One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine"], diff --git a/test/weights.jl b/test/weights.jl index 157970722..3a237e62d 100644 --- a/test/weights.jl +++ b/test/weights.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test @testset "StatsBase.Weights" begin weight_funcs = (weights, aweights, fweights, pweights) diff --git a/test/wsampling.jl b/test/wsampling.jl index 31012438a..f872ac850 100644 --- a/test/wsampling.jl +++ b/test/wsampling.jl @@ -1,5 +1,6 @@ using StatsBase -using Base.Test +using Compat +using Compat.Test import Base: maxabs import StatsBase: norepeat