Skip to content

Commit

Permalink
materialize! for banded QRPackedQLayout (#440)
Browse files Browse the repository at this point in the history
* materialize! for banded QRPackedQLayout

* Update Project.toml

* Update test_bandedqr.jl

* Add resize
  • Loading branch information
dlfivefifty authored Apr 27, 2024
1 parent c385419 commit 6e8982c
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "BandedMatrices"
uuid = "aae01518-5342-5314-be14-df237901396f"
version = "1.6.1"
version = "1.7"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
3 changes: 2 additions & 1 deletion src/BandedMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import ArrayLayouts: AbstractTridiagonalLayout, BidiagonalLayout, BlasMatLdivVec
colsupport, conjlayout, copymutable_oftype_layout, diagonaldata, dualadjoint, hermitiandata,
hermitianlayout, materialize, materialize!, reflector!, reflectorApply!, rowsupport,
sub_materialize, subdiagonaldata, sublayout, supdiagonaldata, symmetricdata, symmetriclayout,
symmetricuplo, transposelayout, triangulardata, triangularlayout, zero!
symmetricuplo, transposelayout, triangulardata, triangularlayout, zero!,
QRPackedQLayout, AdjQRPackedQLayout

import FillArrays: AbstractFill, getindex_value, _broadcasted_zeros, unique_value, OneElement, RectDiagonal

Expand Down
14 changes: 14 additions & 0 deletions src/banded/BandedMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -992,3 +992,17 @@ function show(io::IO, B::BandedMatrix)
end
print(io, ")")
end


###
# resize
###

function resize(A::BandedMatrix, n::Integer, m::Integer)
l,u = bandwidths(A)
_BandedMatrix(reshape(resize!(vec(bandeddata(A)), (l+u+1)*m), l+u+1, m), n, l,u)
end
function resize(A::BandedSubBandedMatrix, n::Integer, m::Integer)
l,u = bandwidths(A)
_BandedMatrix(reshape(resize!(vec(copy(bandeddata(A))), (l+u+1)*m), l+u+1, m), n, l,u)
end
8 changes: 8 additions & 0 deletions src/banded/bandedqr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,11 @@ for BTyp in (:AbstractBandedMatrix, :BandedSubBandedMatrix), Typ in (:StridedVe
end
end
end



materialize!(M::Lmul{<:QRPackedQLayout{<:AbstractBandedLayout}}) = banded_qr_lmul!(M.A,M.B)
materialize!(M::Lmul{<:AdjQRPackedQLayout{<:AbstractBandedLayout}}) = banded_qr_lmul!(M.A,M.B)

materialize!(M::Rmul{<:Any,<:QRPackedQLayout{<:AbstractBandedLayout}}) = banded_qr_rmul!(M.A,M.B)
materialize!(M::Rmul{<:Any,<:AdjQRPackedQLayout{<:AbstractBandedLayout}}) = banded_qr_rmul!(M.A,M.B)
15 changes: 14 additions & 1 deletion test/test_banded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module TestBanded

using ArrayLayouts
using BandedMatrices
import BandedMatrices: _BandedMatrix
using BandedMatrices: _BandedMatrix, resize
using FillArrays
using LinearAlgebra
using SparseArrays
Expand Down Expand Up @@ -545,6 +545,19 @@ include("mymatrix.jl")
@test BandedMatrices.colrange(A, 3) == 3:3
@test BandedMatrices.colrange(A, 4) == 4:4
end

@testset "resize" begin
B = brand(5,6,2,1)
= resize(B, 10,7)
@test size(B̃) == (10,7)
@test bandwidths(B̃) == (2,1)
@test B̃[1:5,1:6] == B

C = resize(view(B,1:4,1:5), 10, 7)
@test size(C) == (10,7)
@test bandwidths(C) == (2,1)
@test C[1:4,1:5] == B[1:4,1:5]
end
end

end # module
16 changes: 13 additions & 3 deletions test/test_bandedqr.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module TestBandedQR

using BandedMatrices, LinearAlgebra, Test, Random
using BandedMatrices, ArrayLayouts, LinearAlgebra, Test, Random
import BandedMatrices: banded_qr!
Random.seed!(0)

Expand Down Expand Up @@ -123,13 +123,23 @@ Random.seed!(0)
@test lmul!(Q', view(BandedMatrix(B,(size(B,1),2)),:,4:10)) Q'*B[:,4:10]
end

@testset "lmul!" begin
for T in (Float64,ComplexF64,Float32,ComplexF32)
A = brand(T,10,10,3,2)
Q,R = qr(A)
B = randn(T, 10, 2)
@test ArrayLayouts.lmul!(Q', copy(B)) == lmul!(Q', copy(B)) Q'B
@test ArrayLayouts.lmul!(Q, copy(B)) == lmul!(Q, copy(B)) Q*B
end
end

@testset "rmul!" begin
for T in (Float64,ComplexF64,Float32,ComplexF32)
A = brand(T,10,10,3,2)
Q,R = qr(A)
B = randn(T, 2, 10)
@test rmul!(copy(B), Q') B*Q'
@test rmul!(copy(B), Q) B*Q
@test ArrayLayouts.rmul!(copy(B), Q') == rmul!(copy(B), Q') B*Q'
@test ArrayLayouts.rmul!(copy(B), Q) == rmul!(copy(B), Q) B*Q
end
end
end
Expand Down

2 comments on commit 6e8982c

@dlfivefifty
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/105716

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v1.7.0 -m "<description of version>" 6e8982c0d8dbe7faa562af09cc3c349d5e91e5f4
git push origin v1.7.0

Please sign in to comment.