Skip to content

Commit

Permalink
work around perf regression on 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jul 23, 2018
1 parent 0257f33 commit 8aef56d
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 7 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.7.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"

[targets.test.deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Expand Down
1 change: 1 addition & 0 deletions src/Distances.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ __precompile__()
module Distances

using LinearAlgebra
using Statistics

export
# generic types/functions
Expand Down
2 changes: 1 addition & 1 deletion src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ const ArraySlice{T} = SubArray{T,1,Array{T,2},Tuple{Base.Slice{Base.OneTo{Int}},
end
@inbounds begin
s = eval_start(d, a, b)
@simd for I in eachindex(a, b)
@simd for I in 1:length(a)
ai = a[I]
bi = b[I]
s = eval_reduce(d, s, eval_op(d, ai, bi))
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ using Distances
using Test
using LinearAlgebra
using Random
using Statistics

include("F64.jl")
include("test_dists.jl")
27 changes: 21 additions & 6 deletions test/test_dists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -511,9 +511,9 @@ end
end

@testset "Bregman Divergence" begin
# Some basic tests.
# Some basic tests.
@test_throws ArgumentError bregman(x -> x, x -> 2*x, [1, 2, 3], [1, 2, 3])
# Test if Bregman() correctly implements the gkl divergence between two random vectors.
# Test if Bregman() correctly implements the gkl divergence between two random vectors.
F(p) = LinearAlgebra.dot(p, log.(p));
(p) = map(x -> log(x) + 1, p)
testDist = Bregman(F, ∇)
Expand All @@ -522,13 +522,28 @@ end
p = p/sum(p);
q = q/sum(q);
@test evaluate(testDist, p, q) gkl_divergence(p, q)
# Test if Bregman() correctly implements the squared euclidean dist. between them.
# Test if Bregman() correctly implements the squared euclidean dist. between them.
@test bregman(x -> norm(x)^2, x -> 2*x, p, q) sqeuclidean(p, q)
# Test if Bregman() correctly implements the IS distance.
# Test if Bregman() correctly implements the IS distance.
F(p) = -1 * sum(log.(p))
(p) = map(x -> -1 * x^(-1), p)
function ISdist(p::AbstractVector, q::AbstractVector)
return sum([p[i]/q[i] - log(p[i]/q[i]) - 1 for i in 1:length(p)])
end
@test bregman(F, ∇, p, q) ISdist(p, q)
end
@test bregman(F, ∇, p, q) ISdist(p, q)
end

@testset "zero allocation colwise!" begin
d = Euclidean()
a = rand(2, 41)
b = rand(2, 41)
z = zeros(41)
colwise!(z, d, a, b)
# This fails when bounds checking is enforced
bounds = Base.JLOptions().check_bounds
if bounds == 0
@test (@allocated colwise!(z, d, a, b)) == 0
else
@test_broken (@allocated colwise!(z, d, a, b)) == 0
end
end

0 comments on commit 8aef56d

Please sign in to comment.