Skip to content

Commit 152d6cc

Browse files
davidavdavKristofferC
authored andcommitted
Add support for julia-v0.5 slice->view change (#48)
1 parent 5fbc985 commit 152d6cc

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

src/Distances.jl

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

33
module Distances
44

5+
import Compat.view
6+
57
export
68
# generic types/functions
79
PreMetric,

src/common.jl

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ function sumsq_percol{T}(a::AbstractMatrix{T})
103103
n = size(a, 2)
104104
r = Array(T, n)
105105
for j = 1:n
106-
aj = slice(a, :, j)
106+
aj = view(a, :, j)
107107
r[j] = dot(aj, aj)
108108
end
109109
return r
@@ -115,7 +115,7 @@ function wsumsq_percol{T1, T2}(w::AbstractArray{T1}, a::AbstractMatrix{T2})
115115
T = typeof(one(T1)*one(T2))
116116
r = Array(T, n)
117117
for j = 1:n
118-
aj = slice(a, :, j)
118+
aj = view(a, :, j)
119119
s = zero(T)
120120
@simd for i = 1:m
121121
@inbounds s += w[i] * abs2(aj[i])
@@ -131,13 +131,11 @@ function dot_percol!(r::AbstractArray, a::AbstractMatrix, b::AbstractMatrix)
131131
size(b) == (m,n) && length(r) == n ||
132132
throw(DimensionMismatch("Inconsistent array dimensions."))
133133
for j = 1:n
134-
aj = slice(a,:,j)
135-
bj = slice(b,:,j)
134+
aj = view(a,:,j)
135+
bj = view(b,:,j)
136136
r[j] = dot(aj, bj)
137137
end
138138
return r
139139
end
140140

141141
dot_percol(a::AbstractMatrix, b::AbstractMatrix) = dot_percol!(Array(Float64, size(a,2)), a, b)
142-
143-

src/generic.jl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractVector, b::Abs
3333
n = size(b, 2)
3434
length(r) == n || throw(DimensionMismatch("Incorrect size of r."))
3535
for j = 1 : n
36-
@inbounds r[j] = evaluate(metric, a, slice(b, :, j))
36+
@inbounds r[j] = evaluate(metric, a, view(b, :, j))
3737
end
3838
r
3939
end
@@ -42,7 +42,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractMatrix, b::Abs
4242
n = size(a, 2)
4343
length(r) == n || throw(DimensionMismatch("Incorrect size of r."))
4444
for j = 1 : n
45-
@inbounds r[j] = evaluate(metric, slice(a, :, j), b)
45+
@inbounds r[j] = evaluate(metric, view(a, :, j), b)
4646
end
4747
r
4848
end
@@ -51,7 +51,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractMatrix, b::Abs
5151
n = get_common_ncols(a, b)
5252
length(r) == n || throw(DimensionMismatch("Incorrect size of r."))
5353
for j = 1 : n
54-
@inbounds r[j] = evaluate(metric, slice(a, :, j), slice(b, :, j))
54+
@inbounds r[j] = evaluate(metric, view(a, :, j), view(b, :, j))
5555
end
5656
r
5757
end
@@ -86,9 +86,9 @@ function pairwise!(r::AbstractMatrix, metric::PreMetric, a::AbstractMatrix, b::A
8686
nb = size(b, 2)
8787
size(r) == (na, nb) || throw(DimensionMismatch("Incorrect size of r."))
8888
for j = 1 : size(b, 2)
89-
bj = slice(b,:,j)
89+
bj = view(b,:,j)
9090
for i = 1 : size(a, 2)
91-
@inbounds r[i,j] = evaluate(metric, slice(a,:,i), bj)
91+
@inbounds r[i,j] = evaluate(metric, view(a,:,i), bj)
9292
end
9393
end
9494
r
@@ -102,9 +102,9 @@ function pairwise!(r::AbstractMatrix, metric::SemiMetric, a::AbstractMatrix)
102102
n = size(a, 2)
103103
size(r) == (n, n) || throw(DimensionMismatch("Incorrect size of r."))
104104
for j = 1 : n
105-
aj = slice(a,:,j)
105+
aj = view(a,:,j)
106106
for i = j+1 : n
107-
@inbounds r[i,j] = evaluate(metric, slice(a,:,i), aj)
107+
@inbounds r[i,j] = evaluate(metric, view(a,:,i), aj)
108108
end
109109
@inbounds r[j,j] = 0
110110
for i = 1 : j-1
@@ -132,5 +132,3 @@ function pairwise(metric::SemiMetric, a::AbstractMatrix)
132132
r = Array(result_type(metric, a, a), (n, n))
133133
pairwise!(r, metric, a)
134134
end
135-
136-

0 commit comments

Comments
 (0)