Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use eachindex in generic_scale! #13460

Merged
merged 1 commit into from
Oct 6, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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