Skip to content

Commit c4431c0

Browse files
heliosdrmKristofferC
authored andcommitted
fix deprecations in Julia 0.7 (#96)
* 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
1 parent 840b285 commit c4431c0

File tree

13 files changed

+47
-40
lines changed

13 files changed

+47
-40
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
*.jl.*.cov
33
*.jl.mem
44
*.ji
5-
benchmark/params.jld
5+
benchmark/params.jld
6+
Manifest.toml

.travis.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ os:
55
- osx
66

77
julia:
8-
- 0.6
8+
- 0.7
99
- nightly
1010

1111
matrix:
@@ -18,9 +18,7 @@ notifications:
1818
sudo: false
1919

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

2523
after_success:
26-
- julia -e 'cd(Pkg.dir("Distances")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'
24+
- julia -e 'import Pkg; Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'

Project.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "Distances"
2+
uuid = "b4f34e82-e78d-54a5-968a-f98e89d6e8f7"
3+
version = "0.7.0"
4+
5+
[deps]
6+
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
7+
8+
[targets.test.deps]
9+
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
10+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

REQUIRE

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
julia 0.6
2-
Compat 0.54.0
1+
julia 0.7-

src/Distances.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ __precompile__()
22

33
module Distances
44

5-
using Compat
6-
using Compat.LinearAlgebra
5+
using LinearAlgebra
76

87
export
98
# generic types/functions

src/common.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ end
101101
function sumsq_percol(a::AbstractMatrix{T}) where {T}
102102
m = size(a, 1)
103103
n = size(a, 2)
104-
r = Vector{T}(uninitialized, n)
104+
r = Vector{T}(undef, n)
105105
for j = 1:n
106106
aj = view(a, :, j)
107107
r[j] = dot(aj, aj)
@@ -113,7 +113,7 @@ function wsumsq_percol(w::AbstractArray{T1}, a::AbstractMatrix{T2}) where {T1, T
113113
m = size(a, 1)
114114
n = size(a, 2)
115115
T = typeof(one(T1) * one(T2))
116-
r = Vector{T}(uninitialized, n)
116+
r = Vector{T}(undef, n)
117117
for j = 1:n
118118
aj = view(a, :, j)
119119
s = zero(T)
@@ -138,4 +138,4 @@ function dot_percol!(r::AbstractArray, a::AbstractMatrix, b::AbstractMatrix)
138138
return r
139139
end
140140

141-
dot_percol(a::AbstractMatrix, b::AbstractMatrix) = dot_percol!(Vector{Float64}(size(a, 2)), a, b)
141+
dot_percol(a::AbstractMatrix, b::AbstractMatrix) = dot_percol!(Vector{Float64}(undef, size(a, 2)), a, b)

src/generic.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,19 @@ end
6262

6363
function colwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix)
6464
n = get_common_ncols(a, b)
65-
r = Vector{result_type(metric, a, b)}(uninitialized, n)
65+
r = Vector{result_type(metric, a, b)}(undef, n)
6666
colwise!(r, metric, a, b)
6767
end
6868

6969
function colwise(metric::PreMetric, a::AbstractVector, b::AbstractMatrix)
7070
n = size(b, 2)
71-
r = Vector{result_type(metric, a, b)}(uninitialized, n)
71+
r = Vector{result_type(metric, a, b)}(undef, n)
7272
colwise!(r, metric, a, b)
7373
end
7474

7575
function colwise(metric::PreMetric, a::AbstractMatrix, b::AbstractVector)
7676
n = size(a, 2)
77-
r = Vector{result_type(metric, a, b)}(uninitialized, n)
77+
r = Vector{result_type(metric, a, b)}(undef, n)
7878
colwise!(r, metric, a, b)
7979
end
8080

@@ -117,12 +117,12 @@ end
117117
function pairwise(metric::PreMetric, a::AbstractMatrix, b::AbstractMatrix)
118118
m = size(a, 2)
119119
n = size(b, 2)
120-
r = Matrix{result_type(metric, a, b)}(uninitialized, m, n)
120+
r = Matrix{result_type(metric, a, b)}(undef, m, n)
121121
pairwise!(r, metric, a, b)
122122
end
123123

124124
function pairwise(metric::PreMetric, a::AbstractMatrix)
125125
n = size(a, 2)
126-
r = Matrix{result_type(metric, a, a)}(uninitialized, n, n)
126+
r = Matrix{result_type(metric, a, a)}(undef, n, n)
127127
pairwise!(r, metric, a)
128128
end

src/mahalanobis.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function evaluate(dist::SqMahalanobis{T}, a::AbstractVector, b::AbstractVector)
1717
if length(a) != length(b)
1818
throw(DimensionMismatch("first array has length $(length(a)) which does not match the length of the second, $(length(b))."))
1919
end
20-
20+
2121
Q = dist.qmat
2222
z = a - b
2323
return dot(z, Q * z)
@@ -48,7 +48,7 @@ function pairwise!(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix,
4848
Qb = Q * b
4949
sa2 = dot_percol(a, Qa)
5050
sb2 = dot_percol(b, Qb)
51-
At_mul_B!(r, a, Qb)
51+
mul!(r, a', Qb)
5252

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

6565
Qa = Q * a
6666
sa2 = dot_percol(a, Qa)
67-
At_mul_B!(r, a, Qa)
67+
mul!(r, a', Qa)
6868

6969
for j = 1:n
7070
for i = 1:(j - 1)

src/metrics.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -455,9 +455,9 @@ nrmsd(a, b) = evaluate(NormRMSDeviation(), a, b)
455455

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

493493
function pairwise!(r::AbstractMatrix, dist::SqEuclidean, a::AbstractMatrix)
494494
m, n = get_pairwise_dims(r, a)
495-
At_mul_B!(r, a, a)
495+
mul!(r, a', a)
496496
sa2 = sumsq_percol(a)
497497
threshT = convert(eltype(r), dist.thresh)
498498
@inbounds for j = 1:n
@@ -525,7 +525,7 @@ end
525525
# Euclidean
526526
function pairwise!(r::AbstractMatrix, dist::Euclidean, a::AbstractMatrix, b::AbstractMatrix)
527527
m, na, nb = get_pairwise_dims(r, a, b)
528-
At_mul_B!(r, a, b)
528+
mul!(r, a', b)
529529
sa2 = sumsq_percol(a)
530530
sb2 = sumsq_percol(b)
531531
threshT = convert(eltype(r), dist.thresh)
@@ -552,7 +552,7 @@ end
552552

553553
function pairwise!(r::AbstractMatrix, dist::Euclidean, a::AbstractMatrix)
554554
m, n = get_pairwise_dims(r, a)
555-
At_mul_B!(r, a, a)
555+
mul!(r, a', a)
556556
sa2 = sumsq_percol(a)
557557
threshT = convert(eltype(r), dist.thresh)
558558
@inbounds for j = 1:n
@@ -580,7 +580,7 @@ end
580580

581581
function pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix, b::AbstractMatrix)
582582
m, na, nb = get_pairwise_dims(r, a, b)
583-
At_mul_B!(r, a, b)
583+
mul!(r, a', b)
584584
ra = sqrt!(sumsq_percol(a))
585585
rb = sqrt!(sumsq_percol(b))
586586
for j = 1:nb
@@ -592,7 +592,7 @@ function pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix, b::Ab
592592
end
593593
function pairwise!(r::AbstractMatrix, dist::CosineDist, a::AbstractMatrix)
594594
m, n = get_pairwise_dims(r, a)
595-
At_mul_B!(r, a, a)
595+
mul!(r, a', a)
596596
ra = sqrt!(sumsq_percol(a))
597597
@inbounds for j = 1:n
598598
@simd for i = j + 1:n
@@ -608,7 +608,7 @@ end
608608

609609
# CorrDist
610610
_centralize_colwise(x::AbstractVector) = x .- mean(x)
611-
_centralize_colwise(x::AbstractMatrix) = x .- mean(x, 1)
611+
_centralize_colwise(x::AbstractMatrix) = x .- mean(x, dims=1)
612612
function colwise!(r::AbstractVector, dist::CorrDist, a::AbstractMatrix, b::AbstractMatrix)
613613
colwise!(r, CosineDist(), _centralize_colwise(a), _centralize_colwise(b))
614614
end

src/wmetrics.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ function pairwise!(r::AbstractMatrix, dist::WeightedSqEuclidean, a::AbstractMatr
123123

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

138138
sa2 = wsumsq_percol(w, a)
139-
At_mul_B!(r, a, a .* w)
139+
mul!(r, a', a .* w)
140140

141141
for j = 1:n
142142
for i = 1:(j - 1)

0 commit comments

Comments
 (0)