Skip to content

Commit 9809ce6

Browse files
committed
Deprecate adjoint(v::AbstractVector)/transpose(v::AbstractVector) to Adjoint(v)/Transpose(v).
1 parent 1460f9e commit 9809ce6

File tree

8 files changed

+30
-17
lines changed

8 files changed

+30
-17
lines changed

base/deprecated.jl

+21
Original file line numberDiff line numberDiff line change
@@ -2540,6 +2540,27 @@ end
25402540
@deprecate RowVector{T}(n::Tuple{Int,Int}) where {T} RowVector{T}(uninitialized, n)
25412541
end
25422542

2543+
# deprecate adjoint(v)/tranpose(v) for v<:AbstractVector in favor of Adjoint/Transpose
2544+
@eval Base.LinAlg begin
2545+
@deprecate adjoint(sv::AbstractVector) Adjoint(sv)
2546+
@deprecate transpose(sv::AbstractVector) Transpose(sv)
2547+
end
2548+
@eval Base.SparseArrays begin
2549+
@deprecate adjoint(sv::SparseVector) Adjoint(sv)
2550+
@deprecate transpose(sv::SparseVector) Transpose(sv)
2551+
end
2552+
@eval Base.LinAlg begin
2553+
@deprecate adjoint(B::BitVector) Adjoint(B)
2554+
end
2555+
@eval Base.LinAlg begin
2556+
function adjoint(A::AbstractVector{<:Real})
2557+
Base.depwarn(string("`adjoint(A::AbstractVector{<:Real})` yielding a ",
2558+
"`RowVector{eltype(A),typeof(A)}` has been deprecated in favor of Transpose(A) ",
2559+
"(or `Adjoint(A)`, depending on the existing code's intent)."), :adjoint)
2560+
return Transpose(A)
2561+
end
2562+
end
2563+
25432564
# A[ct]_(mul|ldiv|rdiv)_B[ct][!] methods from base/operators.jl, to deprecate
25442565
@deprecate Ac_ldiv_Bt(a,b) (\)(Adjoint(a), Transpose(b))
25452566
@deprecate At_ldiv_Bt(a,b) (\)(Transpose(a), Transpose(b))

base/linalg/adjtrans.jl

-4
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,6 @@ transpose(A::Transpose) = copy(A.parent)
6464
adjoint(A::Transpose) = conj!(copy(A.parent))
6565
transpose(A::Adjoint) = conj!(copy(A.parent))
6666

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

7268
# some aliases for internal convenience use
7369
const AdjOrTrans{T,S} = Union{Adjoint{T,S},Transpose{T,S}} where {T,S}

base/linalg/bitarray.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,4 @@ function transpose(B::BitMatrix)
284284
return Bt
285285
end
286286

287-
adjoint(B::Union{BitMatrix,BitVector}) = transpose(B)
287+
adjoint(B::BitMatrix) = transpose(B)

base/linalg/transpose.jl

-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ function adjoint(A::AbstractMatrix)
180180
adjoint!(B, A)
181181
end
182182

183-
@inline adjoint(A::AbstractVector{<:Real}) = transpose(A)
184183
@inline adjoint(A::AbstractMatrix{<:Real}) = transpose(A)
185184

186185
function copy_transpose!(B::AbstractVecOrMat, ir_dest::AbstractRange{Int}, jr_dest::AbstractRange{Int},

base/sparse/sparsevector.jl

-5
Original file line numberDiff line numberDiff line change
@@ -1435,11 +1435,6 @@ vecnorm(x::SparseVectorUnion, p::Real=2) = vecnorm(nonzeros(x), p)
14351435

14361436
### linalg.jl
14371437

1438-
# Transpose
1439-
# (The only sparse matrix structure in base is CSC, so a one-row sparse matrix is worse than dense)
1440-
transpose(sv::SparseVector) = Transpose(sv)
1441-
adjoint(sv::SparseVector) = Adjoint(sv)
1442-
14431438
### BLAS Level-1
14441439

14451440
# axpy

test/sparse/higherorderfns.jl

+4-2
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,10 @@ end
415415
@test broadcast(*, s, V, A, X)::SparseMatrixCSC == sparse(broadcast(*, s, fV, fA, X))
416416
@test broadcast!(*, Z, s, V, A, X) == sparse(broadcast(*, s, fV, fA, X))
417417
# Issue #20954 combinations of sparse arrays and Adjoint/Transpose vectors
418-
@test broadcast(+, A, adjoint(X))::SparseMatrixCSC == sparse(broadcast(+, fA, adjoint(X)))
419-
@test broadcast(*, V, adjoint(X))::SparseMatrixCSC == sparse(broadcast(*, fV, adjoint(X)))
418+
if X isa AbstractVector
419+
@test broadcast(+, A, Adjoint(X))::SparseMatrixCSC == sparse(broadcast(+, fA, Adjoint(X)))
420+
@test broadcast(*, V, Adjoint(X))::SparseMatrixCSC == sparse(broadcast(*, fV, Adjoint(X)))
421+
end
420422
end
421423
@test V .+ ntuple(identity, N) isa Vector
422424
@test A .+ ntuple(identity, N) isa Matrix

test/sparse/sparse.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ end
163163
am = sprand(1, 20, 0.2)
164164
av = squeeze(am, 1)
165165
@test ndims(av) == 1
166-
@test all(transpose(av) .== am)
166+
@test all(Transpose(av) .== am)
167167
end
168168
end
169169

@@ -1313,7 +1313,7 @@ end
13131313
end
13141314

13151315
@testset "issue #9917" begin
1316-
@test sparse(adjoint([])) == reshape(sparse([]), 1, 0)
1316+
@test sparse(Adjoint([])) == reshape(sparse([]), 1, 0)
13171317
@test Array(sparse([])) == zeros(0)
13181318
@test_throws BoundsError sparse([])[1]
13191319
@test_throws BoundsError sparse([])[1] = 1

test/sparse/sparsevector.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -385,14 +385,14 @@ end
385385
@test float(af) == af
386386
@test isa(af, SparseVector{Float64,Int})
387387
@test exact_equal(af, SparseVector(8, [2, 5, 6], [12., 35., 72.]))
388-
@test sparsevec(transpose(transpose(af))) == af
388+
@test sparsevec(Transpose(Transpose(af))) == af
389389

390390
# complex
391391
acp = complex(af)
392392
@test complex(acp) == acp
393393
@test isa(acp, SparseVector{ComplexF64,Int})
394394
@test exact_equal(acp, SparseVector(8, [2, 5, 6], complex([12., 35., 72.])))
395-
@test sparsevec(adjoint(adjoint(acp))) == acp
395+
@test sparsevec(Adjoint(Adjoint(acp))) == acp
396396
end
397397

398398
@testset "Type conversion" begin

0 commit comments

Comments
 (0)