github.com/jingcheng-WU/gonum@v0.9.1-0.20210323123734-f1a2a11a8f7b/lapack/gonum/dorgl2.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 (
     8  	"github.com/jingcheng-WU/gonum/blas"
     9  	"github.com/jingcheng-WU/gonum/blas/blas64"
    10  )
    11  
    12  // Dorgl2 generates an m×n matrix Q with orthonormal rows defined by the
    13  // first m rows product of elementary reflectors as computed by Dgelqf.
    14  //  Q = H_0 * H_1 * ... * H_{k-1}
    15  // len(tau) >= k, 0 <= k <= m, 0 <= m <= n, len(work) >= m.
    16  // Dorgl2 will panic if these conditions are not met.
    17  //
    18  // Dorgl2 is an internal routine. It is exported for testing purposes.
    19  func (impl Implementation) Dorgl2(m, n, k int, a []float64, lda int, tau, work []float64) {
    20  	switch {
    21  	case m < 0:
    22  		panic(mLT0)
    23  	case n < m:
    24  		panic(nLTM)
    25  	case k < 0:
    26  		panic(kLT0)
    27  	case k > m:
    28  		panic(kGTM)
    29  	case lda < max(1, m):
    30  		panic(badLdA)
    31  	}
    32  
    33  	if m == 0 {
    34  		return
    35  	}
    36  
    37  	switch {
    38  	case len(a) < (m-1)*lda+n:
    39  		panic(shortA)
    40  	case len(tau) < k:
    41  		panic(shortTau)
    42  	case len(work) < m:
    43  		panic(shortWork)
    44  	}
    45  
    46  	bi := blas64.Implementation()
    47  
    48  	if k < m {
    49  		for i := k; i < m; i++ {
    50  			for j := 0; j < n; j++ {
    51  				a[i*lda+j] = 0
    52  			}
    53  		}
    54  		for j := k; j < m; j++ {
    55  			a[j*lda+j] = 1
    56  		}
    57  	}
    58  	for i := k - 1; i >= 0; i-- {
    59  		if i < n-1 {
    60  			if i < m-1 {
    61  				a[i*lda+i] = 1
    62  				impl.Dlarf(blas.Right, m-i-1, n-i, a[i*lda+i:], 1, tau[i], a[(i+1)*lda+i:], lda, work)
    63  			}
    64  			bi.Dscal(n-i-1, -tau[i], a[i*lda+i+1:], 1)
    65  		}
    66  		a[i*lda+i] = 1 - tau[i]
    67  		for l := 0; l < i; l++ {
    68  			a[i*lda+l] = 0
    69  		}
    70  	}
    71  }