Skip to content

Commit c69c1ae

Browse files
committed
updates
1 parent 7e2ae2e commit c69c1ae

File tree

3 files changed

+62
-39
lines changed

3 files changed

+62
-39
lines changed

src/InfiniteLinearAlgebra.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import FillArrays: AbstractFill
1111
import BandedMatrices: BandedMatrix, _BandedMatrix, bandeddata, bandwidths
1212
import LinearAlgebra: lmul!, ldiv!, matprod, qr, AbstractTriangular, AbstractQ, adjoint, transpose
1313
import LazyArrays: CachedArray, DenseColumnMajor, FillLayout, ApplyMatrix, check_mul_axes, ApplyStyle, LazyArrayApplyStyle, LazyArrayStyle,
14-
CachedMatrix, CachedArray, resizedata!, MemoryLayout
14+
CachedMatrix, CachedArray, resizedata!, MemoryLayout, mulapplystyle
1515
import MatrixFactorizations: ql, ql!, QLPackedQ, getL, getR, reflector!, reflectorApply!, QL, QR, QRPackedQ
1616

1717
import BlockArrays: BlockSizes, cumulsizes, _find_block, AbstractBlockVecOrMat, sizes_from_blocks
@@ -22,9 +22,7 @@ import BlockBandedMatrices: _BlockSkylineMatrix, _BandedMatrix, AbstractBlockSiz
2222
BlockSkylineSizes, BlockSkylineMatrix, BlockBandedMatrix, _BlockBandedMatrix, BlockTridiagonal
2323

2424

25-
# Fix ∞ BandedMatrix
26-
# ApplyStyle(::typeof(*), ::Type{<:BandedMatrix{<:Any,<:Any,<:OneToInf}}, _::Type{<:AbstractArray}...) =
27-
# LazyArrayApplyStyle()
25+
2826

2927
# BroadcastStyle(::Type{<:BandedMatrix{<:Any,<:Any,<:OneToInf}}) = LazyArrayStyle{2}()
3028

@@ -57,4 +55,13 @@ include("banded/infqltoeplitz.jl")
5755
include("infql.jl")
5856
include("infqr.jl")
5957

58+
###
59+
# temporary work arounds
60+
###
61+
62+
# Fix ∞ BandedMatrix
63+
ApplyStyle(::typeof(*), ::Type{<:BandedMatrix{<:Any,<:AbstractFill,<:OneToInf}}...) =
64+
LazyArrayApplyStyle()
65+
66+
6067
end # module

