gonum.org/v1/gonum@v0.14.0/lapack/gonum/dgelq2.go (about)

     1  // Copyright ©2015 The Gonum Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package gonum
     6  
     7  import "gonum.org/v1/gonum/blas"
     8  
     9  // Dgelq2 computes the LQ factorization of the m×n matrix A.
    10  //
    11  // In an LQ factorization, L is a lower triangular m×n matrix, and Q is an n×n
    12  // orthonormal matrix.
    13  //
    14  // a is modified to contain the information to construct L and Q.
    15  // The lower triangle of a contains the matrix L. The upper triangular elements
    16  // (not including the diagonal) contain the elementary reflectors. tau is modified
    17  // to contain the reflector scales. tau must have length of at least k = min(m,n)
    18  // and this function will panic otherwise.
    19  //
    20  // See Dgeqr2 for a description of the elementary reflectors and orthonormal
    21  // matrix Q. Q is constructed as a product of these elementary reflectors,
    22  // Q = H_{k-1} * ... * H_1 * H_0.
    23  //
    24  // work is temporary storage of length at least m and this function will panic otherwise.
    25  //
    26  // Dgelq2 is an internal routine. It is exported for testing purposes.
    27  func (impl Implementation) Dgelq2(m, n int, a []float64, lda int, tau, work []float64) {
    28  	switch {
    29  	case m < 0:
    30  		panic(mLT0)
    31  	case n < 0:
    32  		panic(nLT0)
    33  	case lda < max(1, n):
    34  		panic(badLdA)
    35  	}
    36  
    37  	// Quick return if possible.
    38  	k := min(m, n)
    39  	if k == 0 {
    40  		return
    41  	}
    42  
    43  	switch {
    44  	case len(a) < (m-1)*lda+n:
    45  		panic(shortA)
    46  	case len(tau) < k:
    47  		panic(shortTau)
    48  	case len(work) < m:
    49  		panic(shortWork)
    50  	}
    51  
    52  	for i := 0; i < k; i++ {
    53  		a[i*lda+i], tau[i] = impl.Dlarfg(n-i, a[i*lda+i], a[i*lda+min(i+1, n-1):], 1)
    54  		if i < m-1 {
    55  			aii := a[i*lda+i]
    56  			a[i*lda+i] = 1
    57  			impl.Dlarf(blas.Right, m-i-1, n-i,
    58  				a[i*lda+i:], 1,
    59  				tau[i],
    60  				a[(i+1)*lda+i:], lda,
    61  				work)
    62  			a[i*lda+i] = aii
    63  		}
    64  	}
    65  }