Skip to content

Commit cf8d454

Browse files
authored
bidiag_forwardsub! with padded (#354)
* bidiag_forwardsub! with padded * avoid method overload error downstream * Update paddedtests.jl * increase cov * Update paddedtests.jl
1 parent befe4a0 commit cf8d454

File tree

4 files changed

+48
-3
lines changed

4 files changed

+48
-3
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "LazyArrays"
22
uuid = "5078a376-72f3-5289-bfd5-ec5146d43c02"
3-
version = "2.2.4"
3+
version = "2.2.5"
44

55
[deps]
66
ArrayLayouts = "4c555306-a7a7-4459-81d9-ec55ddd5c99a"

src/LazyArrays.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ import ArrayLayouts: AbstractQLayout, Dot, Dotu, Ldiv, Lmul, MatMulMatAdd, MatMu
3838
hermitianlayout, layout_getindex, layout_replace_in_print_matrix, ldivaxes, materialize,
3939
materialize!, mulreduce, reshapedlayout, rowsupport, scalarone, scalarzero, sub_materialize,
4040
sublayout, symmetriclayout, symtridiagonallayout, transposelayout, triangulardata,
41-
triangularlayout, tridiagonallayout, zero!, transtype, OnesLayout
41+
triangularlayout, tridiagonallayout, zero!, transtype, OnesLayout,
42+
diagonaldata, subdiagonaldata, supdiagonaldata
4243

4344
import FillArrays: AbstractFill, getindex_value
4445

src/padded.jl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,3 +589,35 @@ PaddedArray(A::T, n::Vararg{Integer,N}) where {T<:Number,N} = ApplyArray{T,N}(se
589589

590590

591591
BroadcastStyle(::Type{<:PaddedArray{<:Any,N}}) where N = LazyArrayStyle{N}()
592+
593+
594+
595+
function ArrayLayouts._bidiag_forwardsub!(M::Ldiv{<:Any,<:PaddedColumns,<:AbstractMatrix,<:AbstractVector})
596+
A, b_in = M.A, M.B
597+
dv = diagonaldata(A)
598+
ev = subdiagonaldata(A)
599+
b = paddeddata(b_in)
600+
N = length(b)
601+
dvj = dv[1]
602+
iszero(dvj) && throw(SingularException(1))
603+
b[1] = bj1 = dvj\b[1]
604+
@inbounds for j = 2:N
605+
bj = b[j]
606+
bj -= ev[j - 1] * bj1
607+
dvj = dv[j]
608+
iszero(dvj) && throw(SingularException(j))
609+
bj = dvj\bj
610+
b[j] = bj1 = bj
611+
end
612+
613+
@inbounds for j = N+1:length(b_in)
614+
iszero(bj1) && break
615+
bj = -ev[j - 1] * bj1
616+
dvj = dv[j]
617+
iszero(dvj) && throw(SingularException(j))
618+
bj = dvj\bj
619+
b_in[j] = bj1 = bj
620+
end
621+
622+
b_in
623+
end

test/paddedtests.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,18 @@ paddeddata(a::PaddedPadded) = a
420420
@test C'b Matrix(C)'b
421421
@test b'C b'Matrix(C)
422422
end
423-
end
424423

424+
@testset "Bidiagonal" begin
425+
B = Bidiagonal(1:5, 1:4, :L)
426+
b = Vcat(randn(5), Zeros(0))
427+
@test ArrayLayouts.ldiv!(B, deepcopy(b)) B\b
428+
c = cache(Zeros(5)); c[1] = 2;
429+
@test ArrayLayouts.ldiv!(B, c) B\[2; zeros(4)]
430+
431+
c = cache(Zeros(5)); c[1:2] = [1,2];
432+
@test_throws SingularException ArrayLayouts.ldiv!(Bidiagonal(0:4, 1:4, :L), c)
433+
@test_throws SingularException ArrayLayouts.ldiv!(Bidiagonal(-1:3, 1:4, :L), c)
434+
@test_throws SingularException ArrayLayouts.ldiv!(Bidiagonal(-4:0, 1:4, :L), c)
435+
end
436+
end
425437
end # module

0 commit comments

Comments
 (0)