From dbc3ced5e1392203282c59a179f61b560576ebae Mon Sep 17 00:00:00 2001 From: Seiji Kumagai Date: Wed, 8 Oct 2014 11:13:35 -0400 Subject: [PATCH] Dict{K,V}() instead of Dict{K,V}[] --- src/counts.jl | 6 +++--- src/misc.jl | 4 ++-- src/scalarstats.jl | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/counts.jl b/src/counts.jl index d292bf1bedfea3..b5625a38b0b32d 100644 --- a/src/counts.jl +++ b/src/counts.jl @@ -159,7 +159,7 @@ proportions(x::IntegerArray, y::IntegerArray, k::Integer, wv::WeightVec) = propo ## auxiliary functions function _normalize_countmap{T}(cm::Dict{T}, s::Real) - r = Dict{T,Float64}[] + r = Dict{T,Float64}() for (k, c) in cm r[k] = c / s end @@ -189,8 +189,8 @@ function addcounts!{T,W}(cm::Dict{T}, x::AbstractArray{T}, wv::WeightVec{W}) return cm end -countmap{T}(x::AbstractArray{T}) = addcounts!(Dict{T,Int}[], x) -countmap{T,W}(x::AbstractArray{T}, wv::WeightVec{W}) = addcounts!(Dict{T,W}[], x, wv) +countmap{T}(x::AbstractArray{T}) = addcounts!(Dict{T,Int}(), x) +countmap{T,W}(x::AbstractArray{T}, wv::WeightVec{W}) = addcounts!(Dict{T,W}(), x, wv) proportionmap(x::AbstractArray) = _normalize_countmap(countmap(x), length(x)) proportionmap(x::AbstractArray, wv::WeightVec) = _normalize_countmap(countmap(x, wv), sum(wv)) diff --git a/src/misc.jl b/src/misc.jl index 8c9a16252c915a..094c09591a5cda 100644 --- a/src/misc.jl +++ b/src/misc.jl @@ -63,7 +63,7 @@ end # findat (get positions (within a) for elements in b) function indexmap{T}(a::AbstractArray{T}) - d = Dict{T,Int}[] + d = Dict{T,Int}() for i = 1 : length(a) @inbounds k = a[i] if !haskey(d, k) @@ -74,7 +74,7 @@ function indexmap{T}(a::AbstractArray{T}) end function levelsmap{T}(a::AbstractArray{T}) - d = Dict{T,Int}[] + d = Dict{T,Int}() index = 1 for i = 1 : length(a) @inbounds k = a[i] diff --git a/src/scalarstats.jl b/src/scalarstats.jl index 589aa2ec495d95..8723a528d3dd14 100644 --- a/src/scalarstats.jl +++ b/src/scalarstats.jl @@ -95,7 +95,7 @@ end # compute mode over arbitrary array function mode{T}(a::AbstractArray{T}) isempty(a) && error("mode: input array cannot be empty.") - cnts = Dict{T,Int}[] + cnts = Dict{T,Int}() # first element mc = 1 mv = a[1] @@ -119,7 +119,7 @@ end function modes{T}(a::AbstractArray{T}) isempty(a) && error("modes: input array cannot be empty.") - cnts = Dict{T,Int}[] + cnts = Dict{T,Int}() # first element mc = 1 cnts[a[1]] = 1