Skip to content

Commit

Permalink
Merge pull request JuliaLang#115 from Keno/pull-request/b00c1f5b
Browse files Browse the repository at this point in the history
Fix 0.3 deprecated types
  • Loading branch information
simonster committed Apr 29, 2015
2 parents 801f23f + b00c1f5 commit 23b36af
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/counts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()

Expand All @@ -47,23 +47,23 @@ 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))
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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 23b36af

Please sign in to comment.