Skip to content

Commit dd59e65

Browse files
authored
fix deprecation warnings for new where syntax (#73)
* move to 0.6 * use function instead of macro in tests
1 parent ac2fe10 commit dd59e65

File tree

11 files changed

+186
-238
lines changed

11 files changed

+186
-238
lines changed

.travis.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
language: julia
2+
23
os:
34
- linux
45
- osx
6+
57
julia:
6-
- 0.5
8+
- 0.6
79
- nightly
10+
11+
matrix:
12+
allow_failures:
13+
- julia: nightly
14+
815
notifications:
916
email: false
17+
1018
sudo: false
19+
1120
script:
1221
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
1322
- julia -e 'Pkg.clone(pwd()); Pkg.build("Distances")'
1423
- julia -e 'Pkg.test("Distances", coverage=true)'
24+
1525
after_success:
1626
- julia -e 'cd(Pkg.dir("Distances")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder())'

REQUIRE

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

src/Distances.jl

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ __precompile__()
22

33
module Distances
44

5-
using Compat
6-
75
export
86
# generic types/functions
97
PreMetric,

src/bhattacharyya.jl

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22
# be compared are probability distributions, frequencies or counts rather than
33
# vectors of samples. Pre-calc accordingly if you have samples.
44

5-
type BhattacharyyaDist <: SemiMetric end
5+
struct BhattacharyyaDist <: SemiMetric end
66

7-
type HellingerDist <: Metric end
7+
struct HellingerDist <: Metric end
88

99

1010
# Bhattacharyya coefficient
1111

12-
function bhattacharyya_coeff{T<:Number}(a::AbstractVector{T}, b::AbstractVector{T})
12+
function bhattacharyya_coeff(a::AbstractVector{T}, b::AbstractVector{T}) where {T <: Number}
1313
if length(a) != length(b)
1414
throw(DimensionMismatch("first array has length $(length(a)) which does not match the length of the second, $(length(b))."))
1515
end
@@ -31,19 +31,19 @@ function bhattacharyya_coeff{T<:Number}(a::AbstractVector{T}, b::AbstractVector{
3131
sqab / sqrt(asum * bsum)
3232
end
3333

34-
bhattacharyya_coeff{T <: Number}(a::T, b::T) = throw("Bhattacharyya coefficient cannot be calculated for scalars")
34+
bhattacharyya_coeff(a::T, b::T) where {T <: Number} = throw("Bhattacharyya coefficient cannot be calculated for scalars")
3535

3636
# Faster pair- and column-wise versions TBD...
3737

3838

3939
# Bhattacharyya distance
40-
evaluate{T<:Number}(dist::BhattacharyyaDist, a::AbstractVector{T}, b::AbstractVector{T}) = -log(bhattacharyya_coeff(a, b))
40+
evaluate(dist::BhattacharyyaDist, a::AbstractVector{T}, b::AbstractVector{T}) where {T <: Number} = -log(bhattacharyya_coeff(a, b))
4141
bhattacharyya(a::AbstractVector, b::AbstractVector) = evaluate(BhattacharyyaDist(), a, b)
42-
evaluate{T <: Number}(dist::BhattacharyyaDist, a::T, b::T) = throw("Bhattacharyya distance cannot be calculated for scalars")
43-
bhattacharyya{T <: Number}(a::T, b::T) = evaluate(BhattacharyyaDist(), a, b)
42+
evaluate(dist::BhattacharyyaDist, a::T, b::T) where {T <: Number} = throw("Bhattacharyya distance cannot be calculated for scalars")
43+
bhattacharyya(a::T, b::T) where {T <: Number} = evaluate(BhattacharyyaDist(), a, b)
4444

4545
# Hellinger distance
46-
evaluate{T<:Number}(dist::HellingerDist, a::AbstractVector{T}, b::AbstractVector{T}) = sqrt(1 - bhattacharyya_coeff(a, b))
46+
evaluate(dist::HellingerDist, a::AbstractVector{T}, b::AbstractVector{T}) where {T <: Number} = sqrt(1 - bhattacharyya_coeff(a, b))
4747
hellinger(a::AbstractVector, b::AbstractVector) = evaluate(HellingerDist(), a, b)
48-
evaluate{T <: Number}(dist::HellingerDist, a::T, b::T) = throw("Hellinger distance cannot be calculated for scalars")
49-
hellinger{T <: Number}(a::T, b::T) = evaluate(HellingerDist(), a, b)
48+
evaluate(dist::HellingerDist, a::T, b::T) where {T <: Number} = throw("Hellinger distance cannot be calculated for scalars")
49+
hellinger(a::T, b::T) where {T <: Number} = evaluate(HellingerDist(), a, b)

src/common.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function sqrt!(a::AbstractArray)
9898
a
9999
end
100100

101-
function sumsq_percol{T}(a::AbstractMatrix{T})
101+
function sumsq_percol(a::AbstractMatrix{T}) where {T}
102102
m = size(a, 1)
103103
n = size(a, 2)
104104
r = Vector{T}(n)
@@ -109,7 +109,7 @@ function sumsq_percol{T}(a::AbstractMatrix{T})
109109
return r
110110
end
111111

112-
function wsumsq_percol{T1, T2}(w::AbstractArray{T1}, a::AbstractMatrix{T2})
112+
function wsumsq_percol(w::AbstractArray{T1}, a::AbstractMatrix{T2}) where {T1,T2}
113113
m = size(a, 1)
114114
n = size(a, 2)
115115
T = typeof(one(T1)*one(T2))

src/generic.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,21 @@
55
# d(x, y) >= 0
66
# d(x, x) = 0
77
#
8-
@compat abstract type PreMetric end
8+
abstract type PreMetric end
99

1010
# a semimetric is a function d that satisfies:
1111
#
1212
# d(x, y) >= 0
1313
# d(x, x) = 0
1414
# d(x, y) = d(y, x)
1515
#
16-
@compat abstract type SemiMetric <: PreMetric end
16+
abstract type SemiMetric <: PreMetric end
1717

1818
# a metric is a semimetric that satisfies triangle inequality:
1919
#
2020
# d(x, y) + d(y, z) >= d(x, z)
2121
#
22-
@compat abstract type Metric <: SemiMetric end
22+
abstract type Metric <: SemiMetric end
2323

2424

2525
# Generic functions

src/mahalanobis.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# Mahalanobis distances
22

3-
immutable Mahalanobis{T} <: Metric
3+
struct Mahalanobis{T} <: Metric
44
qmat::Matrix{T}
55
end
66

7-
immutable SqMahalanobis{T} <: SemiMetric
7+
struct SqMahalanobis{T} <: SemiMetric
88
qmat::Matrix{T}
99
end
1010

11-
result_type{T}(::Mahalanobis{T}, ::AbstractArray, ::AbstractArray) = T
12-
result_type{T}(::SqMahalanobis{T}, ::AbstractArray, ::AbstractArray) = T
11+
result_type(::Mahalanobis{T}, ::AbstractArray, ::AbstractArray) where {T} = T
12+
result_type(::SqMahalanobis{T}, ::AbstractArray, ::AbstractArray) where {T} = T
1313

1414
# SqMahalanobis
1515

16-
function evaluate{T<:AbstractFloat}(dist::SqMahalanobis{T}, a::AbstractVector, b::AbstractVector)
16+
function evaluate(dist::SqMahalanobis{T}, a::AbstractVector, b::AbstractVector) where {T <: AbstractFloat}
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
@@ -25,22 +25,22 @@ end
2525

2626
sqmahalanobis(a::AbstractVector, b::AbstractVector, Q::AbstractMatrix) = evaluate(SqMahalanobis(Q), a, b)
2727

28-
function colwise!{T<:AbstractFloat}(r::AbstractArray, dist::SqMahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix)
28+
function colwise!(r::AbstractArray, dist::SqMahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix) where {T <: AbstractFloat}
2929
Q = dist.qmat
3030
m, n = get_colwise_dims(size(Q, 1), r, a, b)
3131
z = a - b
3232
dot_percol!(r, Q * z, z)
3333
end
3434

35-
function colwise!{T<:AbstractFloat}(r::AbstractArray, dist::SqMahalanobis{T}, a::AbstractVector, b::AbstractMatrix)
35+
function colwise!(r::AbstractArray, dist::SqMahalanobis{T}, a::AbstractVector, b::AbstractMatrix) where {T <: AbstractFloat}
3636
Q = dist.qmat
3737
m, n = get_colwise_dims(size(Q, 1), r, a, b)
3838
z = a .- b
3939
Qz = Q * z
4040
dot_percol!(r, Q * z, z)
4141
end
4242

43-
function pairwise!{T<:AbstractFloat}(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix)
43+
function pairwise!(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix) where {T <: AbstractFloat}
4444
Q = dist.qmat
4545
m, na, nb = get_pairwise_dims(size(Q, 1), r, a, b)
4646

@@ -58,7 +58,7 @@ function pairwise!{T<:AbstractFloat}(r::AbstractMatrix, dist::SqMahalanobis{T},
5858
r
5959
end
6060

61-
function pairwise!{T<:AbstractFloat}(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix)
61+
function pairwise!(r::AbstractMatrix, dist::SqMahalanobis{T}, a::AbstractMatrix) where {T <: AbstractFloat}
6262
Q = dist.qmat
6363
m, n = get_pairwise_dims(size(Q, 1), r, a)
6464

@@ -81,24 +81,24 @@ end
8181

8282
# Mahalanobis
8383

84-
function evaluate{T<:AbstractFloat}(dist::Mahalanobis{T}, a::AbstractVector, b::AbstractVector)
84+
function evaluate(dist::Mahalanobis{T}, a::AbstractVector, b::AbstractVector) where {T <: AbstractFloat}
8585
sqrt(evaluate(SqMahalanobis(dist.qmat), a, b))
8686
end
8787

8888
mahalanobis(a::AbstractVector, b::AbstractVector, Q::AbstractMatrix) = evaluate(Mahalanobis(Q), a, b)
8989

90-
function colwise!{T<:AbstractFloat}(r::AbstractArray, dist::Mahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix)
90+
function colwise!(r::AbstractArray, dist::Mahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix) where {T <: AbstractFloat}
9191
sqrt!(colwise!(r, SqMahalanobis(dist.qmat), a, b))
9292
end
9393

94-
function colwise!{T<:AbstractFloat}(r::AbstractArray, dist::Mahalanobis{T}, a::AbstractVector, b::AbstractMatrix)
94+
function colwise!(r::AbstractArray, dist::Mahalanobis{T}, a::AbstractVector, b::AbstractMatrix) where {T <: AbstractFloat}
9595
sqrt!(colwise!(r, SqMahalanobis(dist.qmat), a, b))
9696
end
9797

98-
function pairwise!{T<:AbstractFloat}(r::AbstractMatrix, dist::Mahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix)
98+
function pairwise!(r::AbstractMatrix, dist::Mahalanobis{T}, a::AbstractMatrix, b::AbstractMatrix) where {T <: AbstractFloat}
9999
sqrt!(pairwise!(r, SqMahalanobis(dist.qmat), a, b))
100100
end
101101

102-
function pairwise!{T<:AbstractFloat}(r::AbstractMatrix, dist::Mahalanobis{T}, a::AbstractMatrix)
102+
function pairwise!(r::AbstractMatrix, dist::Mahalanobis{T}, a::AbstractMatrix) where {T <: AbstractFloat}
103103
sqrt!(pairwise!(r, SqMahalanobis(dist.qmat), a))
104104
end

0 commit comments

Comments
 (0)