Skip to content

Commit

Permalink
Use eachindex in generic_scale!
Browse files Browse the repository at this point in the history
(cherry picked from commit fa6c977)
ref #13460
  • Loading branch information
timholy authored and tkelman committed Oct 31, 2015
1 parent 33e1179 commit 78d5701
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ scale(s::Number, X::AbstractArray) = s*X
# For better performance when input and output are the same array
# See https://github.com/JuliaLang/julia/issues/8415#issuecomment-56608729
function generic_scale!(X::AbstractArray, s::Number)
for i = 1:length(X)
@inbounds X[i] *= s
for I in eachindex(X)
@inbounds X[I] *= s
end
X
end
Expand All @@ -18,8 +18,14 @@ function generic_scale!(C::AbstractArray, X::AbstractArray, s::Number)
if length(C) != length(X)
throw(DimensionMismatch("first array has length $(length(C)) which does not match the length of the second, $(length(X))."))
end
for i = 1:length(X)
@inbounds C[i] = X[i]*s
if size(C) == size(X)
for I in eachindex(C, X)
@inbounds C[I] = X[I]*s
end
else
for (IC, IX) in zip(eachindex(C), eachindex(X))
@inbounds C[IC] = X[IX]*s
end
end
C
end
Expand Down

0 comments on commit 78d5701

Please sign in to comment.