Skip to content

Commit

Permalink
Replace A[ct]_(mul|ldiv|rdiv)_B[ct][!] defs in base/operators.jl with…
Browse files Browse the repository at this point in the history
… shims to lazy calls in base/deprecated.jl, w/o transferring methods.
  • Loading branch information
Sacha0 committed Dec 10, 2017
1 parent 6fb85f0 commit e80697d
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 138 deletions.
122 changes: 122 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2823,6 +2823,128 @@ end
A_mul_Bc(A::AbstractVecOrMat{T}, R::AbstractRotation{S}) where {T,S} = *(A, Adjoint(R))
end

# A[ct]_(mul|ldiv|rdiv)_B[ct][!] methods from base/operators.jl, to deprecate
@eval Base begin
using Base.LinAlg: Adjoint, Transpose
"""
Ac_ldiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ`` \\ ``Bᵀ``.
"""
Ac_ldiv_Bt(a,b) = \(Adjoint(a), Transpose(b))
"""
At_ldiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ`` \\ ``Bᵀ``.
"""
At_ldiv_Bt(a,b) = \(Transpose(a), Transpose(b))
"""
A_ldiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A`` \\ ``Bᵀ``.
"""
A_ldiv_Bt(a,b) = \(a, Transpose(b))
"""
At_ldiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ`` \\ ``B``.
"""
At_ldiv_B(a,b) = \(Transpose(a), b)
"""
Ac_ldiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ`` \\ ``Bᴴ``.
"""
Ac_ldiv_Bc(a,b) = \(Adjoint(a), Adjoint(b))
"""
A_ldiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A`` \\ ``Bᴴ``.
"""
A_ldiv_Bc(a,b) = \(a, Adjoint(b))
"""
Ac_ldiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ`` \\ ``B``.
"""
Ac_ldiv_B(a,b) = \(Adjoint(a), b)
"""
At_rdiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ / Bᵀ``.
"""
At_rdiv_Bt(a,b) = /(Transpose(a), Transpose(b))
"""
A_rdiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A / Bᵀ``.
"""
A_rdiv_Bt(a,b) = /(a, Transpose(b))
"""
At_rdiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ / B``.
"""
At_rdiv_B(a,b) = /(Transpose(a), b)
"""
Ac_rdiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ / Bᴴ``.
"""
Ac_rdiv_Bc(a,b) = /(Adjoint(a), Adjoint(b))
"""
A_rdiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A / Bᴴ``.
"""
A_rdiv_Bc(a,b) = /(a, Adjoint(b))
"""
Ac_rdiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ / B``.
"""
Ac_rdiv_B(a,b) = /(Adjoint(a), b)
"""
At_mul_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ⋅Bᵀ``.
"""
At_mul_Bt(a,b) = *(Transpose(a), Transpose(b))
"""
A_mul_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A⋅Bᵀ``.
"""
A_mul_Bt(a,b) = *(a, Transpose(b))
"""
At_mul_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ⋅B``.
"""
At_mul_B(a,b) = *(Transpose(a), b)
"""
Ac_mul_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ Bᴴ``.
"""
Ac_mul_Bc(a,b) = *(Adjoint(a), Adjoint(b))
"""
A_mul_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A⋅Bᴴ``.
"""
A_mul_Bc(a,b) = *(a, Adjoint(b))
"""
Ac_mul_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ⋅B``.
"""
Ac_mul_B(a,b) = *(Adjoint(a), b)
end

# re. A_mul_B deprecation, don't forget to:
# 1) delete function shims in base/linalg/linalg.jl

# issue #24822
@deprecate_binding Display AbstractDisplay

