Skip to content

Commit

Permalink
fix deprecations in Julia 0.7 (#96)
Browse files Browse the repository at this point in the history
* replace `uninitialized` by `undef`

* fix deprecation warnings for Julia 0.7

* Compat versions of sum, mean for 0.6

* Breaking with Julia 0.6, test with 0.7

This reverts commit d632a58
and updates REQUIRE and .travis.yml

* more 0.7 updates
  • Loading branch information
heliosdrm authored and KristofferC committed Jun 27, 2018
1 parent 840b285 commit c4431c0
Show file tree
Hide file tree
Showing 13 changed files with 47 additions and 40 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.jl.*.cov
*.jl.mem
*.ji
benchmark/params.jld
benchmark/params.jld
Manifest.toml
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ os:
- osx

julia:
- 0.6
- 0.7
- nightly

matrix:
Expand All @@ -18,9 +18,7 @@ notifications:
sudo: false

script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia -e 'Pkg.clone(pwd()); Pkg.build("Distances")'
- julia -e 'Pkg.test("Distances", coverage=true)'
- julia -e 'import Pkg; Pkg.build(); Pkg.test(; coverage=true)'

after_success:
- julia -e 'cd(Pkg.dir("Distances")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
10 changes: 10 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name = "Distances"
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
version = "0.7.0"

[deps]
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

[targets.test.deps]
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
3 changes: 1 addition & 2 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
julia 0.6
Compat 0.54.0
julia 0.7-
3 changes: 1 addition & 2 deletions src/Distances.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ __precompile__()

module Distances

using Compat
using Compat.LinearAlgebra
using LinearAlgebra

export
# generic types/functions
Expand Down
6 changes: 3 additions & 3 deletions src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ end
function sumsq_percol(a::AbstractMatrix{T}) where {T}
m = size(a, 1)
n = size(a, 2)
r = Vector{T}(uninitialized, n)
r = Vector{T}(undef, n)
for j = 1:n
aj = view(a, :, j)
r[j] = dot(aj, aj)
Expand All @@ -113,7 +113,7 @@ function wsumsq_percol(w::AbstractArray{T1}, a::AbstractMatrix{T2}) where {T1, T
m = size(a, 1)
n = size(a, 2)
T = typeof(one(T1) * one(T2))
r = Vector{T}(uninitialized, n)
r = Vector{T}(undef, n)
for j = 1:n
aj = view(a, :, j)
s = zero(T)
Expand All @@ -138,4 +138,4 @@ function dot_percol!(r::AbstractArray, a::AbstractMatrix, b::AbstractMatrix)
return r
end

dot_percol(a::AbstractMatrix, b::AbstractMatrix) = dot_percol!(Vector{Float64}(size(a, 2)), a, b)
dot_percol(a::AbstractMatrix, b::AbstractMatrix) = dot_percol!(Vector{Float64}(undef, size(a, 2)), a, b)
10 changes: 5 additions & 5 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,19 @@ end

function colwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix)
n = get_common_ncols(a, b)
r = Vector{result_type(metric, a, b)}(uninitialized, n)
r = Vector{result_type(metric, a, b)}(undef, n)
colwise!(r, metric, a, b)
end

function colwise(metric::PreMetric, a::AbstractVector, b::AbstractMatrix)
n = size(b, 2)
r = Vector{result_type(metric, a, b)}(uninitialized, n)
r = Vector{result_type(metric, a, b)}(undef, n)
colwise!(r, metric, a, b)
end

function colwise(metric::PreMetric, a::AbstractMatrix, b::AbstractVector)
n = size(a, 2)
r = Vector{result_type(metric, a, b)}(uninitialized, n)
r = Vector{result_type(metric, a, b)}(undef, n)
colwise!(r, metric, a, b)
end

Expand Down Expand Up @@ -117,12 +117,12 @@ end
function pairwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix)
m = size(a, 2)
n = size(b, 2)
r = Matrix{result_type(metric, a, b)}(uninitialized, m, n)
r = Matrix{result_type(metric, a, b)}(undef, m, n)
pairwise!(r, metric, a, b)
end

function pairwise(metric::PreMetric, a::AbstractMatrix)
n = size(a, 2)
r = Matrix{result_type(metric, a, a)}(uninitialized, n, n)
r = Matrix{result_type(metric, a, a)}(undef, n, n)
pairwise!(r, metric, a)
end
6 changes: 3 additions & 3 deletions src/mahalanobis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function evaluate(dist::SqMahalanobis{T}, a::AbstractVector, b::AbstractVector)
if length(a) != length(b)
throw(DimensionMismatch("first array has length $(length(a)) which does not match the length of the second, $(length(b))."))
end

