Skip to content

Commit 0b64a9c

Browse files
author
Kristoffer Carlsson
authored
Get rid of old type aliases (#840)
1 parent 97a6bd4 commit 0b64a9c

File tree

15 files changed

+182
-208
lines changed

15 files changed

+182
-208
lines changed

docs/src/counts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ The package provides functions to count the occurrences of distinct values.
77
```@docs
88
counts
99
proportions
10-
addcounts!(r::AbstractArray, x::StatsBase.IntegerArray, levels::StatsBase.IntUnitRange)
10+
addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer})
1111
```
1212

1313
## Counting over arbitrary distinct values

docs/src/scalarstats.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ percentile
6969
iqr
7070
nquantile
7171
quantile
72-
Statistics.median(v::StatsBase.RealVector, w::AbstractWeights{<:Real})
72+
Statistics.median(v::AbstractVector{<:Real}, w::AbstractWeights{<:Real})
7373
quantilerank
7474
percentilerank
7575
```

src/common.jl

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
11
# common utilities
22

3-
## convenient type alias
4-
#
5-
# These types signficantly reduces the need of using
6-
# type parameters in functions (which are often just
7-
# for the purpose of restricting the arrays to real)
8-
#
9-
# These could be removed when the Base supports
10-
# covariant type notation, i.e. AbstractVector{<:Real}
11-
#
12-
13-
const RealArray{T<:Real,N} = AbstractArray{T,N}
14-
const RealVector{T<:Real} = AbstractArray{T,1}
15-
const RealMatrix{T<:Real} = AbstractArray{T,2}
16-
17-
const IntegerArray{T<:Integer,N} = AbstractArray{T,N}
18-
const IntegerVector{T<:Integer} = AbstractArray{T,1}
19-
const IntegerMatrix{T<:Integer} = AbstractArray{T,2}
20-
21-
const RealFP = Union{Float32, Float64}
22-
23-
# A convenient typealias for deprecating default corrected Bool
24-
const DepBool = Union{Bool, Nothing}
25-
26-
function depcheck(fname::Symbol, varname::Symbol, b::DepBool)
3+
function depcheck(fname::Symbol, varname::Symbol, b::Union{Bool, Nothing})
274
if b === nothing
285
msg = "$fname will default to $varname=true in the future. Use $varname=false for previous behaviour."
296
Base.depwarn(msg, fname)

src/counts.jl

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
#
77
#################################################
88

9-
const IntUnitRange{T<:Integer} = UnitRange{T}
10-
119
if isdefined(Base, :ht_keyindex2)
1210
const ht_keyindex2! = Base.ht_keyindex2
1311
else
@@ -24,14 +22,14 @@ array `r`. For each `xi ∈ x`, if `xi == levels[j]`, then we increment `r[j]`.
2422
If a weighting vector `wv` is specified, the sum of weights is used rather than the
2523
raw counts.
2624
"""
27-
function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntUnitRange)
25+
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer})
2826
# add counts of integers from x that fall within levels to r
2927

3028
checkbounds(r, axes(levels)...)
3129

3230
m0 = first(levels)
3331
m1 = last(levels)
34-
b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::IntUnitRange
32+
b = m0 - firstindex(levels) # firstindex(levels) == 1 because levels::UnitRange{<:Integer}
3533

3634
@inbounds for xi in x
3735
if m0 <= xi <= m1
@@ -41,7 +39,7 @@ function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntUnitRange)
4139
return r
4240
end
4341

44-
function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntUnitRange, wv::AbstractWeights)
42+
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights)
4543
# add wv weighted counts of integers from x that fall within levels to r
4644

4745
length(x) == length(wv) ||
@@ -82,14 +80,14 @@ The output is a vector of length `length(levels)`.
8280
"""
8381
function counts end
8482

85-
counts(x::IntegerArray, levels::IntUnitRange) =
83+
counts(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) =
8684
addcounts!(zeros(Int, length(levels)), x, levels)
87-
counts(x::IntegerArray, levels::IntUnitRange, wv::AbstractWeights) =
85+
counts(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) =
8886
addcounts!(zeros(eltype(wv), length(levels)), x, levels, wv)
89-
counts(x::IntegerArray, k::Integer) = counts(x, 1:k)
90-
counts(x::IntegerArray, k::Integer, wv::AbstractWeights) = counts(x, 1:k, wv)
91-
counts(x::IntegerArray) = counts(x, span(x))
92-
counts(x::IntegerArray, wv::AbstractWeights) = counts(x, span(x), wv)
87+
counts(x::AbstractArray{<:Integer}, k::Integer) = counts(x, 1:k)
88+
counts(x::AbstractArray{<:Integer}, k::Integer, wv::AbstractWeights) = counts(x, 1:k, wv)
89+
counts(x::AbstractArray{<:Integer}) = counts(x, span(x))
90+
counts(x::AbstractArray{<:Integer}, wv::AbstractWeights) = counts(x, span(x), wv)
9391

9492

9593
"""
@@ -101,8 +99,8 @@ Equivalent to `counts(x, levels) / length(x)`.
10199
If a vector of weights `wv` is provided, the proportion of weights is computed rather
102100
than the proportion of raw counts.
103101
"""
104-
proportions(x::IntegerArray, levels::IntUnitRange) = counts(x, levels) .* inv(length(x))
105-
proportions(x::IntegerArray, levels::IntUnitRange, wv::AbstractWeights) =
102+
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) = counts(x, levels) .* inv(length(x))
103+
proportions(x::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) =
106104
counts(x, levels, wv) .* inv(sum(wv))
107105

108106
"""
@@ -113,14 +111,14 @@ Return the proportion of integers in 1 to `k` that occur in `x`.
113111
If a vector of weights `wv` is provided, the proportion of weights is computed rather
114112
than the proportion of raw counts.
115113
"""
116-
proportions(x::IntegerArray, k::Integer) = proportions(x, 1:k)
117-
proportions(x::IntegerArray, k::Integer, wv::AbstractWeights) = proportions(x, 1:k, wv)
118-
proportions(x::IntegerArray) = proportions(x, span(x))
119-
proportions(x::IntegerArray, wv::AbstractWeights) = proportions(x, span(x), wv)
114+
proportions(x::AbstractArray{<:Integer}, k::Integer) = proportions(x, 1:k)
115+
proportions(x::AbstractArray{<:Integer}, k::Integer, wv::AbstractWeights) = proportions(x, 1:k, wv)
116+
proportions(x::AbstractArray{<:Integer}) = proportions(x, span(x))
117+
proportions(x::AbstractArray{<:Integer}, wv::AbstractWeights) = proportions(x, span(x), wv)
120118

121119
#### functions for counting a single list of integers (2D)
122120

123-
function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange})
121+
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}})
124122
# add counts of pairs from zip(x,y) to r
125123

126124
xlevels, ylevels = levels
@@ -146,8 +144,8 @@ function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels::
146144
return r
147145
end
148146

149-
function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray,
150-
levels::NTuple{2,IntUnitRange}, wv::AbstractWeights)
147+
function addcounts!(r::AbstractArray, x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer},
148+
levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights)
151149
# add counts of pairs from zip(x,y) to r
152150

153151
length(x) == length(y) == length(wv) ||
@@ -182,43 +180,43 @@ end
182180

183181
# facet functions
184182

185-
function counts(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange})
183+
function counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}})
186184
addcounts!(zeros(Int, length(levels[1]), length(levels[2])), x, y, levels)
187185
end
188186

189-
function counts(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}, wv::AbstractWeights)
187+
function counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights)
190188
addcounts!(zeros(eltype(wv), length(levels[1]), length(levels[2])), x, y, levels, wv)
191189
end
192190

193-
counts(x::IntegerArray, y::IntegerArray, levels::IntUnitRange) =
191+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}) =
194192
counts(x, y, (levels, levels))
195-
counts(x::IntegerArray, y::IntegerArray, levels::IntUnitRange, wv::AbstractWeights) =
193+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::UnitRange{<:Integer}, wv::AbstractWeights) =
196194
counts(x, y, (levels, levels), wv)
197195

198-
counts(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}) =
196+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, ks::NTuple{2,Integer}) =
199197
counts(x, y, (1:ks[1], 1:ks[2]))
200-
counts(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}, wv::AbstractWeights) =
198+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, ks::NTuple{2,Integer}, wv::AbstractWeights) =
201199
counts(x, y, (1:ks[1], 1:ks[2]), wv)
202-
counts(x::IntegerArray, y::IntegerArray, k::Integer) = counts(x, y, (1:k, 1:k))
203-
counts(x::IntegerArray, y::IntegerArray, k::Integer, wv::AbstractWeights) =
200+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, k::Integer) = counts(x, y, (1:k, 1:k))
201+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, k::Integer, wv::AbstractWeights) =
204202
counts(x, y, (1:k, 1:k), wv)
205-
counts(x::IntegerArray, y::IntegerArray) = counts(x, y, (span(x), span(y)))
206-
counts(x::IntegerArray, y::IntegerArray, wv::AbstractWeights) = counts(x, y, (span(x), span(y)), wv)
203+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}) = counts(x, y, (span(x), span(y)))
204+
counts(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, wv::AbstractWeights) = counts(x, y, (span(x), span(y)), wv)
207205

208-
proportions(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}) =
206+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}) =
209207
counts(x, y, levels) .* inv(length(x))
210-
proportions(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}, wv::AbstractWeights) =
208+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, levels::NTuple{2,UnitRange{<:Integer}}, wv::AbstractWeights) =
211209
counts(x, y, levels, wv) .* inv(sum(wv))
212210

213-
proportions(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}) =
211+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, ks::NTuple{2,Integer}) =
214212
proportions(x, y, (1:ks[1], 1:ks[2]))
215-
proportions(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}, wv::AbstractWeights) =
213+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, ks::NTuple{2,Integer}, wv::AbstractWeights) =
216214
proportions(x, y, (1:ks[1], 1:ks[2]), wv)
217-
proportions(x::IntegerArray, y::IntegerArray, k::Integer) = proportions(x, y, (1:k, 1:k))
218-
proportions(x::IntegerArray, y::IntegerArray, k::Integer, wv::AbstractWeights) =
215+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, k::Integer) = proportions(x, y, (1:k, 1:k))
216+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, k::Integer, wv::AbstractWeights) =
219217
proportions(x, y, (1:k, 1:k), wv)
220-
proportions(x::IntegerArray, y::IntegerArray) = proportions(x, y, (span(x), span(y)))
221-
proportions(x::IntegerArray, y::IntegerArray, wv::AbstractWeights) =
218+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}) = proportions(x, y, (span(x), span(y)))
219+
proportions(x::AbstractArray{<:Integer}, y::AbstractArray{<:Integer}, wv::AbstractWeights) =
222220
proportions(x, y, (span(x), span(y)), wv)
223221

224222

src/cov.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ _scattermatm(x::DenseMatrix, wv::AbstractWeights, mean, dims::Int) =
9191

9292
## weighted cov
9393
covm(x::DenseMatrix, mean, w::AbstractWeights, dims::Int=1;
94-
corrected::DepBool=nothing) =
94+
corrected::Union{Bool, Nothing}=nothing) =
9595
rmul!(scattermat(x, w, mean=mean, dims=dims), varcorrection(w, depcheck(:covm, :corrected, corrected)))
9696

9797

98-
cov(x::DenseMatrix, w::AbstractWeights, dims::Int=1; corrected::DepBool=nothing) =
98+
cov(x::DenseMatrix, w::AbstractWeights, dims::Int=1; corrected::Union{Bool, Nothing}=nothing) =
9999
covm(x, mean(x, w, dims=dims), w, dims; corrected=depcheck(:cov, :corrected, corrected))
100100

101101
function corm(x::DenseMatrix, mean, w::AbstractWeights, vardim::Int=1)
@@ -118,7 +118,7 @@ function mean_and_cov(x::DenseMatrix, dims::Int=1; corrected::Bool=true)
118118
return m, covm(x, m, dims, corrected=corrected)
119119
end
120120
function mean_and_cov(x::DenseMatrix, wv::AbstractWeights, dims::Int=1;
121-
corrected::DepBool=nothing)
121+
corrected::Union{Bool, Nothing}=nothing)
122122
m = mean(x, wv, dims=dims)
123123
return m, cov(x, wv, dims; corrected=depcheck(:mean_and_cov, :corrected, corrected))
124124
end

src/deprecates.jl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ end
2727
@deprecate mean!(R::AbstractArray, A::AbstractArray, w::AbstractWeights, dims::Int) mean!(R, A, w, dims=dims)
2828
@deprecate mean(A::AbstractArray{T}, w::AbstractWeights{W}, dims::Int) where {T<:Number,W<:Real} mean(A, w, dims=dims)
2929

30-
@deprecate wquantile(v::RealVector, w::AbstractWeights{<:Real}, p::RealVector) quantile(v, w, p)
31-
@deprecate wquantile(v::RealVector, w::AbstractWeights{<:Real}, p::Number) quantile(v, w, [p])[1]
32-
@deprecate wquantile(v::RealVector, w::RealVector, p::RealVector) quantile(v, pweights(w), p)
33-
@deprecate wquantile(v::RealVector, w::RealVector, p::Number) quantile(v, pweights(w), [p])[1]
34-
@deprecate wmedian(v::RealVector, w::AbstractWeights{<:Real}) median(v, w)
35-
@deprecate wmedian(v::RealVector, w::RealVector) median(v, weights(w))
30+
@deprecate wquantile(v::AbstractVector{<:Real}, w::AbstractWeights{<:Real}, p::AbstractVector{<:Real}) quantile(v, w, p)
31+
@deprecate wquantile(v::AbstractVector{<:Real}, w::AbstractWeights{<:Real}, p::Number) quantile(v, w, [p])[1]
32+
@deprecate wquantile(v::AbstractVector{<:Real}, w::AbstractVector{<:Real}, p::AbstractVector{<:Real}) quantile(v, pweights(w), p)
33+
@deprecate wquantile(v::AbstractVector{<:Real}, w::AbstractVector{<:Real}, p::Number) quantile(v, pweights(w), [p])[1]
34+
@deprecate wmedian(v::AbstractVector{<:Real}, w::AbstractWeights{<:Real}) median(v, w)
35+
@deprecate wmedian(v::AbstractVector{<:Real}, w::AbstractVector{<:Real}) median(v, weights(w))
3636

3737
@deprecate quantile(v::AbstractArray{<:Real}) quantile(v, [.0, .25, .5, .75, 1.0])
3838

@@ -41,8 +41,8 @@ end
4141
@deprecate values(wv::AbstractWeights) convert(Vector, wv)
4242

4343
### Deprecated November 2021
44-
@deprecate stdm(x::RealArray, w::AbstractWeights, m::Real; corrected::DepBool=nothing) std(x, w, mean=m, corrected=corrected) false
45-
@deprecate varm(x::RealArray, w::AbstractWeights, m::Real; corrected::DepBool=nothing) var(x, w, mean=m, corrected=corrected) false
46-
@deprecate stdm(x::RealArray, w::AbstractWeights, m::RealArray, dim::Int; corrected::DepBool=nothing) std(x, w, dim, mean=m, corrected=corrected) false
47-
@deprecate varm(x::RealArray, w::AbstractWeights, m::RealArray, dim::Int; corrected::DepBool=nothing) var(x, w, dim, mean=m, corrected=corrected) false
48-
@deprecate varm!(R::AbstractArray, x::RealArray, w::AbstractWeights, m::RealArray, dim::Int; corrected::DepBool=nothing) var!(R, x, w, dim, mean=m, corrected=corrected) false
44+
@deprecate stdm(x::AbstractArray{<:Real}, w::AbstractWeights, m::Real; corrected::Union{Bool, Nothing}=nothing) std(x, w, mean=m, corrected=corrected) false
45+
@deprecate varm(x::AbstractArray{<:Real}, w::AbstractWeights, m::Real; corrected::Union{Bool, Nothing}=nothing) var(x, w, mean=m, corrected=corrected) false
46+
@deprecate stdm(x::AbstractArray{<:Real}, w::AbstractWeights, m::AbstractArray{<:Real}, dim::Int; corrected::Union{Bool, Nothing}=nothing) std(x, w, dim, mean=m, corrected=corrected) false
47+
@deprecate varm(x::AbstractArray{<:Real}, w::AbstractWeights, m::AbstractArray{<:Real}, dim::Int; corrected::Union{Bool, Nothing}=nothing) var(x, w, dim, mean=m, corrected=corrected) false
48+
@deprecate varm!(R::AbstractArray, x::AbstractArray{<:Real}, w::AbstractWeights, m::AbstractArray{<:Real}, dim::Int; corrected::Union{Bool, Nothing}=nothing) var!(R, x, w, dim, mean=m, corrected=corrected) false

src/empirical.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ function (ecdf::ECDF)(x::Real)
1616
partialsum / weightsum
1717
end
1818

19-
function (ecdf::ECDF)(v::RealVector)
19+
function (ecdf::ECDF)(v::AbstractVector{<:Real})
2020
evenweights = isempty(ecdf.weights)
2121
weightsum = evenweights ? length(ecdf.sorted_values) : sum(ecdf.weights)
2222
ord = sortperm(v)
@@ -53,7 +53,7 @@ evaluate CDF values on other samples.
5353
`extrema`, `minimum`, and `maximum` are supported to for obtaining the range over which
5454
function is inside the interval ``(0,1)``; the function is defined for the whole real line.
5555
"""
56-
function ecdf(X::RealVector; weights::AbstractVector{<:Real}=Weights(Float64[]))
56+
function ecdf(X::AbstractVector{<:Real}; weights::AbstractVector{<:Real}=Weights(Float64[]))
5757
any(isnan, X) && throw(ArgumentError("ecdf can not include NaN values"))
5858
isempty(weights) || length(X) == length(weights) || throw(ArgumentError("data and weight vectors must be the same size," *
5959
"got $(length(X)) and $(length(weights))"))

src/misc.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Reconstruct a vector from its run-length encoding (see [`rle`](@ref)).
5757
`vals` is a vector of the values and `lens` is a vector of the corresponding
5858
run lengths.
5959
"""
60-
function inverse_rle(vals::AbstractVector{T}, lens::IntegerVector) where T
60+
function inverse_rle(vals::AbstractVector{T}, lens::AbstractVector{<:Integer}) where T
6161
m = length(vals)
6262
length(lens) == m || raise_dimerror()
6363

@@ -131,7 +131,7 @@ julia> indicatormat([1 2 2], 2)
131131
0 1 1
132132
```
133133
"""
134-
function indicatormat(x::IntegerArray, k::Integer; sparse::Bool=false)
134+
function indicatormat(x::AbstractArray{<:Integer}, k::Integer; sparse::Bool=false)
135135
sparse ? _indicatormat_sparse(x, k) : _indicatormat_dense(x, k)
136136
end
137137

@@ -151,7 +151,7 @@ indicatormat(x::AbstractArray; sparse::Bool=false) =
151151
indicatormat(x, sort!(unique(x)); sparse=sparse)
152152

153153

154-
function _indicatormat_dense(x::IntegerArray, k::Integer)
154+
function _indicatormat_dense(x::AbstractArray{<:Integer}, k::Integer)
155155
n = length(x)
156156
r = zeros(Bool, k, n)
157157
for i = 1 : n
@@ -174,7 +174,7 @@ function _indicatormat_dense(x::AbstractArray{T}, c::AbstractArray{T}) where T
174174
return r
175175
end
176176

177-
_indicatormat_sparse(x::IntegerArray, k::Integer) = (n = length(x); sparse(x, 1:n, true, k, n))
177+
_indicatormat_sparse(x::AbstractArray{<:Integer}, k::Integer) = (n = length(x); sparse(x, 1:n, true, k, n))
178178

179179
function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T
180180
d = indexmap(c)
@@ -187,4 +187,3 @@ function _indicatormat_sparse(x::AbstractArray{T}, c::AbstractArray{T}) where T
187187
end
188188
return sparse(rinds, 1:n, true, m, n)
189189
end
190-

0 commit comments

Comments
 (0)