Skip to content

Commit eabb167

Browse files
Cover more lu instance types
1 parent 43dafbb commit eabb167

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "ArrayInterface"
22
uuid = "4fba245c-0d91-5ea0-9b3e-6abc04ee57a9"
3-
version = "7.5.1"
3+
version = "7.5.2"
44

55
[deps]
66
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"

src/ArrayInterface.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,28 @@ function lu_instance(jac_prototype::SparseMatrixCSC)
600600
end
601601
end
602602

603+
function lu_instance(A::Symmetric{T}) where {T}
604+
noUnitT = typeof(zero(T))
605+
luT = LinearAlgebra.lutype(noUnitT)
606+
ipiv = Vector{LinearAlgebra.BlasInt}(undef, 0)
607+
info = zero(LinearAlgebra.BlasInt)
608+
return LU{luT}(similar(A, 0, 0), ipiv, info)
609+
end
610+
611+
noalloc_diag(A::Diagonal) = A.diag
612+
noalloc_diag(A::Tridiagonal) = A.d
613+
noalloc_diag(A::SymTridiagonal) = A.dv
614+
615+
function lu_instance(A::Union{Tridiagonal{T},Diagonal{T},SymTridiagonal{T}}) where {T}
616+
noUnitT = typeof(zero(T))
617+
luT = LinearAlgebra.lutype(noUnitT)
618+
ipiv = Vector{LinearAlgebra.BlasInt}(undef, 0)
619+
info = zero(LinearAlgebra.BlasInt)
620+
vectype = similar(noalloc_diag(A), 0)
621+
newA = Tridiagonal(vectype, vectype, vectype)
622+
return LU{luT}(newA, ipiv, info)
623+
end
624+
603625
"""
604626
lu_instance(a::Number) -> a
605627

test/core.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@ end
7171
A = sprand(50, 50, 0.5)
7272
@test lu_instance(A) isa typeof(lu(A))
7373
@test lu_instance(1) === 1
74+
75+
@test lu_instance(Symmetric(rand(3,3))) isa typeof(lu(Symmetric(rand(4,4))))
76+
@test lu_instance(Tridiagonal(rand(3),rand(4),rand(3))) isa typeof(lu(Tridiagonal(rand(3),rand(4),rand(3))))
77+
@test lu_instance(SymTridiagonal(rand(4),rand(3))) isa typeof(lu(SymTridiagonal(rand(4),rand(3))))
78+
@test lu_instance(Diagonal(rand(4))) isa typeof(lu(Diagonal(rand(4))))
7479
end
7580

7681
@testset "ismutable" begin

0 commit comments

Comments
 (0)