OSDN Git Service

test (#52)
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / lapack / gonum / dgeql2.go
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 "gonum.org/v1/gonum/blas"
8
9 // Dgeql2 computes the QL factorization of the m×n matrix A. That is, Dgeql2
10 // computes Q and L such that
11 //  A = Q * L
12 // where Q is an m×m orthonormal matrix and L is a lower trapezoidal matrix.
13 //
14 // Q is represented as a product of elementary reflectors,
15 //  Q = H_{k-1} * ... * H_1 * H_0
16 // where k = min(m,n) and each H_i has the form
17 //  H_i = I - tau[i] * v_i * v_i^T
18 // Vector v_i has v[m-k+i+1:m] = 0, v[m-k+i] = 1, and v[:m-k+i+1] is stored on
19 // exit in A[0:m-k+i-1, n-k+i].
20 //
21 // tau must have length at least min(m,n), and Dgeql2 will panic otherwise.
22 //
23 // work is temporary memory storage and must have length at least n.
24 //
25 // Dgeql2 is an internal routine. It is exported for testing purposes.
26 func (impl Implementation) Dgeql2(m, n int, a []float64, lda int, tau, work []float64) {
27         checkMatrix(m, n, a, lda)
28         if len(tau) < min(m, n) {
29                 panic(badTau)
30         }
31         if len(work) < n {
32                 panic(badWork)
33         }
34         k := min(m, n)
35         var aii float64
36         for i := k - 1; i >= 0; i-- {
37                 // Generate elementary reflector H_i to annihilate A[0:m-k+i-1, n-k+i].
38                 aii, tau[i] = impl.Dlarfg(m-k+i+1, a[(m-k+i)*lda+n-k+i], a[n-k+i:], lda)
39
40                 // Apply H_i to A[0:m-k+i, 0:n-k+i-1] from the left.
41                 a[(m-k+i)*lda+n-k+i] = 1
42                 impl.Dlarf(blas.Left, m-k+i+1, n-k+i, a[n-k+i:], lda, tau[i], a, lda, work)
43                 a[(m-k+i)*lda+n-k+i] = aii
44         }
45 }