@@ -270,3 +270,85 @@ function _diagonal_lq!(
270270end
271271
272272_diagonal_lq_null! (A:: AbstractMatrix , N; positive:: Bool = false ) = N
273+
274+ # Native logic
275+ # -------------
276+ function lq_full! (A:: AbstractMatrix , LQ, alg:: Native_HouseholderLQ )
277+ check_input (lq_full!, A, LQ, alg)
278+ L, Q = LQ
279+ A === Q &&
280+ throw (ArgumentError (" inplace Q not supported with native LQ implementation" ))
281+ _native_lq! (A, L, Q; alg. kwargs... )
282+ return L, Q
283+ end
284+ function lq_compact! (A:: AbstractMatrix , LQ, alg:: Native_HouseholderLQ )
285+ check_input (lq_compact!, A, LQ, alg)
286+ L, Q = LQ
287+ A === Q &&
288+ throw (ArgumentError (" inplace Q not supported with native LQ implementation" ))
289+ _native_lq! (A, L, Q; alg. kwargs... )
290+ return L, Q
291+ end
292+ function lq_null! (A:: AbstractMatrix , N, alg:: Native_HouseholderLQ )
293+ check_input (lq_null!, A, N, alg)
294+ _native_lq_null! (A, N; alg. kwargs... )
295+ return N
296+ end
297+
298+ function _native_lq! (
299+ A:: AbstractMatrix , L:: AbstractMatrix , Q:: AbstractMatrix ;
300+ positive:: Bool = true # always true regardless of setting
301+ )
302+ m, n = size (A)
303+ minmn = min (m, n)
304+ @inbounds for i in 1 : minmn
305+ for j in 1 : (i - 1 )
306+ L[i, j] = A[i, j]
307+ end
308+ β, v, L[i, i] = _householder! (conj! (view (A, i, i: n)), 1 )
309+ for j in (i + 1 ): size (L, 2 )
310+ L[i, j] = 0
311+ end
312+ H = Householder (conj (β), v, i: n)
313+ rmul! (A, H; rows = (i + 1 ): m)
314+ # A[i, i] == 1; store β instead
315+ A[i, i] = β
316+ end
317+ # copy remaining rows for m > n
318+ @inbounds for j in 1 : size (L, 2 )
319+ for i in (minmn + 1 ): m
320+ L[i, j] = A[i, j]
321+ end
322+ end
323+ # build Q
324+ one! (Q)
325+ @inbounds for i in minmn: - 1 : 1
326+ β = A[i, i]
327+ A[i, i] = 1
328+ Hᴴ = Householder (β, view (A, i, i: n), i: n)
329+ rmul! (Q, Hᴴ)
330+ end
331+ return L, Q
332+ end
333+
334+ function _native_lq_null! (A:: AbstractMatrix , Nᴴ:: AbstractMatrix ; positive:: Bool = true )
335+ m, n = size (A)
336+ minmn = min (m, n)
337+ @inbounds for i in 1 : minmn
338+ β, v, ν = _householder! (conj! (view (A, i, i: n)), 1 )
339+ H = Householder (conj (β), v, i: n)
340+ rmul! (A, H; rows = (i + 1 ): m)
341+ # A[i, i] == 1; store β instead
342+ A[i, i] = β
343+ end
344+ # build Nᴴ
345+ fill! (Nᴴ, zero (eltype (Nᴴ)))
346+ one! (view (Nᴴ, 1 : (n - minmn), (minmn + 1 ): n))
347+ @inbounds for i in minmn: - 1 : 1
348+ β = A[i, i]
349+ A[i, i] = 1
350+ Hᴴ = Householder (β, view (A, i, i: n), i: n)
351+ rmul! (Nᴴ, Hᴴ)
352+ end
353+ return Nᴴ
354+ end
0 commit comments