Skip to content

Backport "Fix structure test for strided matrices" #57218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: release-1.10
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions stdlib/LinearAlgebra/src/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1341,25 +1341,26 @@ This returns a `5×5 Bidiagonal{Float64}`, which can now be passed to other line
(e.g. eigensolvers) which will use specialized methods for `Bidiagonal` types.
"""
function factorize(A::AbstractMatrix{T}) where T
require_one_based_indexing(A)
m, n = size(A)
if m == n
if m == 1 return A[1] end
utri = true
utri1 = true
herm = true
sym = true
for j = 1:n-1, i = j+1:m
if utri1
for j = 1:n, i = j:m
if (j < n) && (i > j) && utri1 # indices are off-diagonal
if A[i,j] != 0
utri1 = i == j + 1
utri = false
end
end
if sym
sym &= A[i,j] == A[j,i]
sym &= A[i,j] == transpose(A[j,i])
end
if herm
herm &= A[i,j] == conj(A[j,i])
herm &= A[i,j] == adjoint(A[j,i])
end
if !(utri1|herm|sym) break end
end
Expand All @@ -1372,7 +1373,7 @@ function factorize(A::AbstractMatrix{T}) where T
if ltri1
for i = 1:n-1
if A[i,i+1] != 0
ltri &= false
ltri = false
break
end
end
Expand Down
6 changes: 6 additions & 0 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1234,4 +1234,10 @@ Base.:+(x::TypeWithZero, ::TypeWithoutZero) = x
@test diagm(0 => [TypeWithoutZero()]) isa Matrix{TypeWithZero}
end

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

end # module TestDense