mirror of
https://github.com/gonum/gonum.git
synced 2025-11-01 19:12:45 +08:00
Add QR factorization to lapack64 interface.
This commit is contained in:
@@ -77,6 +77,71 @@ func (impl Implementation) Dpotrf(ul blas.Uplo, n int, a []float64, lda int) (ok
|
||||
return clapack.Dpotrf(ul, n, a, lda)
|
||||
}
|
||||
|
||||
// Dgeqr2 computes a QR factorization of the m×n matrix A.
|
||||
//
|
||||
// In a QR factorization, Q is an m×m orthonormal matrix, and R is an
|
||||
// upper triangular m×n matrix.
|
||||
//
|
||||
// During Dgeqr2, a is modified to contain the information to construct Q and R.
|
||||
// The upper triangle of a contains the matrix R. The lower triangular elements
|
||||
// (not including the diagonal) contain the elementary reflectors. Tau is modified
|
||||
// to contain the reflector scales. Tau must have length at least k = min(m,n), and
|
||||
// this function will panic otherwise.
|
||||
//
|
||||
// The ith elementary reflector can be explicitly constructed by first extracting
|
||||
// the
|
||||
// v[j] = 0 j < i
|
||||
// v[j] = i j == i
|
||||
// v[j] = a[i*lda+j] j > i
|
||||
// and computing h_i = I - tau[i] * v * v^T.
|
||||
//
|
||||
// The orthonormal matrix Q can be constucted from a product of these elementary
|
||||
// reflectors, Q = H_1*H_2 ... H_k, where k = min(m,n).
|
||||
//
|
||||
// Work is temporary storage of length at least n and this function will panic otherwise.
|
||||
func (impl Implementation) Dgeqr2(m, n int, a []float64, lda int, tau, work []float64) {
|
||||
// TODO(btracey): This is oriented such that columns of a are eliminated.
|
||||
// This likely could be re-arranged to take better advantage of row-major
|
||||
// storage.
|
||||
checkMatrix(m, n, a, lda)
|
||||
if len(work) < n {
|
||||
panic(badWork)
|
||||
}
|
||||
k := min(m, n)
|
||||
if len(tau) < k {
|
||||
panic(badTau)
|
||||
}
|
||||
clapack.Dgeqr2(m, n, a, lda, tau)
|
||||
}
|
||||
|
||||
// Dgeqrf computes the QR factorization of the m×n matrix A using a blocked
|
||||
// algorithm. Please see the documentation for Dgeqr2 for a description of the
|
||||
// parameters at entry and exit.
|
||||
//
|
||||
// The C interface does not support providing temporary storage. To provide compatibility
|
||||
// with native, lwork == -1 will not run Dgeqrf but will instead write the minimum
|
||||
// work necessary to work[0]. If len(work) < lwork, Dgels will panic.
|
||||
//
|
||||
// tau must be at least len min(m,n), and this function will panic otherwise.
|
||||
func (impl Implementation) Dgeqrf(m, n int, a []float64, lda int, tau, work []float64, lwork int) {
|
||||
if lwork == -1 {
|
||||
work[0] = float64(n)
|
||||
return
|
||||
}
|
||||
checkMatrix(m, n, a, lda)
|
||||
if len(work) < lwork {
|
||||
panic(shortWork)
|
||||
}
|
||||
if lwork < n {
|
||||
panic(badWork)
|
||||
}
|
||||
k := min(m, n)
|
||||
if len(tau) < k {
|
||||
panic(badTau)
|
||||
}
|
||||
clapack.Dgeqrf(m, n, a, lda, tau)
|
||||
}
|
||||
|
||||
// Dgetf2 computes the LU decomposition of the m×n matrix A.
|
||||
// The LU decomposition is a factorization of a into
|
||||
// A = P * L * U
|
||||
|
||||
@@ -16,6 +16,14 @@ func TestDpotrf(t *testing.T) {
|
||||
testlapack.DpotrfTest(t, impl)
|
||||
}
|
||||
|
||||
func TestDgeqr2(t *testing.T) {
|
||||
testlapack.Dgeqr2Test(t, impl)
|
||||
}
|
||||
|
||||
func TestDgeqrf(t *testing.T) {
|
||||
testlapack.DgeqrfTest(t, impl)
|
||||
}
|
||||
|
||||
func TestDgetf2(t *testing.T) {
|
||||
testlapack.Dgetf2Test(t, impl)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user