Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
  • Loading branch information
JanReimers committed Mar 16, 2023
1 parent 04cccd7 commit b22f8a3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
12 changes: 6 additions & 6 deletions NDTensors/src/linearalgebra/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ function qr_positive(M::AbstractMatrix)
Q = convert(Matrix, sparseQ)
nc = size(Q, 2)
for c in 1:nc
if R[c, c]!=0.0 #sign(0.0)==0.0 so we don't want to zero out a column of Q.
if R[c, c] != 0.0 #sign(0.0)==0.0 so we don't want to zero out a column of Q.
sign_Rc = sign(R[c, c])
if !isone(sign_Rc)
R[c, c:end] *= conj(sign_Rc) #only fip non-zero portion of the row.
Q[:, c] *= sign_Rc
end
end
end
end
return (Q, R)
end
Expand All @@ -437,13 +437,13 @@ function ql_positive(M::AbstractMatrix)
nr, nc = size(L)
dc = nc > nr ? nc - nr : 0 #diag is shifted over by dc if nc>nr
for c in 1:(nc - dc)
if L[c, c + dc]!=0.0 #sign(0.0)==0.0 so we don't want to zero out a column of Q.
if L[c, c + dc] != 0.0 #sign(0.0)==0.0 so we don't want to zero out a column of Q.
sign_Lc = sign(L[c, c + dc])
if c <= nr && !isone(sign_Lc)
L[c, 1:(c + dc)] *= sign_Lc #only fip non-zero portion of the column.
Q[:, c] *= conj(sign_Lc)
end
end
end
end
return (Q, L)
end
Expand All @@ -452,9 +452,9 @@ end
# Lapack replaces A with Q & R carefully packed together. So here we just copy a
# before letting lapack overwirte it.
#
function ql(A::AbstractMatrix; kwargs...)
function ql(A::AbstractMatrix; kwargs...)
Base.require_one_based_indexing(A)
T=eltype(A)
T = eltype(A)
AA = similar(A, LinearAlgebra._qreltype(T), size(A))
copyto!(AA, A)
return ql!(AA; kwargs...)
Expand Down
9 changes: 6 additions & 3 deletions NDTensors/test/linearalgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ end
@test norm(U2 * U2' - Diagonal(fill(1.0, m))) < 1E-14
end

@testset "Dense $qx decomposition, elt=$elt, positve=$positive, singular=$singular" for qx in [qr, ql],
@testset "Dense $qx decomposition, elt=$elt, positve=$positive, singular=$singular" for qx in
[
qr, ql
],
elt in [Float64, ComplexF64, Float32, ComplexF32],
positive in [false, true],
singular in [false, true]
Expand All @@ -35,7 +38,7 @@ end
# We want to test 0.0 on the diagonal. We need make all roaw equal to gaurantee this with numerical roundoff.
if singular
for i in 2:n
A[i,:]=A[1,:]
A[i, :] = A[1, :]
end
end
Q, X = qx(A; positive=positive) #X is R or L.
Expand All @@ -56,7 +59,7 @@ end
# We want to test 0.0 on the diagonal. We need make all rows equal to gaurantee this with numerical roundoff.
if singular
for i in 2:m
A[i,:]=A[1,:]
A[i, :] = A[1, :]
end
end
Q, X = qx(A; positive=positive)
Expand Down

0 comments on commit b22f8a3

Please sign in to comment.