Skip to content

Commit

Permalink
Fix deprecations (#48)
Browse files Browse the repository at this point in the history
  • Loading branch information
femtocleaner[bot] authored and ararslan committed Oct 21, 2017
1 parent 89d8b94 commit a688ceb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/KernelDensity.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 4 additions & 8 deletions src/bivariate.jl
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/interp.jl
Original file line number Diff line number Diff line change
@@ -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


Expand Down
12 changes: 6 additions & 6 deletions src/univariate.jl
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a688ceb

Please sign in to comment.