github.com/gonum/lapack@v0.0.0-20181123203213-e4cdc5a0bff9/native/dgebd2.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 "github.com/gonum/blas" 8 9 // Dgebd2 reduces an m×n matrix A to upper or lower bidiagonal form by an orthogonal 10 // transformation. 11 // Q^T * A * P = B 12 // if m >= n, B is upper diagonal, otherwise B is lower bidiagonal. 13 // d is the diagonal, len = min(m,n) 14 // e is the off-diagonal len = min(m,n)-1 15 // 16 // Dgebd2 is an internal routine. It is exported for testing purposes. 17 func (impl Implementation) Dgebd2(m, n int, a []float64, lda int, d, e, tauQ, tauP, work []float64) { 18 checkMatrix(m, n, a, lda) 19 if len(d) < min(m, n) { 20 panic(badD) 21 } 22 if len(e) < min(m, n)-1 { 23 panic(badE) 24 } 25 if len(tauQ) < min(m, n) { 26 panic(badTauQ) 27 } 28 if len(tauP) < min(m, n) { 29 panic(badTauP) 30 } 31 if len(work) < max(m, n) { 32 panic(badWork) 33 } 34 if m >= n { 35 for i := 0; i < n; i++ { 36 a[i*lda+i], tauQ[i] = impl.Dlarfg(m-i, a[i*lda+i], a[min(i+1, m-1)*lda+i:], lda) 37 d[i] = a[i*lda+i] 38 a[i*lda+i] = 1 39 // Apply H_i to A[i:m, i+1:n] from the left. 40 if i < n-1 { 41 impl.Dlarf(blas.Left, m-i, n-i-1, a[i*lda+i:], lda, tauQ[i], a[i*lda+i+1:], lda, work) 42 } 43 a[i*lda+i] = d[i] 44 if i < n-1 { 45 a[i*lda+i+1], tauP[i] = impl.Dlarfg(n-i-1, a[i*lda+i+1], a[i*lda+min(i+2, n-1):], 1) 46 e[i] = a[i*lda+i+1] 47 a[i*lda+i+1] = 1 48 impl.Dlarf(blas.Right, m-i-1, n-i-1, a[i*lda+i+1:], 1, tauP[i], a[(i+1)*lda+i+1:], lda, work) 49 a[i*lda+i+1] = e[i] 50 } else { 51 tauP[i] = 0 52 } 53 } 54 return 55 } 56 for i := 0; i < m; i++ { 57 a[i*lda+i], tauP[i] = impl.Dlarfg(n-i, a[i*lda+i], a[i*lda+min(i+1, n-1):], 1) 58 d[i] = a[i*lda+i] 59 a[i*lda+i] = 1 60 if i < m-1 { 61 impl.Dlarf(blas.Right, m-i-1, n-i, a[i*lda+i:], 1, tauP[i], a[(i+1)*lda+i:], lda, work) 62 } 63 a[i*lda+i] = d[i] 64 if i < m-1 { 65 a[(i+1)*lda+i], tauQ[i] = impl.Dlarfg(m-i-1, a[(i+1)*lda+i], a[min(i+2, m-1)*lda+i:], lda) 66 e[i] = a[(i+1)*lda+i] 67 a[(i+1)*lda+i] = 1 68 impl.Dlarf(blas.Left, m-i-1, n-i-1, a[(i+1)*lda+i:], lda, tauQ[i], a[(i+1)*lda+i+1:], lda, work) 69 a[(i+1)*lda+i] = e[i] 70 } else { 71 tauQ[i] = 0 72 } 73 } 74 }