Skip to content
Open
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ jobs:
fail-fast: false
matrix:
version:
- '1.10'
- 'lts'
- '1'
os:
- ubuntu-latest
- macOS-latest
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "SemiseparableMatrices"
uuid = "f8ebbe35-cbfb-4060-bf7f-b10e4670cf57"
authors = ["Sheehan Olver <[email protected]>"]
version = "0.4.0"
version = "0.5.0"

[deps]
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
Expand Down
386 changes: 386 additions & 0 deletions src/BandedPlusSemiseparableMatrices.jl

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions src/SemiseparableMatrices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module SemiseparableMatrices
using LinearAlgebra: BlasFloat
using ArrayLayouts, BandedMatrices, LazyArrays, LinearAlgebra, MatrixFactorizations, Base

import Base: size, getindex, setindex!, convert, copyto!
import Base: size, getindex, setindex!, convert, copyto!, copy, axes
import MatrixFactorizations: QR, QRPackedQ, getQ, getR, QRPackedQLayout, AdjQRPackedQLayout
import LinearAlgebra: qr, qr!, lmul!, ldiv!, rmul!, triu!, factorize, rank
import BandedMatrices: _banded_qr!, bandeddata, resize
Expand All @@ -11,7 +11,7 @@ import ArrayLayouts: MemoryLayout, sublayout, sub_materialize, MatLdivVec, mater
triangulardata, zero!, _copyto!, colsupport, rowsupport,
_qr, _qr!, _factorize

export SemiseparableMatrix, AlmostBandedMatrix, LowRankMatrix, ApplyMatrix, ApplyArray, almostbandwidths, almostbandedrank
export SemiseparableMatrix, AlmostBandedMatrix, LowRankMatrix, ApplyMatrix, ApplyArray, almostbandwidths, almostbandedrank, BandedPlusSemiseparableMatrix

LazyArraysBandedMatricesExt = Base.get_extension(LazyArrays, :LazyArraysBandedMatricesExt)
BandedLayouts = LazyArraysBandedMatricesExt.BandedLayouts
Expand All @@ -30,5 +30,6 @@ separablerank(A) = size(arguments(ApplyLayout{typeof(*)}(),A)[1],2)
include("SemiseparableMatrix.jl")
include("AlmostBandedMatrix.jl")
include("invbanded.jl")
include("BandedPlusSemiseparableMatrices.jl")

end # module
4 changes: 3 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ using SemiseparableMatrices, BandedMatrices, LinearAlgebra, Test

include("test_semiseparable.jl")
include("test_almostbanded.jl")
include("test_invbanded.jl")
include("test_invbanded.jl")
include("test_bandedplussemiseparable.jl")
include("test_qr.jl")
10 changes: 10 additions & 0 deletions test/test_bandedplussemiseparable.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using SemiseparableMatrices, Test

@testset "BandedPlusSemiseparable" begin
n = 20
l, m, r, p = 4, 5, 2, 3
B = brandn(n,n,l,m)
U,V = randn(n,r), randn(n,r)
W,S = randn(n,p), randn(n,p)
@test BandedPlusSemiseparableMatrix(B, (U,V), (W,S)) B + tril(U*V',-1) + triu(W*S',1)
end
39 changes: 39 additions & 0 deletions test/test_getindex.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
using BandedMatrices
using Test, LinearAlgebra
using Random
import .BandedPlusSemiseparableMatrices: BandedPlusSemiseparableMatrix, BandedPlusSemiseparableQRPerturbedFactors

# test get index for BandedPlusSemiseparableQRPerturbedFactors

n = 10
l = 2
m = 3
r = 4
p = 5
B = brandn(n,n,l,m)
U = randn(n,r)
V = randn(n,r)
W = randn(n,p)
S = randn(n,p)
Q = randn(r,p)
K = randn(r,r)
Eₛ = randn(r,min(l+m,n))
Xₛ = randn(min(l,n),p)
Yₛ = randn(min(l,n),r)
Zₛ = randn(min(l,n),min(l+m,n))
A = BandedPlusSemiseparableQRPerturbedFactors(U,V,W,S,B)
A.Q[:,:] = Q
A.K[:,:] = K
A.Eₛ[:,:] = Eₛ
A.Xₛ[:,:] = Xₛ
A.Yₛ[:,:] = Yₛ
A.Zₛ[:,:] = Zₛ

E = [Eₛ zeros(r,max(n-(l+m),0))]
X = [Xₛ; zeros(max(n - l, 0),p)]
Y = [Yₛ; zeros(max(n - l, 0),r)]
Z = [Zₛ zeros(min(l,n),max(n-(l+m),0)); zeros(max(n-l,0),min(l+m,n)) zeros(max(n-l,0), max(n-(l+m),0))]

A₀ = tril(U*V',-1) + Matrix(B) + triu(W*S',1)
AA = A₀ + U*Q*S' + U*K*U'*A₀ + U*E + X*S' + Y*U'*A₀ + Z
@test Matrix(A) ≈ AA
31 changes: 31 additions & 0 deletions test/test_qr.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using BandedMatrices, LinearAlgebra, Random, SemiseparableMatrices, Test
using SemiseparableMatrices: BandedPlusSemiseparableQRPerturbedFactors
#Random.seed!(1234)

@testset "QR" begin
n = 20
l, m, r, p = 4, 5, 2, 3
B = brandn(n,n,l,m)

@testset "BandedPlusSemiseparableQRPerturbedFactors" begin
U,V = randn(n,r), randn(n,r)
W,S = randn(n,p), randn(n,p)
A = BandedPlusSemiseparableQRPerturbedFactors(B, (U,V), (W,S))
fact_true = LinearAlgebra.qrfactUnblocked!(Matrix(A))
fact = qr!(A)
@test A ≈ fact_true.factors ≈ fact.factors
@test fact_true.τ ≈ fact.τ
end

@testset "BandedPlusSemiseparableMatrix" begin
U,V = randn(n,r), randn(n,r)
W,S = randn(n,p), randn(n,p)
A = BandedPlusSemiseparableMatrix(B,(U,V),(W,S))
A_true = Matrix(A)
fact_true = LinearAlgebra.qrfactUnblocked!(Matrix(A))
fact = qr(A)
@test A ≈ A_true
@test fact_true.factors ≈ fact.factors
@test fact_true.τ ≈ fact.τ
end
end
Loading