OSDN Git Service

Hulk did something
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / gonum / dgelq2.go
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         checkMatrix(m, n, a, lda)
29         k := min(m, n)
30         if len(tau) < k {
31                 panic(badTau)
32         }
33         if len(work) < m {
34                 panic(badWork)
35         }
36         for i := 0; i < k; i++ {
37                 a[i*lda+i], tau[i] = impl.Dlarfg(n-i, a[i*lda+i], a[i*lda+min(i+1, n-1):], 1)
38                 if i < m-1 {
39                         aii := a[i*lda+i]
40                         a[i*lda+i] = 1
41                         impl.Dlarf(blas.Right, m-i-1, n-i,
42                                 a[i*lda+i:], 1,
43                                 tau[i],
44                                 a[(i+1)*lda+i:], lda,
45                                 work)
46                         a[i*lda+i] = aii
47                 }
48         }
49 }