diff --git a/src/counts.jl b/src/counts.jl index 0c4dbb14e2cf7b..fcedab5a56f53a 100644 --- a/src/counts.jl +++ b/src/counts.jl @@ -6,11 +6,11 @@ # ################################################# -typealias IntRange1{T<:Integer} Range1{T} +typealias IntUnitRange{T<:Integer} UnitRange{T} #### functions for counting a single list of integers (1D) -function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntRange1) +function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntUnitRange) # add counts of integers from x to r k = length(levels) @@ -29,7 +29,7 @@ function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntRange1) return r end -function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntRange1, wv::WeightVec) +function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntUnitRange, wv::WeightVec) k = length(levels) length(r) == k || raise_dimerror() @@ -47,15 +47,15 @@ function addcounts!(r::AbstractArray, x::IntegerArray, levels::IntRange1, wv::We return r end -counts(x::IntegerArray, levels::IntRange1) = addcounts!(zeros(Int, length(levels)), x, levels) -counts(x::IntegerArray, levels::IntRange1, wv::WeightVec) = addcounts!(zeros(eltype(wv), length(levels)), x, levels, wv) +counts(x::IntegerArray, levels::IntUnitRange) = addcounts!(zeros(Int, length(levels)), x, levels) +counts(x::IntegerArray, levels::IntUnitRange, wv::WeightVec) = addcounts!(zeros(eltype(wv), length(levels)), x, levels, wv) counts(x::IntegerArray, k::Integer) = counts(x, 1:k) counts(x::IntegerArray, k::Integer, wv::WeightVec) = counts(x, 1:k, wv) counts(x::IntegerArray) = counts(x, span(x)) counts(x::IntegerArray, wv::WeightVec) = counts(x, span(x), wv) -proportions(x::IntegerArray, levels::IntRange1) = counts(x, levels) .* inv(length(x)) -proportions(x::IntegerArray, levels::IntRange1, wv::WeightVec) = counts(x, levels, wv) .* inv(sum(wv)) +proportions(x::IntegerArray, levels::IntUnitRange) = counts(x, levels) .* inv(length(x)) +proportions(x::IntegerArray, levels::IntUnitRange, wv::WeightVec) = counts(x, levels, wv) .* inv(sum(wv)) proportions(x::IntegerArray, k::Integer) = proportions(x, 1:k) proportions(x::IntegerArray, k::Integer, wv::WeightVec) = proportions(x, 1:k, wv) proportions(x::IntegerArray) = proportions(x, span(x)) @@ -63,7 +63,7 @@ proportions(x::IntegerArray, wv::WeightVec) = proportions(x, span(x), wv) #### functions for counting a single list of integers (2D) -function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntRange1}) +function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}) # add counts of integers from x to r n = length(x) @@ -93,7 +93,7 @@ function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels:: return r end -function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntRange1}, wv::WeightVec) +function addcounts!(r::AbstractArray, x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}, wv::WeightVec) # add counts of integers from x to r n = length(x) @@ -126,16 +126,16 @@ end # facet functions -function counts(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntRange1}) +function counts(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}) addcounts!(zeros(Int, length(levels[1]), length(levels[2])), x, y, levels) end -function counts(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntRange1}, wv::WeightVec) +function counts(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}, wv::WeightVec) addcounts!(zeros(eltype(wv), length(levels[1]), length(levels[2])), x, y, levels, wv) end -counts(x::IntegerArray, y::IntegerArray, levels::IntRange1) = counts(x, y, (levels, levels)) -counts(x::IntegerArray, y::IntegerArray, levels::IntRange1, wv::WeightVec) = counts(x, y, (levels, levels), wv) +counts(x::IntegerArray, y::IntegerArray, levels::IntUnitRange) = counts(x, y, (levels, levels)) +counts(x::IntegerArray, y::IntegerArray, levels::IntUnitRange, wv::WeightVec) = counts(x, y, (levels, levels), wv) counts(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}) = counts(x, y, (1:ks[1], 1:ks[2])) counts(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}, wv::WeightVec) = counts(x, y, (1:ks[1], 1:ks[2]), wv) @@ -144,8 +144,8 @@ counts(x::IntegerArray, y::IntegerArray, k::Integer, wv::WeightVec) = counts(x, counts(x::IntegerArray, y::IntegerArray) = counts(x, y, (span(x), span(y))) counts(x::IntegerArray, y::IntegerArray, wv::WeightVec) = counts(x, y, (span(x), span(y)), wv) -proportions(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntRange1}) = counts(x, y, levels) .* inv(length(x)) -proportions(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntRange1}, wv::WeightVec) = counts(x, y, levels, wv) .* inv(sum(wv)) +proportions(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}) = counts(x, y, levels) .* inv(length(x)) +proportions(x::IntegerArray, y::IntegerArray, levels::NTuple{2,IntUnitRange}, wv::WeightVec) = counts(x, y, levels, wv) .* inv(sum(wv)) proportions(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}) = proportions(x, y, (1:ks[1], 1:ks[2])) proportions(x::IntegerArray, y::IntegerArray, ks::NTuple{2,Integer}, wv::WeightVec) = proportions(x, y, (1:ks[1], 1:ks[2]), wv)