Skip to content

Commit 6f4b663

Browse files
committed
extend to symtridiagonal case
1 parent 91886b1 commit 6f4b663

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/tridiag.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ julia> SymTridiagonal(B)
107107
[1 2; 3 4] [1 2; 2 3]
108108
```
109109
"""
110-
function SymTridiagonal(A::AbstractMatrix)
110+
function (::Type{SymTri})(A::AbstractMatrix) where {SymTri <: SymTridiagonal}
111111
checksquare(A)
112112
du = diag(A, 1)
113113
d = diag(A)
114114
dl = diag(A, -1)
115115
if _checksymmetric(d, du, dl)
116-
SymTridiagonal(d, du)
116+
SymTri(d, du)
117117
else
118118
throw(ArgumentError("matrix is not symmetric; cannot convert to SymTridiagonal"))
119119
end

test/tridiag.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,6 +1121,12 @@ end
11211121
diagm(-1 => [1,2], 1=>[1,2])]
11221122
B = convert(SymTridiagonal, M)
11231123
@test B == SymTridiagonal(M)
1124+
B = convert(SymTridiagonal{Int8}, M)
1125+
@test B == M
1126+
@test B isa SymTridiagonal{Int8}
1127+
B = convert(SymTridiagonal{Int8, OffsetVector{Int8, Vector{Int8}}}, M)
1128+
@test B == M
1129+
@test B isa SymTridiagonal{Int8, OffsetVector{Int8, Vector{Int8}}}
11241130
end
11251131
@test_throws InexactError convert(SymTridiagonal, fill(5, 4, 4))
11261132
@test_throws InexactError convert(SymTridiagonal, diagm(0=>fill(NaN,4)))

0 commit comments

Comments
 (0)