@@ -12,7 +12,7 @@ function check_input(::typeof(lq_full!), A::AbstractMatrix, LQ, ::AbstractAlgori
1212 @assert L isa AbstractMatrix && Q isa AbstractMatrix
1313 isempty (L) || @check_size (L, (m, n))
1414 @check_scalar (L, A)
15- @check_size (Q, (n, n))
15+ isempty (Q) || @check_size (Q, (n, n))
1616 @check_scalar (Q, A)
1717 return nothing
1818end
@@ -23,7 +23,7 @@ function check_input(::typeof(lq_compact!), A::AbstractMatrix, LQ, ::AbstractAlg
2323 @assert L isa AbstractMatrix && Q isa AbstractMatrix
2424 isempty (L) || @check_size (L, (m, minmn))
2525 @check_scalar (L, A)
26- @check_size (Q, (minmn, n))
26+ isempty (Q) || @check_size (Q, (minmn, n))
2727 @check_scalar (Q, A)
2828 return nothing
2929end
@@ -42,7 +42,7 @@ function check_input(::typeof(lq_full!), A::AbstractMatrix, (L, Q), ::DiagonalAl
4242 @assert Q isa Diagonal && L isa Diagonal
4343 isempty (L) || @check_size (L, (m, n))
4444 @check_scalar (L, A)
45- @check_size (Q, (n, n))
45+ isempty (Q) || @check_size (Q, (n, n))
4646 @check_scalar (Q, A)
4747 return nothing
4848end
@@ -148,7 +148,7 @@ function lq_householder!(
148148
149149 m, n = size (A)
150150 minmn = min (m, n)
151- computeL = length (L) > 0
151+ computeL = ! isempty (L)
152152 inplaceQ = Q === A
153153
154154 if inplaceQ
@@ -162,25 +162,25 @@ function lq_householder!(
162162 if blocksize > 1
163163 # L doubles as workspace for T, so Q is constructed before L is extracted
164164 mb = min (minmn, blocksize)
165- if computeL # first use L as space for T
166- A, T = gelqt! (driver, A, view (L, 1 : mb, 1 : minmn))
167- else
168- A, T = gelqt! (driver, A, similar (A, mb, minmn))
169- end
170- Q = gemlqt! (driver, ' R' , ' N' , A, T, one! (Q))
165+ T = computeL ? view (L, 1 : mb, 1 : minmn) : similar (A, mb, minmn)
166+ A, T = gelqt! (driver, A, T)
167+ isempty (Q) || (Q = gemlqt! (driver, ' R' , ' N' , A, T, one! (Q)))
171168 computeL && _lq_copyL! (L, A)
172- positive && gaugefix! (lq_householder!, computeL ? L : nothing , Q, diagview (A))
169+ positive && gaugefix! (lq_householder!, L , Q, diagview (A))
173170 else
174171 A, τ = gelqf! (driver, A)
175172 computeL && _lq_copyL! (L, A)
176- Lf = computeL ? L : nothing
177173 if inplaceQ
178- Ld = positive ? copy (diagview (A)) : nothing # unglq! destroys the diagonal of A
179- unglq! (driver, A, τ) # Q === A, so no need to rebind Q
180- positive && gaugefix! (lq_householder!, Lf, Q, Ld)
174+ if positive
175+ Ld = copy (diagview (A)) # unglq! destroys the diagonal of A
176+ unglq! (driver, A, τ) # Q === A, so no need to rebind Q
177+ gaugefix! (lq_householder!, L, Q, Ld)
178+ else
179+ unglq! (driver, A, τ)
180+ end
181181 else
182- Q = unmlq! (driver, ' R' , ' N' , A, τ, one! (Q))
183- positive && gaugefix! (lq_householder!, Lf , Q, diagview (A))
182+ isempty (Q) || (Q = unmlq! (driver, ' R' , ' N' , A, τ, one! (Q) ))
183+ positive && gaugefix! (lq_householder!, L , Q, diagview (A))
184184 end
185185 end
186186
@@ -220,6 +220,7 @@ function lq_householder!(
220220 L[i, j] = A[i, j]
221221 end
222222 end
223+ isempty (Q) && return L, Q
223224 # build Q
224225 one! (Q)
225226 @inbounds for i in minmn: - 1 : 1
@@ -324,13 +325,13 @@ function lq_via_qr!(
324325 Qt = (A === Q) ? At : similar (Q' )
325326 Lt = similar (L' )
326327 n = size (A, 2 )
327- if size (Q) == (n, n)
328+ if size (Q) == (n, n) || size (L, 2 ) == n
328329 Qt, Lt = qr_full! (At, (Qt, Lt), qr_alg)
329330 else
330331 Qt, Lt = qr_compact! (At, (Qt, Lt), qr_alg)
331332 end
332- adjoint! (Q, Qt)
333- ! isempty (L) && adjoint! (L, Lt)
333+ isempty (Q) || adjoint! (Q, Qt)
334+ isempty (L) || adjoint! (L, Lt)
334335 return L, Q
335336end
336337
@@ -348,38 +349,28 @@ end
348349function lq_full! (A:: AbstractMatrix , LQ, alg:: DiagonalAlgorithm )
349350 check_input (lq_full!, A, LQ, alg)
350351 L, Q = LQ
351- lq_diagonal ! (A, L, Q; alg. kwargs... )
352+ _lq_diagonal ! (A, L, Q; alg. kwargs... )
352353 return L, Q
353354end
354355function lq_compact! (A:: AbstractMatrix , LQ, alg:: DiagonalAlgorithm )
355356 check_input (lq_compact!, A, LQ, alg)
356357 L, Q = LQ
357- lq_diagonal ! (A, L, Q; alg. kwargs... )
358+ _lq_diagonal ! (A, L, Q; alg. kwargs... )
358359 return L, Q
359360end
360361function lq_null! (A:: AbstractMatrix , N, alg:: DiagonalAlgorithm )
361362 check_input (lq_null!, A, N, alg)
362- return lq_null_diagonal ! (A, N; alg. kwargs... )
363+ return _lq_null_diagonal ! (A, N; alg. kwargs... )
363364end
364365
365- function lq_diagonal ! (
366+ function _lq_diagonal ! (
366367 A:: AbstractMatrix , L:: AbstractMatrix , Q:: AbstractMatrix ; positive:: Bool = true
367368 )
368- # note: Ad and Qd might share memory here so order of operations is important
369- Ad = diagview (A)
370- Ld = diagview (L)
371- Qd = diagview (Q)
372- if positive
373- @. Ld = abs (Ad)
374- @. Qd = sign_safe (Ad)
375- else
376- Ld .= Ad
377- one! (Q)
378- end
369+ Q, L = _qr_diagonal! (A, Q, L; positive)
379370 return L, Q
380371end
381372
382- lq_null_diagonal ! (A:: AbstractMatrix , N; positive:: Bool = true ) = N
373+ _lq_null_diagonal ! (A:: AbstractMatrix , N; positive:: Bool = true ) = N
383374
384375# Deprecations
385376# ------------
0 commit comments