From d0d0baec671636ef3a03c499a889986b25710625 Mon Sep 17 00:00:00 2001 From: Daniel Karrasch Date: Tue, 29 Nov 2022 22:17:53 +0100 Subject: [PATCH] Adjustments to `AbstractQ` intro in LinearAlgebra (#275) --- Project.toml | 2 +- src/banded/bandedqr.jl | 36 ++++++++++++++++++++++-------------- test/test_bandedlu.jl | 6 +++--- test/test_bandedqr.jl | 2 +- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/Project.toml b/Project.toml index fbe0b19e..a5528860 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "BandedMatrices" uuid = "aae01518-5342-5314-be14-df237901396f" -version = "0.17.8" +version = "0.17.9" [deps] ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a" diff --git a/src/banded/bandedqr.jl b/src/banded/bandedqr.jl index 2709f5a4..9904988b 100644 --- a/src/banded/bandedqr.jl +++ b/src/banded/bandedqr.jl @@ -1,3 +1,5 @@ +AdjointQType = isdefined(LinearAlgebra, :AdjointQ) ? LinearAlgebra.AdjointQ : Adjoint + _qr(::AbstractBandedLayout, ax, A) = _banded_qr(ax, A) _banded_qr(_, A) = qr!(BandedMatrix{float(eltype(A))}(A, (bandwidth(A,1),bandwidth(A,1)+bandwidth(A,2)))) @@ -63,9 +65,9 @@ function banded_qr_lmul!(A, B) B end -function banded_qr_lmul!(adjA::Adjoint, B) +function banded_qr_lmul!(adjA::AdjointQType, B) require_one_based_indexing(B) - A = adjA.parent + A = parent(adjA) mA, nA = size(A.factors) mB, nB = size(B,1), size(B,2) if mA != mB @@ -119,8 +121,8 @@ function banded_qr_rmul!(A, Q) end A end -function banded_qr_rmul!(A, adjQ::Adjoint) - Q = adjQ.parent +function banded_qr_rmul!(A, adjQ::AdjointQType) + Q = parent(adjQ) mQ, nQ = size(Q.factors) mA, nA = size(A,1), size(A,2) if nA != mQ @@ -148,21 +150,27 @@ function banded_qr_rmul!(A, adjQ::Adjoint) end banded_lmul!(A::QRPackedQ, B::AbstractVecOrMat) = banded_qr_lmul!(A, B) -banded_lmul!(adjA::Adjoint{<:Any,<:QRPackedQ}, B::AbstractVecOrMat) = banded_qr_lmul!(adjA, B) +banded_lmul!(adjA::AdjointQType{<:Any,<:QRPackedQ}, B::AbstractVecOrMat) = banded_qr_lmul!(adjA, B) banded_rmul!(A::AbstractMatrix, Q::QRPackedQ) = banded_qr_rmul!(A, Q) -banded_rmul!(A::AbstractMatrix, adjQ::Adjoint{<:Any,<:QRPackedQ}) = banded_qr_rmul!(A, adjQ) +banded_rmul!(A::AbstractMatrix, adjQ::AdjointQType{<:Any,<:QRPackedQ}) = banded_qr_rmul!(A, adjQ) -lmul!(A::QRPackedQ{<:Any,<:AbstractBandedMatrix}, B::AbstractVecOrMat) = banded_lmul!(A,B) -lmul!(adjA::Adjoint{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}, B::AbstractVecOrMat) = banded_lmul!(adjA,B) -lmul!(A::QRPackedQ{<:Any,BandedSubBandedMatrix{T,C,R,I1,I2}}, B::AbstractVecOrMat) where {T,C,R,I1<:AbstractUnitRange,I2<:AbstractUnitRange} = +lmul!(A::QRPackedQ{<:Any,<:AbstractBandedMatrix}, B::AbstractVector) = banded_lmul!(A,B) +lmul!(A::QRPackedQ{<:Any,<:AbstractBandedMatrix}, B::AbstractMatrix) = banded_lmul!(A,B) +lmul!(adjA::AdjointQType{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}, B::AbstractVector) = banded_lmul!(adjA,B) +lmul!(adjA::AdjointQType{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}, B::AbstractMatrix) = banded_lmul!(adjA,B) +lmul!(A::QRPackedQ{<:Any,BandedSubBandedMatrix{T,C,R,I1,I2}}, B::AbstractVector) where {T,C,R,I1<:AbstractUnitRange,I2<:AbstractUnitRange} = + banded_lmul!(A,B) +lmul!(A::QRPackedQ{<:Any,BandedSubBandedMatrix{T,C,R,I1,I2}}, B::AbstractMatrix) where {T,C,R,I1<:AbstractUnitRange,I2<:AbstractUnitRange} = banded_lmul!(A,B) -lmul!(adjA::Adjoint{T,<:QRPackedQ{T,<:BandedSubBandedMatrix{T,C,R,I1,I2,t}}}, B::AbstractVecOrMat) where {T,C,R,I1<:AbstractUnitRange,I2<:AbstractUnitRange,t} = +lmul!(adjA::AdjointQType{T,<:QRPackedQ{T,<:BandedSubBandedMatrix{T,C,R,I1,I2,t}}}, B::AbstractVector) where {T,C,R,I1<:AbstractUnitRange,I2<:AbstractUnitRange,t} = + banded_lmul!(adjA,B) +lmul!(adjA::AdjointQType{T,<:QRPackedQ{T,<:BandedSubBandedMatrix{T,C,R,I1,I2,t}}}, B::AbstractMatrix) where {T,C,R,I1<:AbstractUnitRange,I2<:AbstractUnitRange,t} = banded_lmul!(adjA,B) -# rmul!(A::AbstractMatrix, adjQ::Adjoint{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}) = banded_rmul!(A, adjA) -# rmul!(A::StridedMatrix, adjQ::Adjoint{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}) = banded_rmul!(A, adjA) +# rmul!(A::AbstractMatrix, adjQ::AdjointQType{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}) = banded_rmul!(A, adjA) +# rmul!(A::StridedMatrix, adjQ::AdjointQType{<:Any,<:QRPackedQ{<:Any,<:AbstractBandedMatrix}}) = banded_rmul!(A, adjA) rmul!(A::StridedVecOrMat{T}, Q::QRPackedQ{T,B}) where {T<:BlasFloat,B<:AbstractBandedMatrix{T}} = banded_rmul!(A, Q) -rmul!(A::StridedVecOrMat{T}, adjQ::Adjoint{<:Any,<:QRPackedQ{T,B}}) where {T<:BlasComplex,B<:AbstractBandedMatrix{T}} = banded_rmul!(A, adjQ) -rmul!(A::StridedVecOrMat{T}, adjQ::Adjoint{<:Any,<:QRPackedQ{T,B}}) where {T<:BlasReal,B<:AbstractBandedMatrix{T}} = banded_rmul!(A, adjQ) +rmul!(A::StridedVecOrMat{T}, adjQ::AdjointQType{<:Any,<:QRPackedQ{T,B}}) where {T<:BlasComplex,B<:AbstractBandedMatrix{T}} = banded_rmul!(A, adjQ) +rmul!(A::StridedVecOrMat{T}, adjQ::AdjointQType{<:Any,<:QRPackedQ{T,B}}) where {T<:BlasReal,B<:AbstractBandedMatrix{T}} = banded_rmul!(A, adjQ) function _banded_widerect_ldiv!(A::QR{T}, B) where T diff --git a/test/test_bandedlu.jl b/test/test_bandedlu.jl index 4d0df520..5d1e7a9a 100644 --- a/test/test_bandedlu.jl +++ b/test/test_bandedlu.jl @@ -153,9 +153,9 @@ struct _foo <: Number end end @testset "zero matrix" begin - for A in (BandedMatrix{Float64}(undef, 0,0, 1,1), - BandedMatrix{Float64}(undef, 0,3, 1,1), - BandedMatrix{Float64}(undef, 0,0, -1,-2)) + for A in (BandedMatrix{Float64}(undef, (0,0), (1,1)), + BandedMatrix{Float64}(undef, (0,3), (1,1)), + BandedMatrix{Float64}(undef, (0,0), (-1,-2))) @test lu(A).factors == zeros(size(A)...) @test lu(A) \ zeros(0) == zeros(0) end diff --git a/test/test_bandedqr.jl b/test/test_bandedqr.jl index 83cf9c56..8a319708 100644 --- a/test/test_bandedqr.jl +++ b/test/test_bandedqr.jl @@ -91,7 +91,7 @@ Random.seed!(0) @test qr(V) isa QR{Float64,<:BandedMatrix{Float64}} @test qr(V).R ≈ qr(Matrix(V)).R @test qr(V).τ ≈ LinearAlgebra.qrfactUnblocked!(Matrix(V)).τ - @test qr(V).Q ≈ qr(Matrix(V)).Q + @test Matrix(qr(V).Q) ≈ Matrix(qr(Matrix(V)).Q) @test Matrix(qr(V)) ≈ V B = BandedMatrix(A,(1,2)) # pad V = view(copy(B),1:5,1:6)