diff --git a/src/deviation.jl b/src/deviation.jl index c0e4756eb..c3061b096 100644 --- a/src/deviation.jl +++ b/src/deviation.jl @@ -9,8 +9,7 @@ Count the number of indices at which the elements of the arrays `a` and `b` are equal. """ function counteq(a::AbstractArray, b::AbstractArray) - n = length(a) - length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) + length(a) == length(b) || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] == b[i] @@ -28,8 +27,7 @@ Count the number of indices at which the elements of the arrays `a` and `b` are not equal. """ function countne(a::AbstractArray, b::AbstractArray) - n = length(a) - length(b) == n || throw(DimensionMismatch("Inconsistent lengths.")) + length(a) == length(b) || throw(DimensionMismatch("Inconsistent lengths.")) c = 0 for i in eachindex(a, b) @inbounds if a[i] != b[i] @@ -47,8 +45,7 @@ Compute the squared L2 distance between two arrays: ``\\sum_{i=1}^n |a_i - b_i|^ Efficient equivalent of `sum(abs2, a - b)`. """ function sqL2dist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number - n = length(a) - length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) + length(a) == length(b) || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds r += abs2(a[i] - b[i]) @@ -75,8 +72,7 @@ Compute the L1 distance between two arrays: ``\\sum_{i=1}^n |a_i - b_i|``. Efficient equivalent of `sum(abs, a - b)`. """ function L1dist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number - n = length(a) - length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) + length(a) == length(b) || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds r += abs(a[i] - b[i]) @@ -94,8 +90,7 @@ two arrays: ``\\max_{i\\in1:n} |a_i - b_i|``. Efficient equivalent of `maxabs(a - b)`. """ function Linfdist(a::AbstractArray{T}, b::AbstractArray{T}) where T<:Number - n = length(a) - length(b) == n || throw(DimensionMismatch("Input dimension mismatch")) + length(a) == length(b) || throw(DimensionMismatch("Input dimension mismatch")) r = 0.0 for i in eachindex(a, b) @inbounds v = abs(a[i] - b[i])