From a688cebc81cea8c0b72a5db7eda1c3472d7a6fc5 Mon Sep 17 00:00:00 2001 From: "femtocleaner[bot]" Date: Sat, 21 Oct 2017 13:23:10 -0700 Subject: [PATCH] Fix deprecations (#48) --- src/KernelDensity.jl | 2 +- src/bivariate.jl | 12 ++++-------- src/interp.jl | 4 ++-- src/univariate.jl | 12 ++++++------ 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/KernelDensity.jl b/src/KernelDensity.jl index 93a5df1c..26aca568 100644 --- a/src/KernelDensity.jl +++ b/src/KernelDensity.jl @@ -14,7 +14,7 @@ import Distributions: twoπ, pdf export kde, kde_lscv, UnivariateKDE, BivariateKDE, InterpKDE, pdf -@compat abstract type AbstractKDE end +abstract type AbstractKDE end include("univariate.jl") include("bivariate.jl") diff --git a/src/bivariate.jl b/src/bivariate.jl index 6a9a4ae4..407e3154 100644 --- a/src/bivariate.jl +++ b/src/bivariate.jl @@ -1,22 +1,18 @@ # Store both grid and density for KDE over R2 -type BivariateKDE{Rx<:Range,Ry<:Range} <: AbstractKDE +mutable struct BivariateKDE{Rx<:Range,Ry<:Range} <: AbstractKDE x::Rx y::Ry density::Matrix{Float64} end -function kernel_dist{D<:UnivariateDistribution}(::Type{D},w::Tuple{Real,Real}) +function kernel_dist(::Type{D},w::Tuple{Real,Real}) where D<:UnivariateDistribution kernel_dist(D,w[1]), kernel_dist(D,w[2]) end -function kernel_dist{Dx<:UnivariateDistribution,Dy<:UnivariateDistribution}(::Type{Tuple{Dx, Dy}},w::Tuple{Real,Real}) +function kernel_dist(::Type{Tuple{Dx, Dy}},w::Tuple{Real,Real}) where {Dx<:UnivariateDistribution,Dy<:UnivariateDistribution} kernel_dist(Dx,w[1]), kernel_dist(Dy,w[2]) end -if VERSION >= v"0.6.0-dev.2123" - const DataTypeOrUnionAll = Union{DataType, UnionAll} -else - const DataTypeOrUnionAll = DataType -end +const DataTypeOrUnionAll = Union{DataType, UnionAll} # this function provided for backwards compatibility, though it doesn't have the type restrictions # to ensure that the given tuple only contains univariate distributions diff --git a/src/interp.jl b/src/interp.jl index b8ae3ab0..0d5d8674 100644 --- a/src/interp.jl +++ b/src/interp.jl @@ -1,9 +1,9 @@ import Interpolations: interpolate, scale -type InterpKDE{K,I} <: AbstractKDE +mutable struct InterpKDE{K,I} <: AbstractKDE kde::K itp::I - @compat (::Type{InterpKDE{K,I}}){K,I}(kde::K, itp::I) = new{K,I}(kde, itp) + InterpKDE{K,I}(kde::K, itp::I) where {K,I} = new{K,I}(kde, itp) end diff --git a/src/univariate.jl b/src/univariate.jl index 9bea4ad9..b495aa06 100644 --- a/src/univariate.jl +++ b/src/univariate.jl @@ -1,5 +1,5 @@ # Store both grid and density for KDE over the real line -type UnivariateKDE{R<:Range} <: AbstractKDE +mutable struct UnivariateKDE{R<:Range} <: AbstractKDE x::R density::Vector{Float64} end @@ -9,7 +9,7 @@ kernel_dist(::Type{Normal},w::Real) = Normal(0.0,w) kernel_dist(::Type{Uniform},w::Real) = (s = 1.7320508075688772*w; Uniform(-s,s)) const LocationScale = Union{Laplace,Logistic,SymTriangularDist} -kernel_dist{D}(::Type{D},w::Real) = (s = w/std(D(0.0,1.0)); D(0.0,s)) +kernel_dist(::Type{D},w::Real) where {D} = (s = w/std(D(0.0,1.0)); D(0.0,s)) # Silverman's rule of thumb for KDE bandwidth selection @@ -70,14 +70,14 @@ function kde_range(boundary::Tuple{Real,Real}, npoints::Int) lo:step:hi end -immutable UniformWeights{N} end +struct UniformWeights{N} end UniformWeights(n) = UniformWeights{n}() Base.sum(x::UniformWeights) = 1. -Base.getindex{N}(x::UniformWeights{N}, i) = 1/N +Base.getindex(x::UniformWeights{N}, i) where {N} = 1/N -typealias Weights Union{UniformWeights, RealVector, WeightVec} +const Weights = Union{UniformWeights, RealVector, WeightVec} # tabulate data for kde @@ -175,7 +175,7 @@ function kde_lscv(data::RealVector, midpoints::Range; K = length(k.density) ft = rfft(k.density) - ft2 = @compat(abs2.(ft)) + ft2 = abs2.(ft) c = -twoπ/(step(k.x)*K) hlb, hub = bandwidth_range