Skip to content

Commit f134f66

Browse files
authored
Try getting degenerate UL working (#46)
* Try getting degenerate UL working * Update Project.toml * inf band getindex * Update infbanded.jl * Update Project.toml * Update Project.toml * Update Project.toml * v0.4.3
1 parent ac70e7d commit f134f66

File tree

4 files changed

+68
-13
lines changed

4 files changed

+68
-13
lines changed

Project.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InfiniteLinearAlgebra"
22
uuid = "cde9dba0-b1de-11e9-2c62-0bab9446c55c"
3-
version = "0.4.2"
3+
version = "0.4.3"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"
@@ -16,16 +16,16 @@ MatrixFactorizations = "a3b82374-2e81-5b9e-98ce-41277c0e4c87"
1616
SemiseparableMatrices = "f8ebbe35-cbfb-4060-bf7f-b10e4670cf57"
1717

1818
[compat]
19-
ArrayLayouts = "0.4.4"
20-
BandedMatrices = "0.15.19"
19+
ArrayLayouts = "0.4.10"
20+
BandedMatrices = "0.15.23"
2121
BlockArrays = "0.12.12"
2222
BlockBandedMatrices = "0.9"
23-
FillArrays = "0.9.5, 0.10"
24-
InfiniteArrays = "0.8"
25-
LazyArrays = "0.17.5, 0.18"
23+
FillArrays = "0.10"
24+
InfiniteArrays = "0.8.3"
25+
LazyArrays = "0.19"
2626
LazyBandedMatrices = "0.3.2"
2727
MatrixFactorizations = "0.6"
28-
SemiseparableMatrices = "0.1.3"
28+
SemiseparableMatrices = "0.2"
2929
julia = "1.5"
3030

3131
[extras]

src/banded/infbanded.jl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
11
###
2+
# BandIndexing
3+
###
4+
5+
struct InfBandCartesianIndices <: AbstractVector{CartesianIndex{2}}
6+
b::Int
7+
end
8+
9+
InfBandCartesianIndices(b::Band) = InfBandCartesianIndices(b.i)
10+
11+
size(::InfBandCartesianIndices) = (∞,)
12+
getindex(B::InfBandCartesianIndices, k::Int) = B.b 0 ? CartesianIndex(k, k+B.b) : CartesianIndex(k-B.b, k)
13+
14+
Base.checkindex(::Type{Bool}, ::NTuple{2,OneToInf{Int}}, ::InfBandCartesianIndices) = true
15+
BandedMatrices.band_to_indices(_, ::NTuple{2,OneToInf{Int}}, b) = (InfBandCartesianIndices(b),)
16+
Base.BroadcastStyle(::Type{<:SubArray{<:Any,1,<:Any,Tuple{InfBandCartesianIndices}}}) = LazyArrayStyle{1}()
17+
18+
_inf_banded_sub_materialize(_, V) = V
19+
function _inf_banded_sub_materialize(::BandedColumns, V)
20+
A = parent(V)
21+
b = parentindices(V)[1].b
22+
data = bandeddata(A)
23+
l,u = bandwidths(A)
24+
if -l  b  u
25+
data[u+1-b, max(1,b+1):end]
26+
else
27+
Zeros{eltype(V)}(∞) # Not type stable
28+
end
29+
end
30+
31+
sub_materialize(_, V::SubArray{<:Any,1,<:AbstractMatrix,Tuple{InfBandCartesianIndices}}, ::Tuple{InfAxes}) =
32+
_inf_banded_sub_materialize(MemoryLayout(parent(V)), V)
33+
###
234
# Diagonal
335
###
436

@@ -423,4 +455,5 @@ function _bidiag_forwardsub!(M::Ldiv{<:Any,<:PaddedLayout})
423455
end
424456

425457
b_in
426-
end
458+
end
459+

src/inful.jl

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@ _ultailL1(c::Number, a::Number, b::Number) = (a + sign(a)*sqrt(a^2-4b*c))/2
2222

2323
function _ultailL1(C::AbstractMatrix, A::AbstractMatrix, B::AbstractMatrix)
2424
d = size(A,1)
25-
λs = filter!-> abs(λ)  1, eigvals([zeros(2,2) -B; -C -A], [B zeros(2,2); zeros(2,2) -B]))
25+
λs = filter!-> abs(λ)  1, eigvals([zeros(d,d) -B; -C -A], [B zeros(d,d); zeros(d,d) -B]))
2626
@assert length(λs) == d
2727
V = Matrix{eltype(λs)}(undef, d, d)
28-
for (j,λ) in enumerate(λs)
29-
V[:,j] = svd(A-λ*B - C/λ).V[:,end] # nullspace(A-λ*B - C/λ)
28+
j = 1
29+
for λ in union(λs)
30+
c = count(==(λ), λs) # multiplicities
31+
V[:,j:j+c-1] = svd(A-λ*B - C/λ).V[:,end-c+1:end] # nullspace(A-λ*B - C/λ)
32+
j += c
3033
end
3134
C*(V*Diagonal(inv.(λs))/V)
3235
end
@@ -72,4 +75,7 @@ _inf_getL(::BlockTridiagonalToeplitzLayout, F::UL) = mortar(Bidiagonal(F.factors
7275

7376

7477
getU(F::UL, ::NTuple{2,Infinity}) = _inf_getU(MemoryLayout(F.factors), F)
75-
getL(F::UL, ::NTuple{2,Infinity}) = _inf_getL(MemoryLayout(F.factors), F)
78+
getL(F::UL, ::NTuple{2,Infinity}) = _inf_getL(MemoryLayout(F.factors), F)
79+
80+
getU(F::UL{T,<:Tridiagonal}, ::NTuple{2,Infinity}) where T = _inf_getU(MemoryLayout(F.factors), F)
81+
getL(F::UL{T,<:Tridiagonal}, ::NTuple{2,Infinity}) where T = _inf_getL(MemoryLayout(F.factors), F)

test/runtests.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using InfiniteLinearAlgebra, BlockBandedMatrices, BlockArrays, BandedMatrices, InfiniteArrays, FillArrays, LazyArrays, Test,
22
MatrixFactorizations, ArrayLayouts, LinearAlgebra, Random, LazyBandedMatrices
33
import InfiniteLinearAlgebra: qltail, toeptail, tailiterate , tailiterate!, tail_de, ql_X!,
4-
InfToeplitz, PertToeplitz, TriToeplitz, InfBandedMatrix,
4+
InfToeplitz, PertToeplitz, TriToeplitz, InfBandedMatrix, InfBandCartesianIndices,
55
rightasymptotics, QLHessenberg, ConstRows, PertConstRows, BandedToeplitzLayout, PertToeplitzLayout
66
import Base: BroadcastStyle
77
import BlockArrays: _BlockArray
@@ -12,8 +12,11 @@ import LazyArrays: colsupport, ApplyStyle, MemoryLayout, ApplyLayout, LazyArrayS
1212
import InfiniteArrays: OneToInf
1313
import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayout
1414

15+
16+
1517
@testset "∞-banded" begin
1618
D = Diagonal(Fill(2,∞))
19+
1720
B = D[1:∞,2:∞]
1821
@test B isa BandedMatrix
1922
@test B[1:10,1:10] == diagm(-1 => Fill(2,9))
@@ -23,6 +26,14 @@ import LazyBandedMatrices: BroadcastBandedBlockBandedLayout, BroadcastBandedLayo
2326
x = [1; 2; zeros(∞)]
2427
@test A*x isa Vcat
2528
@test (A*x)[1:10] == A[1:10,1:10]*x[1:10]
29+
30+
@test InfBandCartesianIndices(0)[1:5] == CartesianIndex.(1:5,1:5)
31+
@test InfBandCartesianIndices(1)[1:5] == CartesianIndex.(1:5,2:6)
32+
@test InfBandCartesianIndices(-1)[1:5] == CartesianIndex.(2:6,1:5)
33+
34+
@test D[band(0)] Fill(2,∞)
35+
@test D[band(1)] Fill(0,∞)
36+
@test A[band(0)][2:10] == 2:10
2637
end
2738

2839
@testset "∞-block arrays" begin
@@ -133,6 +144,11 @@ end
133144
@test (A + I)[1:100,1:100] == A[1:100,1:100]+I
134145
@test (I + A)[1:100,1:100] == I+A[1:100,1:100]
135146
@test (I - A)[1:100,1:100] == I-A[1:100,1:100]
147+
148+
@test (A - im*I)[1:100,1:100] == A[1:100,1:100]-im*I
149+
@test (A + im*I)[1:100,1:100] == A[1:100,1:100]+im*I
150+
@test (im*I + A)[1:100,1:100] == im*I+A[1:100,1:100]
151+
@test (im*I - A)[1:100,1:100] == im*I-A[1:100,1:100]
136152
end
137153

138154
@testset "Fill" begin

0 commit comments

Comments
 (0)