diff --git a/base/deprecated.jl b/base/deprecated.jl index 48d17812143ff4..23b5d403c96c24 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -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 diff --git a/base/linalg/adjtrans.jl b/base/linalg/adjtrans.jl index d75494322715e5..53ee6ba35cbb1e 100644 --- a/base/linalg/adjtrans.jl +++ b/base/linalg/adjtrans.jl @@ -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) diff --git a/base/linalg/bidiag.jl b/base/linalg/bidiag.jl index 02f1baab392416..bbf83468fc8968 100644 --- a/base/linalg/bidiag.jl +++ b/base/linalg/bidiag.jl @@ -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 diff --git a/base/linalg/diagonal.jl b/base/linalg/diagonal.jl index 9f817a74828bc5..c10b82953b9033 100644 --- a/base/linalg/diagonal.jl +++ b/base/linalg/diagonal.jl @@ -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 diff --git a/base/linalg/linalg.jl b/base/linalg/linalg.jl index 3482798b52295b..8c21dd20761912 100644 --- a/base/linalg/linalg.jl +++ b/base/linalg/linalg.jl @@ -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 @@ -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 diff --git a/base/linalg/triangular.jl b/base/linalg/triangular.jl index aa9cb4d522c144..2a9736b1af0500 100644 --- a/base/linalg/triangular.jl +++ b/base/linalg/triangular.jl @@ -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) diff --git a/base/linalg/uniformscaling.jl b/base/linalg/uniformscaling.jl index d87e42b4a2e78b..00b5091e03221d 100644 --- a/base/linalg/uniformscaling.jl +++ b/base/linalg/uniformscaling.jl @@ -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 diff --git a/base/operators.jl b/base/operators.jl index d40cf227410e18..c6eb8c3ccaef36 100644 --- a/base/operators.jl +++ b/base/operators.jl @@ -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) diff --git a/base/sparse/linalg.jl b/base/sparse/linalg.jl index a816e9d2a00eea..d5cef054dc0ba4 100644 --- a/base/sparse/linalg.jl +++ b/base/sparse/linalg.jl @@ -938,10 +938,9 @@ function \(A::SparseMatrixCSC, B::AbstractVecOrMat) return \(qrfact(A), B) end end -\(::SparseMatrixCSC, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) -for (xform, f) in ((:Adjoint, :Ac_ldiv_B), (:Transpose, :At_ldiv_B)) +for (xform, f) in ((:Adjoint, :Ac_ldiv_B), (:Transpose, :At_ldiv_B)), rhstype in (:AbstractVector, :AbstractMatrix) @eval begin - function \(xformA::($xform){<:Any,<:SparseMatrixCSC}, B::AbstractVecOrMat) + function \(xformA::($xform){<:Any,<:SparseMatrixCSC}, B::$rhstype) A = xformA.parent m, n = size(A) if m == n @@ -962,9 +961,11 @@ for (xform, f) in ((:Adjoint, :Ac_ldiv_B), (:Transpose, :At_ldiv_B)) return ($f)(qrfact(A), B) end end - \(::($xform){<:Any,<:SparseMatrixCSC}, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) end end +\(::SparseMatrixCSC, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) +\(::Adjoint{<:Any,<:SparseMatrixCSC}, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) +\(::Transpose{<:Any,<:SparseMatrixCSC}, ::RowVector) = throw(DimensionMismatch("Cannot left-divide matrix by transposed vector")) function factorize(A::SparseMatrixCSC) m, n = size(A)