Skip to content

Commit dc0763e

Browse files
committed
Merge pull request #31 from KristofferC/kc/typess
fix some hard coding of types
2 parents 834268b + ed2ee58 commit dc0763e

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/common.jl

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

101-
function sumsq_percol(a::AbstractMatrix)
101+
function sumsq_percol{T}(a::AbstractMatrix{T})
102102
m = size(a, 1)
103103
n = size(a, 2)
104-
r = Array(Float64, n)
104+
r = Array(T, n)
105105
for j = 1:n
106106
aj = view(a,:,j)
107107
r[j] = dot(aj, aj)
108108
end
109109
return r
110110
end
111111

112-
function wsumsq_percol(w::AbstractArray, a::AbstractMatrix)
112+
function wsumsq_percol{T1, T2}(w::AbstractArray{T1}, a::AbstractMatrix{T2})
113113
m = size(a, 1)
114114
n = size(a, 2)
115-
r = Array(Float64, n)
115+
T = typeof(one(T1)*one(T2))
116+
r = Array(T, n)
116117
for j = 1:n
117118
aj = view(a,:,j)
118-
s = 0.
119-
for i = 1:m
119+
s = zero(T)
120+
@simd for i = 1:m
120121
@inbounds s += w[i] * abs2(aj[i])
121122
end
122123
r[j] = s

src/wmetrics.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function evaluate(d::UnionWeightedMetrics, a::AbstractArray, b::AbstractArray)
6464
end
6565
s = eval_start(d, a, b)
6666
if size(a) == size(b)
67-
for I in eachindex(a, b, d.weights)
67+
@simd for I in eachindex(a, b, d.weights)
6868
@inbounds ai = a[I]
6969
@inbounds bi = b[I]
7070
@inbounds wi = d.weights[I]

0 commit comments

Comments
 (0)