Skip to content

Commit 373d5a4

Browse files
authored
Backport "Fix structure test for strided matrices" (#57217)
x-ref JuliaLang/LinearAlgebra.jl#1184
1 parent 9eaadcd commit 373d5a4

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

stdlib/LinearAlgebra/src/dense.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1417,25 +1417,26 @@ This returns a `5×5 Bidiagonal{Float64}`, which can now be passed to other line
14171417
(e.g. eigensolvers) which will use specialized methods for `Bidiagonal` types.
14181418
"""
14191419
function factorize(A::AbstractMatrix{T}) where T
1420+
require_one_based_indexing(A)
14201421
m, n = size(A)
14211422
if m == n
14221423
if m == 1 return A[1] end
14231424
utri = true
14241425
utri1 = true
14251426
herm = true
14261427
sym = true
1427-
for j = 1:n-1, i = j+1:m
1428-
if utri1
1428+
for j = 1:n, i = j:m
1429+
if (j < n) && (i > j) && utri1 # indices are off-diagonal
14291430
if A[i,j] != 0
14301431
utri1 = i == j + 1
14311432
utri = false
14321433
end
14331434
end
14341435
if sym
1435-
sym &= A[i,j] == A[j,i]
1436+
sym &= A[i,j] == transpose(A[j,i])
14361437
end
14371438
if herm
1438-
herm &= A[i,j] == conj(A[j,i])
1439+
herm &= A[i,j] == adjoint(A[j,i])
14391440
end
14401441
if !(utri1|herm|sym) break end
14411442
end
@@ -1448,7 +1449,7 @@ function factorize(A::AbstractMatrix{T}) where T
14481449
if ltri1
14491450
for i = 1:n-1
14501451
if A[i,i+1] != 0
1451-
ltri &= false
1452+
ltri = false
14521453
break
14531454
end
14541455
end

stdlib/LinearAlgebra/test/dense.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1285,4 +1285,10 @@ end
12851285
@test eltype(A) == eltype(T)
12861286
end
12871287

1288+
@testset "structure of dense matrices" begin
1289+
# A is neither triangular nor symmetric/Hermitian
1290+
A = [1 im 2; -im 0 3; 2 3 im]
1291+
@test factorize(A) isa LU{ComplexF64, Matrix{ComplexF64}, Vector{Int}}
1292+
end
1293+
12881294
end # module TestDense

0 commit comments

Comments
 (0)