Skip to content

Commit 0dbbaf7

Browse files
committed
Merge pull request #5957 from JuliaLang/kms/fix_scale!
Remove scale!{T<:BlasReal}(X::Array{T}, s::Complex)
2 parents fffd879 + 3e93fef commit 0dbbaf7

File tree

4 files changed

+20
-1
lines changed

4 files changed

+20
-1
lines changed

base/deprecated.jl

+2
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,5 @@ function nnz(X)
408408
countnz(X)
409409
end
410410
export nnz
411+
412+
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.")

base/linalg/dense.jl

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Linear algebra functions for dense matrices in column major format
22

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

76
#Test whether a matrix is positive-definite

base/linalg/generic.jl

+8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
scale(X::AbstractArray, s::Number) = scale!(copy(X), s)
44
scale(s::Number, X::AbstractArray) = scale!(copy(X), s)
55

6+
function scale{R<:Real,S<:Complex}(X::AbstractArray{R}, s::S)
7+
Y = Array(promote_type(R,S), size(X))
8+
copy!(Y, X)
9+
scale!(Y, s)
10+
end
11+
12+
scale{R<:Real}(s::Complex, X::AbstractArray{R}) = scale(X, s)
13+
614
function scale!(X::AbstractArray, s::Number)
715
for i in 1:length(X)
816
@inbounds X[i] *= s

test/linalg1.jl

+10
Original file line numberDiff line numberDiff line change
@@ -442,3 +442,13 @@ Ai = int(ceil(Ar*100))
442442
@test_approx_eq norm(Ai,Inf) norm(full(Ai),Inf)
443443
@test_approx_eq normfro(Ai) normfro(full(Ai))
444444

445+
# scale real matrix by complex type
446+
@test_throws scale!([1.0], 2.0im)
447+
@test isequal(scale([1.0], 2.0im), Complex{Float64}[2.0im])
448+
@test isequal(scale(Float32[1.0], 2.0f0im), Complex{Float32}[2.0im])
449+
@test isequal(scale(Float32[1.0], 2.0im), Complex{Float64}[2.0im])
450+
@test isequal(scale(Float64[1.0], 2.0f0im), Complex{Float64}[2.0im])
451+
@test isequal(scale(Float32[1.0], big(2.0)im), Complex{BigFloat}[2.0im])
452+
@test isequal(scale(Float64[1.0], big(2.0)im), Complex{BigFloat}[2.0im])
453+
@test isequal(scale(BigFloat[1.0], 2.0im), Complex{BigFloat}[2.0im])
454+
@test isequal(scale(BigFloat[1.0], 2.0f0im), Complex{BigFloat}[2.0im])

0 commit comments

Comments
 (0)