Skip to content
This repository has been archived by the owner on Jun 29, 2019. It is now read-only.

Commit

Permalink
use view in the place of unsafe_view
Browse files Browse the repository at this point in the history
  • Loading branch information
lindahua committed Jan 28, 2014
1 parent 1c9acef commit de9eaa3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
julia 0.2-
NumericExtensions 0.3-
NumericExtensions 0.4-
14 changes: 7 additions & 7 deletions src/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractVector, b::Abs
n = size(b, 2)
length(r) == n || throw(DimensionMismatch("Incorrect size of r."))
for j = 1 : n
@inbounds r[j] = evaluate(metric, a, unsafe_view(b, :, j))
@inbounds r[j] = evaluate(metric, a, view(b, :, j))
end
r
end
Expand All @@ -42,7 +42,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractMatrix, b::Abs
n = size(a, 2)
length(r) == n || throw(DimensionMismatch("Incorrect size of r."))
for j = 1 : n
@inbounds r[j] = evaluate(metric, unsafe_view(a, :, j), b)
@inbounds r[j] = evaluate(metric, view(a, :, j), b)
end
r
end
Expand All @@ -51,7 +51,7 @@ function colwise!(r::AbstractArray, metric::PreMetric, a::AbstractMatrix, b::Abs
n = get_common_ncols(a, b)
length(r) == n || throw(DimensionMismatch("Incorrect size of r."))
for j = 1 : n
@inbounds r[j] = evaluate(metric, unsafe_view(a, :, j), unsafe_view(b, :, j))
@inbounds r[j] = evaluate(metric, view(a, :, j), view(b, :, j))
end
r
end
Expand Down Expand Up @@ -86,9 +86,9 @@ function pairwise!(r::AbstractMatrix, metric::PreMetric, a::AbstractMatrix, b::A
nb = size(b, 2)
size(r) == (na, nb) || throw(DimensionMismatch("Incorrect size of r."))
for j = 1 : size(b, 2)
bj = unsafe_view(b,:,j)
bj = view(b,:,j)
for i = 1 : size(a, 2)
@inbounds r[i,j] = evaluate(metric, unsafe_view(a,:,i), bj)
@inbounds r[i,j] = evaluate(metric, view(a,:,i), bj)
end
end
r
Expand All @@ -102,9 +102,9 @@ function pairwise!(r::AbstractMatrix, metric::SemiMetric, a::AbstractMatrix)
n = size(a, 2)
size(r) == (n, n) || throw(DimensionMismatch("Incorrect size of r."))
for j = 1 : n
aj = unsafe_view(a,:,j)
aj = view(a,:,j)
for i = j+1 : n
@inbounds r[i,j] = evaluate(metric, unsafe_view(a,:,i), aj)
@inbounds r[i,j] = evaluate(metric, view(a,:,i), aj)
end
@inbounds r[j,j] = 0
for i = 1 : j-1
Expand Down

0 comments on commit de9eaa3

Please sign in to comment.