Skip to content

Commit 3428e88

Browse files
dkarraschmforets
andauthored
Fix eigvecs(:::SymTridiagonal) with longer off-diagonal vector (#40526)
Co-authored-by: Marcelo Forets <[email protected]>
1 parent 5784cd3 commit 3428e88

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

stdlib/LinearAlgebra/src/lapack.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3835,7 +3835,7 @@ for (stev, stebz, stegr, stein, elty) in
38353835
eev = copy(ev)
38363836
eev[n] = zero($elty)
38373837
else
3838-
throw(DimensionMismatch("ev has length $(length(ev)) but should be either $(length(dv) - 1) or $(length(dv))"))
3838+
throw(DimensionMismatch("ev has length $ne but needs one less than or equal to dv's length, $n)"))
38393839
end
38403840

38413841
abstol = Vector{$elty}(undef, 1)
@@ -3878,10 +3878,15 @@ for (stev, stebz, stegr, stein, elty) in
38783878
require_one_based_indexing(dv, ev_in, w_in, iblock_in, isplit_in)
38793879
chkstride1(dv, ev_in, w_in, iblock_in, isplit_in)
38803880
n = length(dv)
3881-
if length(ev_in) != n - 1
3882-
throw(DimensionMismatch("ev_in has length $(length(ev_in)) but needs one less than dv's length, $n)"))
3881+
ne = length(ev_in)
3882+
if ne == n - 1
3883+
ev = [ev_in; zero($elty)]
3884+
elseif ne == n
3885+
ev = copy(ev_in)
3886+
ev[n] = zero($elty)
3887+
else
3888+
throw(DimensionMismatch("ev_in has length $ne but needs one less than or equal to dv's length, $n)"))
38833889
end
3884-
ev = [ev_in; zeros($elty,1)]
38853890
ldz = n #Leading dimension
38863891
#Number of eigenvalues to find
38873892
if !(1 <= length(w_in) <= n)

stdlib/LinearAlgebra/test/lapack.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ end
410410
@test_throws DimensionMismatch LAPACK.stev!('U',d,rand(elty,11))
411411
@test_throws DimensionMismatch LAPACK.stebz!('A','B',zero(elty),zero(elty),0,0,-1.,d,rand(elty,10))
412412
@test_throws DimensionMismatch LAPACK.stegr!('N','A',d,rand(elty,11),zero(elty),zero(elty),0,0)
413-
@test_throws DimensionMismatch LAPACK.stein!(d,zeros(elty,10),zeros(elty,10),zeros(BlasInt,10),zeros(BlasInt,10))
413+
@test_throws DimensionMismatch LAPACK.stein!(d,zeros(elty,11),zeros(elty,10),zeros(BlasInt,10),zeros(BlasInt,10))
414414
@test_throws DimensionMismatch LAPACK.stein!(d,e,zeros(elty,11),zeros(BlasInt,10),zeros(BlasInt,10))
415415
end
416416
end

stdlib/LinearAlgebra/test/tridiag.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,8 @@ end
590590
F2 = eigen(A2)
591591
test_approx_eq_modphase(F.vectors, F2.vectors)
592592
@test F.values F2.values eigvals(A) eigvals(A2)
593+
@test eigvecs(A) eigvecs(A2)
594+
@test eigvecs(A, eigvals(A)[1:1]) eigvecs(A2, eigvals(A2)[1:1])
593595
end
594596

595597
@testset "non-commutative algebra (#39701)" begin

0 commit comments

Comments
 (0)