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
… de-jazzed passthroughs.
  • Loading branch information
Sacha0 committed Dec 7, 2017
1 parent 651b754 commit 574003f
Show file tree
Hide file tree
Showing 9 changed files with 235 additions and 141 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
52 changes: 52 additions & 0 deletions base/linalg/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,55 @@ similar(A::AdjOrTransAbsMat, ::Type{T}, dims::Dims{2}) where {T} =
# sundry basic definitions
parent(A::AdjOrTrans) = A.parent
vec(v::AdjOrTransAbsVec) = v.parent


### linear algebra

# generic fallbacks inherited from A[ct]_(mul|ldiv|rdiv)_B[ct]
# --> mul, adjoint args
*(a::Adjoint, b) = adjoint(a.parent) * b
*(a, b::Adjoint) = a * adjoint(b.parent)
*(a::Adjoint, b::Adjoint) = adjoint(a.parent) * adjoint(b.parent)
# --> mul, transpose args
*(a::Transpose,b) = transpose(a.parent) * b
*(a, b::Transpose) = a * transpose(b.parent)
*(a::Transpose, b::Transpose) = transpose(a.parent) * transpose(b.parent)
# --> rdiv, adjoint args
/(a::Adjoint, b) = adjoint(a.parent) / b
/(a, b::Adjoint) = a / adjoint(b.parent)
/(a::Adjoint, b::Adjoint) = adjoint(a.parent) / adjoint(b.parent)
# --> rdiv, transpose args
/(a::Transpose, b) = transpose(a.parent) / b
/(a, b::Transpose) = a / transpose(b.parent)
/(a::Transpose, b::Transpose) = transpose(a.parent) / transpose(b.parent)
# --> ldiv, adjoint args
\(a::Adjoint, b) = adjoint(a.parent) \ b
\(a, b::Adjoint) = a \ adjoint(b.parent)
\(a::Adjoint, b::Adjoint) = adjoint(a.parent) \ adjoint(b.parent)
# --> ldiv, transpose args
\(a::Transpose, b) = transpose(a.parent) \ b
\(a, b::Transpose) = a \ transpose(b.parent)
\(a::Transpose, b::Transpose) = \(a, transpose(b.parent))
# --> mixed args
\(a::Adjoint, b::Transpose) = \(a, transpose(b.parent))