Q = dist.qmat
z = a - b
return dot(z, Q * z)
Expand Down Expand Up @@ -48,7 +48,7 @@ function pairwise!(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix,
Qb = Q * b
sa2 = dot_percol(a, Qa)
sb2 = dot_percol(b, Qb)
At_mul_B!(r, a, Qb)
mul!(r, a', Qb)

for j = 1:nb
@simd for i = 1:na
Expand All @@ -64,7 +64,7 @@ function pairwise!(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix)

Qa = Q * a
sa2 = dot_percol(a, Qa)
At_mul_B!(r, a, Qa)
mul!(r, a', Qa)

for j = 1:n
for i = 1:(j - 1)
Expand Down
18 changes: 9 additions & 9 deletions src/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,9 +455,9 @@ nrmsd(a, b) = evaluate(NormRMSDeviation(), a, b)

# SqEuclidean
function pairwise!(r::AbstractMatrix, dist::SqEuclidean, a::AbstractMatrix, b::AbstractMatrix)
At_mul_B!(r, a, b)
sa2 = sum(abs2, a, 1)
sb2 = sum(abs2, b, 1)
mul!(r, a', b)
sa2 = sum(abs2, a, dims=1)
sb2 = sum(abs2, b, dims=1)
threshT = convert(eltype(r), dist.thresh)
if threshT <= 0
# If there's no chance of triggering the threshold, we can use @simd
Expand Down Expand Up @@ -492,7 +492,7 @@ end

function pairwise!(r::AbstractMatrix, dist::SqEuclidean, a::AbstractMatrix)
m, n = get_pairwise_dims(r, a)
At_mul_B!(r, a, a)
mul!(r, a', a)
sa2 = sumsq_percol(a)
threshT = convert(eltype(r), dist.thresh)
@inbounds for j = 1:n
Expand Down Expand Up @@ -525,7 +525,7 @@ end
# Euclidean
function pairwise!(r::AbstractMatrix, dist::Euclidean, a::AbstractMatrix, b::AbstractMatrix)
m, na, nb = get_pairwise_dims(r, a, b)
At_mul_B!(r, a, b)
mul!(r, a', b)
sa2 = sumsq_percol(a)
sb2 = sumsq_percol(b)
threshT = convert(eltype(r), dist.thresh)
Expand All @@ -552,7 +552,7 @@ end

function pairwise!(r::AbstractMatrix, dist::Euclidean, a::AbstractMatrix)
m, n = get_pairwise_dims(r, a)
At_mul_B!(r, a, a)
mul!(r, a', a)
sa2 = sumsq_percol(a)
threshT = convert(eltype(r), dist.thresh)
@inbounds for j = 1:n
Expand Down Expand Up @@ -580,7 +580,7 @@ end

function pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix, b::AbstractMatrix)
m, na, nb = get_pairwise_dims(r, a, b)
At_mul_B!(r, a, b)
mul!(r, a', b)
ra = sqrt!(sumsq_percol(a))
rb = sqrt!(sumsq_percol(b))
for j = 1:nb
Expand All @@ -592,7 +592,7 @@ function pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix, b::Ab
end
function pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix)
m, n = get_pairwise_dims(r, a)
At_mul_B!(r, a, a)
mul!(r, a', a)
ra = sqrt!(sumsq_percol(a))
@inbounds for j = 1:n
@simd for i = j + 1:n
Expand All @@ -608,7 +608,7 @@ end

# CorrDist
_centralize_colwise(x::AbstractVector) = x .- mean(x)
_centralize_colwise(x::AbstractMatrix) = x .- mean(x, 1)
_centralize_colwise(x::AbstractMatrix) = x .- mean(x, dims=1)
function colwise!(r::AbstractVector, dist::CorrDist, a::AbstractMatrix, b::AbstractMatrix)
colwise!(r, CosineDist(), _centralize_colwise(a), _centralize_colwise(b))
end
Expand Down
4 changes: 2 additions & 2 deletions src/wmetrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function pairwise!(r::AbstractMatrix, dist::WeightedSqEuclidean, a::AbstractMatr

sa2 = wsumsq_percol(w, a)
sb2 = wsumsq_percol(w, b)
At_mul_B!(r, a, b .* w)
mul!(r, a', b .* w)
for j = 1:nb
@simd for i = 1:na
@inbounds r[i, j] = sa2[i] + sb2[j] - 2 * r[i, j]
Expand All @@ -136,7 +136,7 @@ function pairwise!(r::AbstractMatrix, dist::WeightedSqEuclidean, a::AbstractMatr
m, n = get_pairwise_dims(length(w), r, a)

sa2 = wsumsq_percol(w, a)
At_mul_B!(r, a, a .* w)
mul!(r, a', a .* w)

for j = 1:n
for i = 1:(j - 1)
Expand Down
1 change: 0 additions & 1 deletion test/REQUIRE

This file was deleted.

7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Distances
using Compat.Test
using Compat.LinearAlgebra
using Compat.Random

using Test
using LinearAlgebra
using Random

include("F64.jl")
include("test_dists.jl")
8 changes: 4 additions & 4 deletions test/test_dists.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ end
p = rand(T, n)
q = rand(T, n)
r = rand(T, n)
p[p .< median(p)] = 0
p[p .< median(p)] .= 0
p /= sum(p)
q /= sum(q)
r /= sum(r)
Expand Down Expand Up @@ -189,7 +189,7 @@ end
# Test KL, Renyi and JS divergences
r = rand(T, 12)
p = copy(r)
p[p .< median(p)] = 0.0
p[p .< median(p)] .= 0.0
scale = sum(p) / sum(r)
r /= sum(r)
p /= sum(p)
Expand Down Expand Up @@ -310,7 +310,7 @@ end
a = T.([1.0, 2.0, 1.0, 3.0, 2.0, 1.0])
b = T.([1.0, 3.0, 0.0, 2.0, 2.0, 0.0])
p = rand(T, 12)
p[p .< median(p)] = 0.0
p[p .< median(p)] .= 0.0
q = rand(T, 12)

# Bhattacharyya and Hellinger distances are defined for discrete
Expand Down Expand Up @@ -373,7 +373,7 @@ end
Q = rand(T, m, n)
# Make sure not to remove all of the non-zeros from any column
for i in 1:n
P[P[:, i] .< median(P[:, i]) / 2, i] = 0.0
P[P[:, i] .< median(P[:, i]) / 2, i] .= 0.0
end

test_colwise(SqEuclidean(), X, Y, T)
Expand Down

0 comments on commit c4431c0

Please sign in to comment.