Skip to content

Commit

Permalink
Deprecate vectorized two-argument complex methods in favor of compact…
Browse files Browse the repository at this point in the history
… broadcast syntax.
  • Loading branch information
Sacha0 committed Dec 25, 2016
1 parent 55b1230 commit cd0f380
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 53 deletions.
46 changes: 0 additions & 46 deletions base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -871,49 +871,3 @@ big{T<:AbstractFloat,N}(A::AbstractArray{Complex{T},N}) = convert(AbstractArray{

_default_type(T::Type{Complex}) = Complex{Int}
promote_array_type{S<:Union{Complex, Real}, T<:AbstractFloat}(F, ::Type{S}, ::Type{Complex{T}}, ::Type) = Complex{T}

function complex{S<:Real,T<:Real}(A::AbstractArray{S}, B::AbstractArray{T})
if size(A) != size(B); throw(DimensionMismatch()); end
F = similar(A, typeof(complex(zero(S),zero(T))))
RF, RA, RB = eachindex(F), eachindex(A), eachindex(B)
if RF == RA == RB
for i in RA
@inbounds F[i] = complex(A[i], B[i])
end
else
for (iF, iA, iB) in zip(RF, RA, RB)
@inbounds F[iF] = complex(A[iA], B[iB])
end
end
return F
end

function complex{T<:Real}(A::Real, B::AbstractArray{T})
F = similar(B, typeof(complex(A,zero(T))))
RF, RB = eachindex(F), eachindex(B)
if RF == RB
for i in RB
@inbounds F[i] = complex(A, B[i])
end
else
for (iF, iB) in zip(RF, RB)
@inbounds F[iF] = complex(A, B[iB])
end
end
return F
end

function complex{T<:Real}(A::AbstractArray{T}, B::Real)
F = similar(A, typeof(complex(zero(T),B)))
RF, RA = eachindex(F), eachindex(A)
if RF == RA
for i in RA
@inbounds F[i] = complex(A[i], B)
end
else
for (iF, iA) in zip(RF, RA)
@inbounds F[iF] = complex(A[iA], B)
end
end
return F
end
5 changes: 5 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1168,4 +1168,9 @@ for (dep, f, op) in [(:sumabs!, :sum!, :abs),
end
end

# Deprecate vectorized two-argument complex in favor of compact broadcast syntax
@deprecate complex(A::AbstractArray, b::Real) complex.(A, b)
@deprecate complex(a::Real, B::AbstractArray) complex.(a, B)
@deprecate complex(A::AbstractArray, B::AbstractArray) complex.(A, B)

# End deprecations scheduled for 0.6
2 changes: 0 additions & 2 deletions base/sharedarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,8 +512,6 @@ function copy!(S::SharedArray, R::SharedArray)
return S
end

complex(S1::SharedArray,S2::SharedArray) = convert(SharedArray, complex(S1.s, S2.s))

function print_shmem_limits(slen)
try
if is_linux()
Expand Down
2 changes: 0 additions & 2 deletions base/sparse/sparsematrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -354,8 +354,6 @@ float(S::SparseMatrixCSC) = SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.row

complex(S::SparseMatrixCSC) = SparseMatrixCSC(S.m, S.n, copy(S.colptr), copy(S.rowval), complex(copy(S.nzval)))

complex(A::SparseMatrixCSC, B::SparseMatrixCSC) = A + im*B

# Construct a sparse vector

# Note that unlike `vec` for arrays, this does not share data
Expand Down
4 changes: 2 additions & 2 deletions test/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -813,8 +813,8 @@ end
@test_throws DomainError complex(2,2)^(-2)
@test complex(2.0,2.0)^(-2) === complex(0.0, -0.125)

@test complex(1.0,[1.0,1.0]) == [complex(1.0,1.0), complex(1.0,1.0)]
@test complex([1.0,1.0],1.0) == [complex(1.0,1.0), complex(1.0,1.0)]
@test complex.(1.0, [1.0, 1.0]) == [complex(1.0, 1.0), complex(1.0, 1.0)]
@test complex.([1.0, 1.0], 1.0) == [complex(1.0, 1.0), complex(1.0, 1.0)]
# robust division of Float64
# hard complex divisions from Fig 6 of arxiv.1210.4539
z7 = Complex{Float64}(3.898125604559113300e289, 8.174961907852353577e295)
Expand Down
2 changes: 1 addition & 1 deletion test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ end
end

@testset "sparse matrix construction" begin
@test isequal(Array(sparse(complex(ones(5,5),ones(5,5)))), complex(ones(5,5),ones(5,5)))
@test isequal(Array(sparse(complex.(ones(5,5), ones(5,5)))), complex.(ones(5,5), ones(5,5)))
@test_throws ArgumentError sparse([1,2,3], [1,2], [1,2,3], 3, 3)
@test_throws ArgumentError sparse([1,2,3], [1,2,3], [1,2], 3, 3)
@test_throws ArgumentError sparse([1,2,3], [1,2,3], [1,2,3], 0, 1)
Expand Down

0 comments on commit cd0f380

Please sign in to comment.