# ambiguity killers (TODO: clean up eventually)
/(A::Adjoint{<:Any,<:Vector}, B::Matrix) = adjoint(A.parent) / B
/(A::Transpose{<:Any,<:Vector}, B::Matrix) = transpose(A.parent) / B
*(A::Adjoint{<:Any,<:Matrix}, B::Adjoint{<:Any,<:Vector}) = A * adjoint(B.parent)
\(A::Matrix, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
\(A::Matrix, B::Transpose{<:Any,<:Matrix}) = A \ transpose(B.parent)
\(A::Adjoint{<:Any,<:Matrix}, B::Vector) = adjoint(A.parent) \ B
\(A::Adjoint{<:Any,<:Matrix}, B::Matrix) = adjoint(A.parent) \ B
\(A::Transpose{<:Any,<:Matrix}, B::Vector) = transpose(A.parent) \ B
\(A::Transpose{<:Any,<:Matrix}, B::Matrix) = transpose(A.parent) \ B
/(A::Matrix, B::Transpose{<:Any,<:Matrix}) = A / transpose(B.parent)
/(A::Matrix, B::Adjoint{<:Any,<:Matrix}) = A / adjoint(B.parent)
/(A::Transpose{<:Any,<:Matrix}, B::Matrix) = transpose(A.parent) / B
/(A::Adjoint{<:Any,<:Matrix}, B::Matrix) = adjoint(A.parent) / B
\(A::AbstractMatrix, B::Adjoint{<:Any,<:AbstractMatrix}) = A \ adjoint(B.parent)
\(A::Adjoint{<:Any,<:AbstractMatrix}, B::AbstractMatrix) = adjoint(A.parent) \ B
\(A::Adjoint{<:Any,<:AbstractMatrix}, B::Adjoint{<:Any,<:AbstractMatrix}) = adjoint(A.parent) \ B
\(A::Vector, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
/(A::Matrix, B::Adjoint{<:Any,<:AbstractVector}) = A / adjoint(B.parent)
\(A::AbstractVector, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
8 changes: 8 additions & 0 deletions base/linalg/bidiag.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,3 +654,11 @@ function fill!(A::Union{Bidiagonal,Tridiagonal,SymTridiagonal}, x)
throw(ArgumentError("array A of type $(typeof(A)) and size $(size(A)) can
not be filled with x=$x, since some of its entries are constrained."))
end

# ambiguity killers
\(A::Transpose{TA,<:Bidiagonal{TA}}, B::Transpose{TB,Matrix{TB}}) where {TA<:Number,TB<:Number} = transpose(A.parent) \ B
\(A::Bidiagonal{TA}, B::Transpose{TB,Matrix{TB}}) where {TA<:Number,TB<:Number} = A \ transpose(B.parent)
\(A::Bidiagonal{TA}, B::Adjoint{TB,<:AbstractMatrix{TB}}) where {TA<:Number,TB<:Number} = A \ adjoint(B.parent)
\(A::Adjoint{TA,<:Bidiagonal{TA}}, B::Adjoint{TB,<:AbstractMatrix{TB}}) where {TA<:Number,TB<:Number} = adjoint(A.parent) \ B
\(A::Bidiagonal{TA}, B::Adjoint{TB,<:AbstractVector{TB}}) where {TA<:Number,TB<:Number} = A \ adjoint(B.parent)
\(A::Adjoint{TA,<:Bidiagonal{TA}}, B::Adjoint{TB,<:AbstractVector{TB}}) where {TA<:Number,TB<:Number} = adjoint(A.parent) \ B
3 changes: 3 additions & 0 deletions base/linalg/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -459,3 +459,6 @@ function svdfact(D::Diagonal)
U, s, V = svd(D)
SVD(U, s, V')
end

# ambiguity killer
\(A::Transpose{<:Any,<:Diagonal}, B::Matrix) = transpose(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
20 changes: 20 additions & 0 deletions base/linalg/triangular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2386,3 +2386,23 @@ for func in (:svd, :svdfact, :svdfact!, :svdvals)
end

factorize(A::AbstractTriangular) = A

# ambiguity killers
\(A::Union{UpperTriangular,LowerTriangular}, B::Transpose{<:Any,<:Matrix}) = A \ transpose(B.parent)
\(A::Union{UnitUpperTriangular,UnitLowerTriangular}, B::Transpose{<:Any,<:Matrix}) = A \ transpose(B.parent)
\(A::Union{UpperTriangular,LowerTriangular}, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
\(A::Union{UnitUpperTriangular,UnitLowerTriangular}, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
\(A::Adjoint{<:Any,<:Union{UpperTriangular,LowerTriangular}}, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
\(A::Adjoint{<:Any,<:Union{UnitUpperTriangular,UnitLowerTriangular}}, B::Adjoint{<:Any,<:Matrix}) = A \ adjoint(B.parent)
\(A::Transpose{<:Any,<:Union{UpperTriangular,LowerTriangular}}, B::Transpose{<:Any,<:Matrix}) = A \ transpose(B.parent)
\(A::Transpose{<:Any,<:Union{UnitUpperTriangular,UnitLowerTriangular}}, B::Transpose{<:Any,<:Matrix}) = A \ transpose(B.parent)
/(A::Transpose{<:Any,<:Matrix}, B::Union{UpperTriangular,LowerTriangular}) = transpose(A.parent) / B
/(A::Transpose{<:Any,<:Matrix}, B::Union{UnitUpperTriangular,UnitLowerTriangular}) = transpose(A.parent) / B
/(A::Adjoint{<:Any,<:Matrix}, B::Union{UpperTriangular,LowerTriangular}) = adjoint(A.parent) / B
/(A::Adjoint{<:Any,<:Matrix}, B::Union{UnitUpperTriangular,UnitLowerTriangular}) = adjoint(A.parent) / B
/(A::Transpose{<:Any,<:Matrix}, B::Transpose{<:Any,<:Union{UpperTriangular,LowerTriangular}}) = transpose(A.parent) / B
/(A::Transpose{<:Any,<:Matrix}, B::Transpose{<:Any,<:Union{UnitUpperTriangular,UnitLowerTriangular}}) = transpose(A.parent) / B
/(A::Adjoint{<:Any,<:Matrix}, B::Adjoint{<:Any,<:Union{UpperTriangular,LowerTriangular}}) = adjoint(A.parent) / B
/(A::Adjoint{<:Any,<:Matrix}, B::Adjoint{<:Any,<:Union{UnitUpperTriangular,UnitLowerTriangular}}) = adjoint(A.parent) / B
/(A::Matrix, B::Adjoint{<:Any,<:Union{UpperTriangular,LowerTriangular}}) = A / adjoint(B.parent)
/(A::Matrix, B::Adjoint{<:Any,<:Union{UnitUpperTriangular,UnitLowerTriangular}}) = A / adjoint(B.parent)
3 changes: 3 additions & 0 deletions base/linalg/uniformscaling.jl
Original file line number Diff line number Diff line change
Expand Up @@ -386,3 +386,6 @@ Array(s::UniformScaling, dims::Dims{2}) = Matrix(s, dims)
## Diagonal construction from UniformScaling
Diagonal{T}(s::UniformScaling, m::Integer) where {T} = Diagonal{T}(fill(T(s.λ), m))
Diagonal(s::UniformScaling, m::Integer) = Diagonal{eltype(s)}(s, m)

# ambiguity killer
*(adjI::Adjoint{<:Any,<:UniformScaling}, B::Matrix) = adjoint(adjI.parent) * B
Loading

0 comments on commit 574003f

Please sign in to comment.