From a0a08598917c9d8523b39e25c9fcf667e57c1e2d Mon Sep 17 00:00:00 2001 From: Tamas Nagy Date: Sun, 10 Jun 2018 15:57:18 -0700 Subject: [PATCH] use improved high numerical precision range from Base (#52) KernelDensity.jl rolled its own range generator which suffers from similar flaws as Base's linspace prior to being fixed in JuliaLang/julia#18777. This closes #39. --- src/univariate.jl | 3 +-- test/univariate.jl | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/univariate.jl b/src/univariate.jl index a82605cb..ae09eab6 100644 --- a/src/univariate.jl +++ b/src/univariate.jl @@ -66,8 +66,7 @@ function kde_range(boundary::Tuple{Real,Real}, npoints::Int) lo, hi = boundary lo < hi || error("boundary (a,b) must have a < b") - step = (hi - lo) / (npoints-1) - lo:step:hi + Compat.range(lo, stop=hi, length=npoints) end struct UniformWeights{N} end diff --git a/test/univariate.jl b/test/univariate.jl index dcefd08d..dd848950 100644 --- a/test/univariate.jl +++ b/test/univariate.jl @@ -13,6 +13,8 @@ end r = kde_range((-2.0,2.0), 128) @test step(r) > 0 +r2 = kde_range((0.12698109160784082, 0.9785547869337731), 256) +@test length(r2) == 256 for X in ([0.0], [0.0,0.0], [0.0,0.5], [-0.5:0.1:0.5;]) w = default_bandwidth(X)