Skip to content

Commit

Permalink
Merge pull request #5957 from JuliaLang/kms/fix_scale!
Browse files Browse the repository at this point in the history
Remove scale!{T<:BlasReal}(X::Array{T}, s::Complex)
  • Loading branch information
kmsquire committed Feb 25, 2014
2 parents fffd879 + 3e93fef commit 0dbbaf7
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -408,3 +408,5 @@ function nnz(X)
countnz(X)
end
export nnz

scale!{T<:Base.LinAlg.BlasReal}(X::Array{T}, s::Complex) = error("scale!: Cannot scale a real array by a complex value in-place. Use scale(X::Array{Real}, s::Complex) instead.")
1 change: 0 additions & 1 deletion base/linalg/dense.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Linear algebra functions for dense matrices in column major format

scale!{T<:BlasFloat}(X::Array{T}, s::Number) = BLAS.scal!(length(X), convert(T,s), X, 1)
scale!{T<:BlasReal}(X::Array{T}, s::Complex) = scale!(complex(X), s)
scale!{T<:BlasComplex}(X::Array{T}, s::Real) = BLAS.scal!(length(X), oftype(real(zero(T)),s), X, 1)

#Test whether a matrix is positive-definite
Expand Down
8 changes: 8 additions & 0 deletions base/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
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)

function scale!(X::AbstractArray, s::Number)
for i in 1:length(X)
@inbounds X[i] *= s
Expand Down
10 changes: 10 additions & 0 deletions test/linalg1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,13 @@ Ai = int(ceil(Ar*100))
@test_approx_eq norm(Ai,Inf) norm(full(Ai),Inf)
@test_approx_eq normfro(Ai) normfro(full(Ai))

# scale real matrix by complex type
@test_throws scale!([1.0], 2.0im)
@test isequal(scale([1.0], 2.0im), Complex{Float64}[2.0im])
@test isequal(scale(Float32[1.0], 2.0f0im), Complex{Float32}[2.0im])
@test isequal(scale(Float32[1.0], 2.0im), Complex{Float64}[2.0im])
@test isequal(scale(Float64[1.0], 2.0f0im), Complex{Float64}[2.0im])
@test isequal(scale(Float32[1.0], big(2.0)im), Complex{BigFloat}[2.0im])
@test isequal(scale(Float64[1.0], big(2.0)im), Complex{BigFloat}[2.0im])
@test isequal(scale(BigFloat[1.0], 2.0im), Complex{BigFloat}[2.0im])
@test isequal(scale(BigFloat[1.0], 2.0f0im), Complex{BigFloat}[2.0im])

0 comments on commit 0dbbaf7

Please sign in to comment.