Expand Down
12 changes: 11 additions & 1 deletion base/linalg/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,16 @@ similar(A::AdjOrTrans, ::Type{T}, dims::Dims{N}) where {T,N} = similar(A.parent,
parent(A::AdjOrTrans) = A.parent
vec(v::AdjOrTransAbsVec) = v.parent


### linear algebra

# definitions necessary for test/linalg/rowvector.jl to pass
# should be cleaned up / revised as necessary in the future
/(A::Transpose{<:Any,<:Vector}, B::Matrix) = /(transpose(A.parent), B)
/(A::Transpose{<:Any,<:Vector}, B::Transpose{<:Any,<:Matrix}) = /(transpose(A.parent), B)
*(A::Adjoint{<:Any,<:Matrix}, B::Adjoint{<:Any,<:Vector}) = *(adjoint(A.parent), adjoint(B.parent))


# dismabiguation methods
*(A::Transpose{<:Any,<:AbstractVector}, B::Adjoint{<:Any,<:AbstractVector}) = transpose(A.parent) * B
*(A::Transpose{<:Any,<:AbstractVector}, B::Adjoint{<:Any,<:AbstractMatrix}) = transpose(A.parent) * B
Expand All @@ -107,4 +117,4 @@ vec(v::AdjOrTransAbsVec) = v.parent
*(A::Adjoint{<:Any,<:AbstractVector}, B::Transpose{<:Any,<:AbstractMatrix}) = adjoint(A.parent) * B
*(A::Adjoint{<:Any,<:AbstractMatrix}, B::Adjoint{<:Any,<:AbstractVector}) = A * adjoint(B.parent)
*(A::Adjoint{<:Any,<:AbstractMatrix}, B::Transpose{<:Any,<:AbstractVector}) = A * transpose(B.parent)
*(A::Adjoint{<:Any,<:AbstractMatrix}, B::Transpose{<:Any,<:AbstractMatrix}) = adjoint(A.parent) * B
*(A::Adjoint{<:Any,<:AbstractMatrix}, B::Transpose{<:Any,<:AbstractMatrix}) = adjoint(A.parent) * B
23 changes: 22 additions & 1 deletion base/linalg/linalg.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# shims to maintain existence of names in Base module in A_mul_B deprecation process
function Ac_ldiv_Bt end
function At_ldiv_Bt end
function A_ldiv_Bt end
function At_ldiv_B end
function Ac_ldiv_Bc end
function A_ldiv_Bc end
function Ac_ldiv_B end
function At_rdiv_Bt end
function A_rdiv_Bt end
function At_rdiv_B end
function Ac_rdiv_Bc end
function A_rdiv_Bc end
function Ac_rdiv_B end
function At_mul_Bt end
function A_mul_Bt end
function At_mul_B end
function Ac_mul_Bc end
function A_mul_Bc end
function Ac_mul_B end

"""
Linear algebra module. Provides array arithmetic,
matrix factorizations and other linear algebra related
Expand Down Expand Up @@ -237,7 +258,7 @@ function char_uplo(uplo::Symbol)
end
end

# shims to maintain existence of names in A_mul_B deprecation process
# shims to maintain existence of names in LinAlg module in A_mul_B deprecation process
function A_mul_B! end
function Ac_mul_B! end
function Ac_mul_B! end
Expand Down
2 changes: 2 additions & 0 deletions base/linalg/lq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ function *(A::QR{TA},B::LQ{TB}) where {TA,TB}
TAB = promote_type(TA, TB)
A_mul_B!(convert(Factorization{TAB},A), convert(Factorization{TAB},B))
end
*(A::Adjoint{<:Any,<:LQ}, B::LQ) = adjoint(A.parent) * B
*(A::LQ, B::Adjoint{<:Any,<:LQ}) = A * adjoint(B.parent)

## Multiplication by Q
### QB
Expand Down
7 changes: 7 additions & 0 deletions base/linalg/rowvector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ pinv(v::RowVector, tol::Real=0) = pinv(v', tol)'
/(rowvec::RowVector, transmat::Transpose{<:Any,<:AbstractMatrix}) = transpose(transmat.parent \ transpose(rowvec))
/(rowvec::RowVector, adjmat::Adjoint{<:Any,<:AbstractMatrix}) = adjoint(adjmat.parent \ adjoint(rowvec))


# definitions necessary for test/linalg/dense.jl to pass
# should be cleaned up / revised as necessary in the future
/(A::Number, B::Adjoint{<:Any,<:RowVector}) = /(A, adjoint(B.parent))
/(A::Matrix, B::RowVector) = adjoint(adjoint(B) \ adjoint(A))


# dismabiguation methods
*(A::Adjoint{<:Any,<:AbstractVector}, B::Transpose{<:Any,<:RowVector}) = adjoint(A.parent) * B
*(A::Adjoint{<:Any,<:AbstractMatrix}, B::Transpose{<:Any,<:RowVector}) = A * transpose(B.parent)
Expand Down
2 changes: 2 additions & 0 deletions base/linalg/tridiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ broadcast(::typeof(ceil), ::Type{T}, M::Tridiagonal) where {T<:Integer} =
transpose(M::Tridiagonal) = Tridiagonal(M.du, M.d, M.dl)
adjoint(M::Tridiagonal) = conj(transpose(M))

\(A::Adjoint{<:Any,<:Tridiagonal}, B::Adjoint{<:Any,<:StridedVecOrMat}) = adjoint(A.parent) \ adjoint(B.parent)

function diag(M::Tridiagonal{T}, n::Integer=0) where T
# every branch call similar(..., ::Int) to make sure the
# same vector type is returned independent of n
Expand Down
2 changes: 2 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ end
copy(J::UniformScaling) = UniformScaling(J.λ)

transpose(J::UniformScaling) = J
Transpose(S::UniformScaling) = transpose(S)
adjoint(J::UniformScaling) = UniformScaling(conj(J.λ))
Adjoint(S::UniformScaling) = adjoint(S)

one(::Type{UniformScaling{T}}) where {T} = UniformScaling(one(T))
one(J::UniformScaling{T}) where {T} = one(UniformScaling{T})
Expand Down
136 changes: 0 additions & 136 deletions base/operators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -762,142 +762,6 @@ julia> adjoint(A)
adjoint(x) = conj(transpose(x))
conj(x) = x

# transposed multiply

"""
Ac_mul_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ⋅B``.
"""
Ac_mul_B(a,b) = adjoint(a)*b

"""
A_mul_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A⋅Bᴴ``.
"""
A_mul_Bc(a,b) = a*adjoint(b)

"""
Ac_mul_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ Bᴴ``.
"""
Ac_mul_Bc(a,b) = adjoint(a)*adjoint(b)

"""
At_mul_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ⋅B``.
"""
At_mul_B(a,b) = transpose(a)*b

"""
A_mul_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A⋅Bᵀ``.
"""
A_mul_Bt(a,b) = a*transpose(b)

"""
At_mul_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ⋅Bᵀ``.
"""
At_mul_Bt(a,b) = transpose(a)*transpose(b)

# transposed divide

"""
Ac_rdiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ / B``.
"""
Ac_rdiv_B(a,b) = adjoint(a)/b

"""
A_rdiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A / Bᴴ``.
"""
A_rdiv_Bc(a,b) = a/adjoint(b)

"""
Ac_rdiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ / Bᴴ``.
"""
Ac_rdiv_Bc(a,b) = adjoint(a)/adjoint(b)

"""
At_rdiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ / B``.
"""
At_rdiv_B(a,b) = transpose(a)/b

"""
A_rdiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A / Bᵀ``.
"""
A_rdiv_Bt(a,b) = a/transpose(b)

"""
At_rdiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ / Bᵀ``.
"""
At_rdiv_Bt(a,b) = transpose(a)/transpose(b)

"""
Ac_ldiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ`` \\ ``B``.
"""
Ac_ldiv_B(a,b) = adjoint(a)\b

"""
A_ldiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A`` \\ ``Bᴴ``.
"""
A_ldiv_Bc(a,b) = a\adjoint(b)

"""
Ac_ldiv_Bc(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ`` \\ ``Bᴴ``.
"""
Ac_ldiv_Bc(a,b) = adjoint(a)\adjoint(b)

"""
At_ldiv_B(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ`` \\ ``B``.
"""
At_ldiv_B(a,b) = transpose(a)\b

"""
A_ldiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``A`` \\ ``Bᵀ``.
"""
A_ldiv_Bt(a,b) = a\transpose(b)

"""
At_ldiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᵀ`` \\ ``Bᵀ``.
"""
At_ldiv_Bt(a,b) = At_ldiv_B(a,transpose(b))

"""
Ac_ldiv_Bt(A, B)
For matrices or vectors ``A`` and ``B``, calculates ``Aᴴ`` \\ ``Bᵀ``.
"""
Ac_ldiv_Bt(a,b) = Ac_ldiv_B(a,transpose(b))

"""
widen(x)
Expand Down
3 changes: 3 additions & 0 deletions base/sparse/linalg.jl
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,9 @@ ldiv!(U::UpperTriangular{T,<:SparseMatrixCSCUnion{T}}, B::StridedVecOrMat) where

(\)(L::LowerTriangular{T,<:SparseMatrixCSCUnion{T}}, B::SparseMatrixCSC) where {T} = A_ldiv_B!(L, Array(B))
(\)(U::UpperTriangular{T,<:SparseMatrixCSCUnion{T}}, B::SparseMatrixCSC) where {T} = A_ldiv_B!(U, Array(B))
\(A::Transpose{<:Real,<:Hermitian{<:Real,<:SparseMatrixCSC}}, B::Vector) = A.parent \ B
\(A::Transpose{<:Complex,<:Hermitian{<:Complex,<:SparseMatrixCSC}}, B::Vector) = transpose(A.parent) \ B
\(A::Transpose{<:Number,<:Symmetric{<:Number,<:SparseMatrixCSC}}, B::Vector) = A.parent \ B

function rdiv!(A::SparseMatrixCSC{T}, D::Diagonal{T}) where T
dd = D.diag
Expand Down
3 changes: 3 additions & 0 deletions test/linalg/generic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,10 @@ Base.zero(::Type{ModInt{n}}) where {n} = ModInt{n}(0)
Base.zero(::ModInt{n}) where {n} = ModInt{n}(0)
Base.one(::Type{ModInt{n}}) where {n} = ModInt{n}(1)
Base.one(::ModInt{n}) where {n} = ModInt{n}(1)
Base.adjoint(a::ModInt{n}) where {n} = ModInt{n}(conj(a))
Base.transpose(a::ModInt{n}) where {n} = a # see Issue 20978
Base.LinAlg.Adjoint(a::ModInt{n}) where {n} = adjoint(a)
Base.LinAlg.Transpose(a::ModInt{n}) where {n} = transpose(a)

@testset "Issue 22042" begin
A = [ModInt{2}(1) ModInt{2}(0); ModInt{2}(1) ModInt{2}(1)]
Expand Down

0 comments on commit e80697d

Please sign in to comment.