github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/gonum/dorg2l.go (about)

     1  // Copyright ©2016 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 (
     8  	"github.com/jingcheng-WU/gonum/blas"
     9  	"github.com/jingcheng-WU/gonum/blas/blas64"
    10  )
    11  
    12  // Dorg2l generates an m×n matrix Q with orthonormal columns which is defined
    13  // as the last n columns of a product of k elementary reflectors of order m.
    14  //  Q = H_{k-1} * ... * H_1 * H_0
    15  // See Dgelqf for more information. It must be that m >= n >= k.
    16  //
    17  // tau contains the scalar reflectors computed by Dgeqlf. tau must have length
    18  // at least k, and Dorg2l will panic otherwise.
    19  //
    20  // work contains temporary memory, and must have length at least n. Dorg2l will
    21  // panic otherwise.
    22  //
    23  // Dorg2l is an internal routine. It is exported for testing purposes.
    24  func (impl Implementation) Dorg2l(m, n, k int, a []float64, lda int, tau, work []float64) {
    25  	switch {
    26  	case m < 0:
    27  		panic(mLT0)
    28  	case n < 0:
    29  		panic(nLT0)
    30  	case n > m:
    31  		panic(nGTM)
    32  	case k < 0:
    33  		panic(kLT0)
    34  	case k > n:
    35  		panic(kGTN)
    36  	case lda < max(1, n):
    37  		panic(badLdA)
    38  	}
    39  
    40  	if n == 0 {
    41  		return
    42  	}
    43  
    44  	switch {
    45  	case len(a) < (m-1)*lda+n:
    46  		panic(shortA)
    47  	case len(tau) < k:
    48  		panic(shortTau)
    49  	case len(work) < n:
    50  		panic(shortWork)
    51  	}
    52  
    53  	// Initialize columns 0:n-k to columns of the unit matrix.
    54  	for j := 0; j < n-k; j++ {
    55  		for l := 0; l < m; l++ {
    56  			a[l*lda+j] = 0
    57  		}
    58  		a[(m-n+j)*lda+j] = 1
    59  	}
    60  
    61  	bi := blas64.Implementation()
    62  	for i := 0; i < k; i++ {
    63  		ii := n - k + i
    64  
    65  		// Apply H_i to A[0:m-k+i, 0:n-k+i] from the left.
    66  		a[(m-n+ii)*lda+ii] = 1
    67  		impl.Dlarf(blas.Left, m-n+ii+1, ii, a[ii:], lda, tau[i], a, lda, work)
    68  		bi.Dscal(m-n+ii, -tau[i], a[ii:], lda)
    69  		a[(m-n+ii)*lda+ii] = 1 - tau[i]
    70  
    71  		// Set A[m-k+i:m, n-k+i+1] to zero.
    72  		for l := m - n + ii + 1; l < m; l++ {
    73  			a[l*lda+ii] = 0
    74  		}
    75  	}
    76  }