src/banded/hessenbergq.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ getindex(Q::LowerHessenbergQ, i::Integer, j::Integer) = (Q')[j,i]'
130130
# QLPackedQ, QRPackedQ <-> Lower/UpperHessenbergQ
131131
###
132132

133+
UpperHessenbergQ(Q::LinearAlgebra.QRPackedQ) = UpperHessenbergQ(QRPackedQ(Q))
134+
133135
function UpperHessenbergQ(Q::QRPackedQ{T}) where T
134136
@assert bandwidth(Q.factors,1) == 1
135137
q = Vector{Matrix{T}}()

test/runtests.jl

Lines changed: 49 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -6,55 +6,62 @@ import BlockArrays: _BlockArray
66
import BlockBandedMatrices: isblockbanded, _BlockBandedMatrix
77
import MatrixFactorizations: QLPackedQ
88
import BandedMatrices: bandeddata, _BandedMatrix
9+
import LazyArrays: colsupport
910

1011
@testset "Algebra" begin
11-
A = BlockTridiagonal(Vcat([fill(1.0,2,1),Matrix(1.0I,2,2),Matrix(1.0I,2,2),Matrix(1.0I,2,2)],Fill(Matrix(1.0I,2,2), ∞)),
12-
Vcat([zeros(1,1)], Fill(zeros(2,2), ∞)),
13-
Vcat([fill(1.0,1,2),Matrix(1.0I,2,2)], Fill(Matrix(1.0I,2,2), ∞)))
14-
15-
@test A isa InfiniteLinearAlgebra.BlockTriPertToeplitz
16-
@test isblockbanded(A)
12+
@testset "BlockTridiagonal" begin
13+
A = BlockTridiagonal(Vcat([fill(1.0,2,1),Matrix(1.0I,2,2),Matrix(1.0I,2,2),Matrix(1.0I,2,2)],Fill(Matrix(1.0I,2,2), ∞)),
14+
Vcat([zeros(1,1)], Fill(zeros(2,2), ∞)),
15+
Vcat([fill(1.0,1,2),Matrix(1.0I,2,2)], Fill(Matrix(1.0I,2,2), ∞)))
16+
17+
@test A isa InfiniteLinearAlgebra.BlockTriPertToeplitz
18+
@test isblockbanded(A)
1719

18-
@test A[Block.(1:2),Block(1)] == A[1:3,1:1] == reshape([0.,1.,1.],3,1)
20+
@test A[Block.(1:2),Block(1)] == A[1:3,1:1] == reshape([0.,1.,1.],3,1)
1921

20-
@test BlockBandedMatrix(A)[1:100,1:100] == BlockBandedMatrix(A,(2,1))[1:100,1:100] == BlockBandedMatrix(A,(1,1))[1:100,1:100] == A[1:100,1:100]
22+
@test BlockBandedMatrix(A)[1:100,1:100] == BlockBandedMatrix(A,(2,1))[1:100,1:100] == BlockBandedMatrix(A,(1,1))[1:100,1:100] == A[1:100,1:100]
2123

22-
@test (A - I)[1:100,1:100] == A[1:100,1:100]-I
23-
@test (A + I)[1:100,1:100] == A[1:100,1:100]+I
24-
@test (I + A)[1:100,1:100] == I+A[1:100,1:100]
25-
@test (I - A)[1:100,1:100] == I-A[1:100,1:100]
26-
27-
A = BandedMatrix(-3 => Fill(7/10,∞), -2 => Fill(1,∞), 1 => Fill(2im,∞))
28-
Ac = BandedMatrix(A')
29-
At = BandedMatrix(transpose(A))
30-
@test Ac[1:10,1:10] (A')[1:10,1:10] A[1:10,1:10]'
31-
@test At[1:10,1:10] transpose(A)[1:10,1:10] transpose(A[1:10,1:10])
24+
@test (A - I)[1:100,1:100] == A[1:100,1:100]-I
25+
@test (A + I)[1:100,1:100] == A[1:100,1:100]+I
26+
@test (I + A)[1:100,1:100] == I+A[1:100,1:100]
27+
@test (I - A)[1:100,1:100] == I-A[1:100,1:100]
28+
end
29+
@testset "BandedMatrix" begin
30+
A = BandedMatrix(-3 => Fill(7/10,∞), -2 => Fill(1,∞), 1 => Fill(2im,∞))
31+
Ac = BandedMatrix(A')
32+
At = BandedMatrix(transpose(A))
33+
@test Ac[1:10,1:10] (A')[1:10,1:10] A[1:10,1:10]'
34+
@test At[1:10,1:10] transpose(A)[1:10,1:10] transpose(A[1:10,1:10])
3235

33-
A = BandedMatrix(-1 => Vcat(Float64[], Fill(1/4,∞)), 0 => Vcat([1.0+im],Fill(0,∞)), 1 => Vcat(Float64[], Fill(1,∞)))
34-
Ac = BandedMatrix(A')
35-
At = BandedMatrix(transpose(A))
36-
@test Ac[1:10,1:10] (A')[1:10,1:10] A[1:10,1:10]'
37-
@test At[1:10,1:10] transpose(A)[1:10,1:10] transpose(A[1:10,1:10])
36+
A = BandedMatrix(-1 => Vcat(Float64[], Fill(1/4,∞)), 0 => Vcat([1.0+im],Fill(0,∞)), 1 => Vcat(Float64[], Fill(1,∞)))
37+
Ac = BandedMatrix(A')
38+
At = BandedMatrix(transpose(A))
39+
@test Ac[1:10,1:10] (A')[1:10,1:10] A[1:10,1:10]'
40+
@test At[1:10,1:10] transpose(A)[1:10,1:10] transpose(A[1:10,1:10])
3841

39-
A = BandedMatrix(-2 => Vcat(Float64[], Fill(1/4,∞)), 0 => Vcat([1.0+im,2,3],Fill(0,∞)), 1 => Vcat(Float64[], Fill(1,∞)))
40-
Ac = BandedMatrix(A')
41-
At = BandedMatrix(transpose(A))
42-
@test Ac[1:10,1:10] (A')[1:10,1:10] A[1:10,1:10]'
43-
@test At[1:10,1:10] transpose(A)[1:10,1:10] transpose(A[1:10,1:10])
42+
A = BandedMatrix(-2 => Vcat(Float64[], Fill(1/4,∞)), 0 => Vcat([1.0+im,2,3],Fill(0,∞)), 1 => Vcat(Float64[], Fill(1,∞)))
43+
Ac = BandedMatrix(A')
44+
At = BandedMatrix(transpose(A))
45+
@test Ac[1:10,1:10] (A')[1:10,1:10] A[1:10,1:10]'
46+
@test At[1:10,1:10] transpose(A)[1:10,1:10] transpose(A[1:10,1:10])
4447

45-
A = _BandedMatrix(Fill(1,4,∞),∞,1,2)
46-
@test A*A isa ApplyArray
47-
@test (A^2)[1:10,1:10] == (A*A)[1:10,1:10] == (A[1:100,1:100]^2)[1:10,1:10]
48-
@test (A^3)[1:10,1:10] == (A*A*A)[1:10,1:10] == (A[1:100,1:100]^3)[1:10,1:10]
48+
A = _BandedMatrix(Fill(1,4,∞),∞,1,2)
49+
@test A*A isa ApplyArray
50+
@test (A^2)[1:10,1:10] == (A*A)[1:10,1:10] == (A[1:100,1:100]^2)[1:10,1:10]
51+
@test (A^3)[1:10,1:10] == (A*A*A)[1:10,1:10] == (A[1:100,1:100]^3)[1:10,1:10]
52+
end
4953

50-
@testset "Diagonal" begin
54+
@testset "Fill" begin
5155
A = _BandedMatrix(Ones(1,∞),∞,-1,1)
5256
@test 1.0 .* A isa BandedMatrix{Float64,<:Fill}
5357
@test_skip Ones(∞) .* A
5458
@test 2.0 .* A isa BandedMatrix{Float64,<:Fill}
5559
@test A .* 2.0 isa BandedMatrix{Float64,<:Fill}
5660
@test Eye(∞)*A isa BandedMatrix{Float64,<:Fill}
5761
@test A*Eye(∞) isa BandedMatrix{Float64,<:Fill}
62+
end
63+
64+
@testset "Banded Broadast" begin
5865
A = _BandedMatrix((1:∞)',∞,-1,1)
5966
@test 2.0 .* A isa BandedMatrix{Float64,<:Adjoint}
6067
@test A .* 2.0 isa BandedMatrix{Float64,<:Adjoint}
@@ -65,10 +72,17 @@ import BandedMatrices: bandeddata, _BandedMatrix
6572
@test A .* 2.0 isa BandedMatrix
6673
@test Eye(∞) * A isa BandedMatrix
6774
@test A * Eye(∞) isa BandedMatrix
75+
b = 1:
76+
@test bandwidths(b .* A) == (0,1)
77+
@test Base.replace_in_print_matrix(b.*A, 2,1,"0.0") == ""
78+
@test bandwidths(A .* b) == (0,1)
79+
@test A .* b' isa BroadcastArray
80+
@test bandwidths(A .* b') == bandwidths(A .* b')
81+
@test colsupport(A .* b', 3) == 2:3
6882
end
69-
83+
7084
@testset "Triangle OP recurrences" begin
71-
mortar((n -> 1:n).(1:∞))
85+
# mortar((n -> 1:n).(1:∞))
7286
end
7387
# Multivariate OPs Corollary (3)
7488
# n = 5

0 commit comments

Comments
 (0)