// Copyright ©2015 The gonum Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. // Package lapack64 provides a set of convenient wrapper functions for LAPACK // calls, as specified in the netlib standard (www.netlib.org). // // The native Go routines are used by default, and the Use function can be used // to set an alternate implementation. // // If the type of matrix (General, Symmetric, etc.) is known and fixed, it is // used in the wrapper signature. In many cases, however, the type of the matrix // changes during the call to the routine, for example the matrix is symmetric on // entry and is triangular on exit. In these cases the correct types should be checked // in the documentation. // // The full set of Lapack functions is very large, and it is not clear that a // full implementation is desirable, let alone feasible. Please open up an issue // if there is a specific function you need and/or are willing to implement. package lapack64 import ( "github.com/gonum/blas" "github.com/gonum/blas/blas64" "github.com/gonum/lapack" "github.com/gonum/lapack/native" ) var lapack64 lapack.Float64 = native.Implementation{} // Use sets the LAPACK float64 implementation to be used by subsequent BLAS calls. // The default implementation is native.Implementation. func Use(l lapack.Float64) { lapack64 = l } // Potrf computes the cholesky factorization of a. // A = U^T * U if ul == blas.Upper // A = L * L^T if ul == blas.Lower // The underlying data between the input matrix and output matrix is shared. func Potrf(a blas64.Symmetric) (t blas64.Triangular, ok bool) { ok = lapack64.Dpotrf(a.Uplo, a.N, a.Data, a.Stride) t.Uplo = a.Uplo t.N = a.N t.Data = a.Data t.Stride = a.Stride t.Diag = blas.NonUnit return } // Geqrf computes the QR factorization of the m×n matrix A using a blocked // algorithm. 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 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, and lwork specifies the usable memory length. // At minimum, lwork >= m and this function will panic otherwise. // Dgeqrf is a blocked LQ factorization, but the block size is limited // by the temporary space available. If lwork == -1, instead of performing Dgelqf, // the optimal work length will be stored into work[0]. func Geqrf(a blas64.General, tau, work []float64, lwork int) { lapack64.Dgeqrf(a.Rows, a.Cols, a.Data, a.Stride, tau, work, lwork) }