github.com/gopherd/gonum@v0.0.4/lapack/gonum/dlapll.go (about)

     1  // Copyright ©2017 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 "github.com/gopherd/gonum/blas/blas64"
     8  
     9  // Dlapll returns the smallest singular value of the n×2 matrix A = [ x y ].
    10  // The function first computes the QR factorization of A = Q*R, and then computes
    11  // the SVD of the 2-by-2 upper triangular matrix r.
    12  //
    13  // The contents of x and y are overwritten during the call.
    14  //
    15  // Dlapll is an internal routine. It is exported for testing purposes.
    16  func (impl Implementation) Dlapll(n int, x []float64, incX int, y []float64, incY int) float64 {
    17  	switch {
    18  	case n < 0:
    19  		panic(nLT0)
    20  	case incX <= 0:
    21  		panic(badIncX)
    22  	case incY <= 0:
    23  		panic(badIncY)
    24  	}
    25  
    26  	// Quick return if possible.
    27  	if n == 0 {
    28  		return 0
    29  	}
    30  
    31  	switch {
    32  	case len(x) < 1+(n-1)*incX:
    33  		panic(shortX)
    34  	case len(y) < 1+(n-1)*incY:
    35  		panic(shortY)
    36  	}
    37  
    38  	// Quick return if possible.
    39  	if n == 1 {
    40  		return 0
    41  	}
    42  
    43  	// Compute the QR factorization of the N-by-2 matrix [ X Y ].
    44  	a00, tau := impl.Dlarfg(n, x[0], x[incX:], incX)
    45  	x[0] = 1
    46  
    47  	bi := blas64.Implementation()
    48  	c := -tau * bi.Ddot(n, x, incX, y, incY)
    49  	bi.Daxpy(n, c, x, incX, y, incY)
    50  	a11, _ := impl.Dlarfg(n-1, y[incY], y[2*incY:], incY)
    51  
    52  	// Compute the SVD of 2-by-2 upper triangular matrix.
    53  	ssmin, _ := impl.Dlas2(a00, y[0], a11)
    54  	return ssmin
    55  }