Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

work around perf regression on 0.7 #101

Merged
merged 1 commit into from
Jul 23, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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