github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/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 native
     6  
     7  import (
     8  	"github.com/gonum/blas"
     9  	"github.com/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  	checkMatrix(m, n, a, lda)
    21  	if len(tau) < k {
    22  		panic(badTau)
    23  	}
    24  	if k > m {
    25  		panic(kGTM)
    26  	}
    27  	if k > m {
    28  		panic(kGTM)
    29  	}
    30  	if m > n {
    31  		panic(nLTM)
    32  	}
    33  	if len(work) < m {
    34  		panic(badWork)
    35  	}
    36  	if m == 0 {
    37  		return
    38  	}
    39  	bi := blas64.Implementation()
    40  	if k < m {
    41  		for i := k; i < m; i++ {
    42  			for j := 0; j < n; j++ {
    43  				a[i*lda+j] = 0
    44  			}
    45  		}
    46  		for j := k; j < m; j++ {
    47  			a[j*lda+j] = 1
    48  		}
    49  	}
    50  	for i := k - 1; i >= 0; i-- {
    51  		if i < n-1 {
    52  			if i < m-1 {
    53  				a[i*lda+i] = 1
    54  				impl.Dlarf(blas.Right, m-i-1, n-i, a[i*lda+i:], 1, tau[i], a[(i+1)*lda+i:], lda, work)
    55  			}
    56  			bi.Dscal(n-i-1, -tau[i], a[i*lda+i+1:], 1)
    57  		}
    58  		a[i*lda+i] = 1 - tau[i]
    59  		for l := 0; l < i; l++ {
    60  			a[i*lda+l] = 0
    61  		}
    62  	}
    63  }