Skip to content

Commit

Permalink
Deprecate adjoint(v::AbstractVector)/transpose(v::AbstractVector) to …
Browse files Browse the repository at this point in the history
…Adjoint(v)/Transpose(v).
  • Loading branch information
Sacha0 committed Dec 21, 2017
1 parent 1460f9e commit 9809ce6
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 17 deletions.
21 changes: 21 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2540,6 +2540,27 @@ end
@deprecate RowVector{T}(n::Tuple{Int,Int}) where {T} RowVector{T}(uninitialized, n)
end

# deprecate adjoint(v)/tranpose(v) for v<:AbstractVector in favor of Adjoint/Transpose
@eval Base.LinAlg begin
@deprecate adjoint(sv::AbstractVector) Adjoint(sv)
@deprecate transpose(sv::AbstractVector) Transpose(sv)
end
@eval Base.SparseArrays begin
@deprecate adjoint(sv::SparseVector) Adjoint(sv)
@deprecate transpose(sv::SparseVector) Transpose(sv)
end
@eval Base.LinAlg begin
@deprecate adjoint(B::BitVector) Adjoint(B)
end
@eval Base.LinAlg begin
function adjoint(A::AbstractVector{<:Real})
Base.depwarn(string("`adjoint(A::AbstractVector{<:Real})` yielding a ",
"`RowVector{eltype(A),typeof(A)}` has been deprecated in favor of Transpose(A) ",
"(or `Adjoint(A)`, depending on the existing code's intent)."), :adjoint)
return Transpose(A)
end
end

# A[ct]_(mul|ldiv|rdiv)_B[ct][!] methods from base/operators.jl, to deprecate
@deprecate Ac_ldiv_Bt(a,b) (\)(Adjoint(a), Transpose(b))
@deprecate At_ldiv_Bt(a,b) (\)(Transpose(a), Transpose(b))
Expand Down
4 changes: 0 additions & 4 deletions base/linalg/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ transpose(A::Transpose) = copy(A.parent)
adjoint(A::Transpose) = conj!(copy(A.parent))
transpose(A::Adjoint) = conj!(copy(A.parent))

# lowercase quasi-constructors for vectors, TODO: deprecate
adjoint(sv::AbstractVector) = Adjoint(sv)
transpose(sv::AbstractVector) = Transpose(sv)


# some aliases for internal convenience use
const AdjOrTrans{T,S} = Union{Adjoint{T,S},Transpose{T,S}} where {T,S}
Expand Down
2 changes: 1 addition & 1 deletion base/linalg/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,4 @@ function transpose(B::BitMatrix)
return Bt
end

adjoint(B::Union{BitMatrix,BitVector}) = transpose(B)
adjoint(B::BitMatrix) = transpose(B)
1 change: 0 additions & 1 deletion base/linalg/transpose.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ function adjoint(A::AbstractMatrix)
adjoint!(B, A)
end

@inline adjoint(A::AbstractVector{<:Real}) = transpose(A)
@inline adjoint(A::AbstractMatrix{<:Real}) = transpose(A)

function copy_transpose!(B::AbstractVecOrMat, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int},
Expand Down
5 changes: 0 additions & 5 deletions base/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1435,11 +1435,6 @@ vecnorm(x::SparseVectorUnion, p::Real=2) = vecnorm(nonzeros(x), p)

### linalg.jl

# Transpose
# (The only sparse matrix structure in base is CSC, so a one-row sparse matrix is worse than dense)
transpose(sv::SparseVector) = Transpose(sv)
adjoint(sv::SparseVector) = Adjoint(sv)

### BLAS Level-1

# axpy
Expand Down
6 changes: 4 additions & 2 deletions test/sparse/higherorderfns.jl
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,10 @@ end
@test broadcast(*, s, V, A, X)::SparseMatrixCSC == sparse(broadcast(*, s, fV, fA, X))
@test broadcast!(*, Z, s, V, A, X) == sparse(broadcast(*, s, fV, fA, X))
# Issue #20954 combinations of sparse arrays and Adjoint/Transpose vectors
@test broadcast(+, A, adjoint(X))::SparseMatrixCSC == sparse(broadcast(+, fA, adjoint(X)))
@test broadcast(*, V, adjoint(X))::SparseMatrixCSC == sparse(broadcast(*, fV, adjoint(X)))
if X isa AbstractVector
@test broadcast(+, A, Adjoint(X))::SparseMatrixCSC == sparse(broadcast(+, fA, Adjoint(X)))
@test broadcast(*, V, Adjoint(X))::SparseMatrixCSC == sparse(broadcast(*, fV, Adjoint(X)))
end
end
@test V .+ ntuple(identity, N) isa Vector
@test A .+ ntuple(identity, N) isa Matrix
Expand Down
4 changes: 2 additions & 2 deletions test/sparse/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ end
am = sprand(1, 20, 0.2)
av = squeeze(am, 1)
@test ndims(av) == 1
@test all(transpose(av) .== am)
@test all(Transpose(av) .== am)
end
end

Expand Down Expand Up @@ -1313,7 +1313,7 @@ end
end

@testset "issue #9917" begin
@test sparse(adjoint([])) == reshape(sparse([]), 1, 0)
@test sparse(Adjoint([])) == reshape(sparse([]), 1, 0)
@test Array(sparse([])) == zeros(0)
@test_throws BoundsError sparse([])[1]
@test_throws BoundsError sparse([])[1] = 1
Expand Down
4 changes: 2 additions & 2 deletions test/sparse/sparsevector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -385,14 +385,14 @@ end
@test float(af) == af
@test isa(af, SparseVector{Float64,Int})
@test exact_equal(af, SparseVector(8, [2, 5, 6], [12., 35., 72.]))
@test sparsevec(transpose(transpose(af))) == af
@test sparsevec(Transpose(Transpose(af))) == af

# complex
acp = complex(af)
@test complex(acp) == acp
@test isa(acp, SparseVector{ComplexF64,Int})
@test exact_equal(acp, SparseVector(8, [2, 5, 6], complex([12., 35., 72.])))
@test sparsevec(adjoint(adjoint(acp))) == acp
@test sparsevec(Adjoint(Adjoint(acp))) == acp
end

@testset "Type conversion" begin
Expand Down

0 comments on commit 9809ce6

Please sign in to comment.