Skip to content

Commit d1704dd

Browse files
committed
solves with QL
1 parent ddd2bb6 commit d1704dd

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

src/InfiniteLinearAlgebra.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import LinearAlgebra: lmul!, ldiv!, matprod, qr, AbstractTriangular, AbstractQ,
1313
import LazyArrays: CachedArray, CachedMatrix, CachedVector, DenseColumnMajor, FillLayout, ApplyMatrix, check_mul_axes, ApplyStyle, LazyArrayApplyStyle, LazyArrayStyle,
1414
CachedMatrix, CachedArray, resizedata!, MemoryLayout, mulapplystyle, LmulStyle, RmulStyle,
1515
colsupport, rowsupport, triangularlayout, factorize, subarraylayout, sub_materialize,
16-
@lazymul, ApplyLayout
16+
@lazymul, ApplyLayout, TriangularLayout, PaddedLayout, materialize!, MatLdivVec, triangulardata
1717
import MatrixFactorizations: ql, ql!, QLPackedQ, getL, getR, reflector!, reflectorApply!, QL, QR, QRPackedQ
1818

1919
import BlockArrays: BlockSizes, cumulsizes, _find_block, AbstractBlockVecOrMat, sizes_from_blocks

src/banded/infbanded.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const TriToeplitz{T} = Tridiagonal{T,Fill{T,1,Tuple{OneToInf{Int}}}}
22
const ConstRowMatrix{T} = ApplyMatrix{T,typeof(*),<:Tuple{<:AbstractVector,<:AbstractFill{<:Any,2,Tuple{OneTo{Int},OneToInf{Int}}}}}
3-
const PertConstRowMatrix{T} = Hcat{T,<:Tuple{Matrix{T},<:ConstRowMatrix{T}}}
3+
const PertConstRowMatrix{T} = Hcat{T,<:Tuple{Array{T},<:ConstRowMatrix{T}}}
44
const InfToeplitz{T} = BandedMatrix{T,<:ConstRowMatrix{T},OneToInf{Int}}
55
const PertToeplitz{T} = BandedMatrix{T,<:PertConstRowMatrix{T},OneToInf{Int}}
66

src/infql.jl

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,4 +276,28 @@ end
276276
function (*)(A::Adjoint{T,<:QLPackedQ{T,<:InfBlockBandedMatrix}}, x::AbstractVector{S}) where {T,S}
277277
TS = promote_op(matprod, T, S)
278278
lmul!(A, cache(convert(AbstractVector{TS},x)))
279-
end
279+
end
280+
281+
ldiv!(F::QLProduct, b::AbstractVector) = ldiv!(F.L, lmul!(F.Q',b))
282+
283+
function materialize!(M::MatLdivVec{<:TriangularLayout{'L','N',BandedColumns{PertConstRows}},<:PaddedLayout})
284+
A,b = M.A,M.B
285+
require_one_based_indexing(A, b)
286+
n = size(A, 2)
287+
if !(n == length(b))
288+
throw(DimensionMismatch("second dimension of left hand side A, $n, and length of right hand side b, $(length(b)), must be equal"))
289+
end
290+
data = triangulardata(A)
291+
nz = nzzeros(b,1)
292+
@inbounds for j in 1:n
293+
iszero(data[j,j]) && throw(SingularException(j))
294+
bj = b[j] = data[j,j] \ b[j]
295+
allzero = j > nz && iszero(bj)
296+
for i in (j+1:n) colsupport(data,j)
297+
b[i] -= data[i,j] * bj
298+
allzero = allzero && iszero(b[i])
299+
end
300+
allzero && break
301+
end
302+
b
303+
end

test/test_infql.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,9 @@ import BandedMatrices: _BandedMatrix
159159
@test Qn[1:10,1:10] * diagm(0 => [Ones(5); -(-1).^(1:5)]) Q[1:10,1:10]
160160
@test diagm(0 => [Ones(5); -(-1).^(1:5)]) * Ln[1:10,1:10] L[1:10,1:10]
161161
end
162+
163+
@testset "solve with QL" begin
164+
A = BandedMatrix(-1 => Fill(2,∞), 0 => Fill(5,∞), 1 => Fill(0.5,∞))
165+
@test (qr(A)\Vcat(1.0,Zeros(∞)))[1:1000] (ql(A)\Vcat(1.0,Zeros(∞)))[1:1000]
166+
end
162167
end

0 commit comments

Comments
 (0)