Skip to content

Commit

Permalink
Make scale(Array,Number) fall back to *. Fixes #12912.
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasnoack committed Sep 7, 2015
1 parent f51873a commit ab0db5c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
12 changes: 2 additions & 10 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,8 @@

## linalg.jl: Some generic Linear Algebra definitions

scale(X::AbstractArray, s::Number) = scale!(copy(X), s)
scale(s::Number, X::AbstractArray) = scale!(copy(X), s)

function scale{R<:Real,S<:Complex}(X::AbstractArray{R}, s::S)
Y = Array(promote_type(R,S), size(X))
copy!(Y, X)
scale!(Y, s)
end

scale{R<:Real}(s::Complex, X::AbstractArray{R}) = scale(X, s)
scale(X::AbstractArray, s::Number) = X*s
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
Expand Down
1 change: 1 addition & 0 deletions test/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ a = reshape([1.:6;], (2,3))
@test scale([1.; 2.], a) == a.*[1; 2]
@test scale(a, [1; 2; 3]) == a.*[1 2 3]
@test scale([1; 2], a) == a.*[1; 2]
@test scale(eye(Int, 2), 0.5) == 0.5*eye(2)
@test_throws DimensionMismatch scale(a, ones(2))
@test_throws DimensionMismatch scale(ones(3), a)

Expand Down

0 comments on commit ab0db5c

Please sign in to comment.