Skip to content

Commit

Permalink
Specialize generic_scale! when input and output are the same array
Browse files Browse the repository at this point in the history
Ref #8145
  • Loading branch information
simonster committed Sep 24, 2014
1 parent fa362dc commit c344abd
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,15 @@ end

scale{R<:Real}(s::Complex, X::AbstractArray{R}) = scale(X, s)

generic_scale!(X::AbstractArray, s::Number) = generic_scale!(X, X, s)
# 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
end
X
end

function generic_scale!(C::AbstractArray, X::AbstractArray, s::Number)
length(C) == length(X) || error("C must be the same length as X")
for i = 1:length(X)
Expand All @@ -21,8 +29,8 @@ function generic_scale!(C::AbstractArray, X::AbstractArray, s::Number)
end
scale!(C::AbstractArray, s::Number, X::AbstractArray) = generic_scale!(C, X, s)
scale!(C::AbstractArray, X::AbstractArray, s::Number) = generic_scale!(C, X, s)
scale!(X::AbstractArray, s::Number) = generic_scale!(X, X, s)
scale!(s::Number, X::AbstractArray) = generic_scale!(X, X, s)
scale!(X::AbstractArray, s::Number) = generic_scale!(X, s)
scale!(s::Number, X::AbstractArray) = generic_scale!(X, s)

cross(a::AbstractVector, b::AbstractVector) = [a[2]*b[3]-a[3]*b[2], a[3]*b[1]-a[1]*b[3], a[1]*b[2]-a[2]*b[1]]

Expand Down

1 comment on commit c344abd

@simonster
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, meant #8415

Please sign in to comment.