gonum.org/v1/gonum@v0.14.0/lapack/gonum/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 gonum 6 7 import "gonum.org/v1/gonum/blas" 8 9 // Dgebd2 reduces an m×n matrix A to upper or lower bidiagonal form by an orthogonal 10 // transformation. 11 // 12 // Qᵀ * A * P = B 13 // 14 // if m >= n, B is upper diagonal, otherwise B is lower bidiagonal. 15 // d is the diagonal, len = min(m,n) 16 // e is the off-diagonal len = min(m,n)-1 17 // 18 // Dgebd2 is an internal routine. It is exported for testing purposes. 19 func (impl Implementation) Dgebd2(m, n int, a []float64, lda int, d, e, tauQ, tauP, work []float64) { 20 switch { 21 case m < 0: 22 panic(mLT0) 23 case n < 0: 24 panic(nLT0) 25 case lda < max(1, n): 26 panic(badLdA) 27 } 28 29 // Quick return if possible. 30 minmn := min(m, n) 31 if minmn == 0 { 32 return 33 } 34 35 switch { 36 case len(d) < minmn: 37 panic(shortD) 38 case len(e) < minmn-1: 39 panic(shortE) 40 case len(tauQ) < minmn: 41 panic(shortTauQ) 42 case len(tauP) < minmn: 43 panic(shortTauP) 44 case len(work) < max(m, n): 45 panic(shortWork) 46 } 47 48 if m >= n { 49 for i := 0; i < n; i++ { 50 a[i*lda+i], tauQ[i] = impl.Dlarfg(m-i, a[i*lda+i], a[min(i+1, m-1)*lda+i:], lda) 51 d[i] = a[i*lda+i] 52 a[i*lda+i] = 1 53 // Apply H_i to A[i:m, i+1:n] from the left. 54 if i < n-1 { 55 impl.Dlarf(blas.Left, m-i, n-i-1, a[i*lda+i:], lda, tauQ[i], a[i*lda+i+1:], lda, work) 56 } 57 a[i*lda+i] = d[i] 58 if i < n-1 { 59 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) 60 e[i] = a[i*lda+i+1] 61 a[i*lda+i+1] = 1 62 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) 63 a[i*lda+i+1] = e[i] 64 } else { 65 tauP[i] = 0 66 } 67 } 68 return 69 } 70 for i := 0; i < m; i++ { 71 a[i*lda+i], tauP[i] = impl.Dlarfg(n-i, a[i*lda+i], a[i*lda+min(i+1, n-1):], 1) 72 d[i] = a[i*lda+i] 73 a[i*lda+i] = 1 74 if i < m-1 { 75 impl.Dlarf(blas.Right, m-i-1, n-i, a[i*lda+i:], 1, tauP[i], a[(i+1)*lda+i:], lda, work) 76 } 77 a[i*lda+i] = d[i] 78 if i < m-1 { 79 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) 80 e[i] = a[(i+1)*lda+i] 81 a[(i+1)*lda+i] = 1 82 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) 83 a[(i+1)*lda+i] = e[i] 84 } else { 85 tauQ[i] = 0 86 } 87 } 88 }