lapack: rename HowMany type and consts

This commit is contained in:
Vladimir Chalupecky
2018-08-22 14:56:27 +02:00
committed by Vladimír Chalupecký
parent 7ef6056c6f
commit b132fde8ea
5 changed files with 40 additions and 41 deletions

View File

@@ -123,7 +123,7 @@ func (impl Implementation) Dgeev(jobvl lapack.LeftEVJob, jobvr lapack.RightEVJob
if wantvr { if wantvr {
side = lapack.EVRight side = lapack.EVRight
} }
impl.Dtrevc3(side, lapack.AllEVMulQ, nil, n, nil, 1, nil, 1, nil, 1, impl.Dtrevc3(side, lapack.EVAllMulQ, nil, n, nil, 1, nil, 1, nil, 1,
n, work, -1) n, work, -1)
maxwrk = max(maxwrk, n+int(work[0])) maxwrk = max(maxwrk, n+int(work[0]))
maxwrk = max(maxwrk, 4*n) maxwrk = max(maxwrk, 4*n)
@@ -215,7 +215,7 @@ func (impl Implementation) Dgeev(jobvl lapack.LeftEVJob, jobvr lapack.RightEVJob
if wantvl || wantvr { if wantvl || wantvr {
// Compute left and/or right eigenvectors. // Compute left and/or right eigenvectors.
impl.Dtrevc3(side, lapack.AllEVMulQ, nil, n, impl.Dtrevc3(side, lapack.EVAllMulQ, nil, n,
a, lda, vl, ldvl, vr, ldvr, n, work[iwrk:], lwork-iwrk) a, lda, vl, ldvl, vr, ldvr, n, work[iwrk:], lwork-iwrk)
} }
bi := blas64.Implementation() bi := blas64.Implementation()

View File

@@ -36,16 +36,16 @@ import (
// If side == lapack.EVRightLeft, both right and left eigenvectors will be computed. // If side == lapack.EVRightLeft, both right and left eigenvectors will be computed.
// For other values of side, Dtrevc3 will panic. // For other values of side, Dtrevc3 will panic.
// //
// If howmny == lapack.AllEV, all right and/or left eigenvectors will be // If howmny == lapack.EVAll, all right and/or left eigenvectors will be
// computed. // computed.
// If howmny == lapack.AllEVMulQ, all right and/or left eigenvectors will be // If howmny == lapack.EVAllMulQ, all right and/or left eigenvectors will be
// computed and multiplied from left by the matrices in VR and/or VL. // computed and multiplied from left by the matrices in VR and/or VL.
// If howmny == lapack.SelectedEV, right and/or left eigenvectors will be // If howmny == lapack.EVSelected, right and/or left eigenvectors will be
// computed as indicated by selected. // computed as indicated by selected.
// For other values of howmny, Dtrevc3 will panic. // For other values of howmny, Dtrevc3 will panic.
// //
// selected specifies which eigenvectors will be computed. It must have length n // selected specifies which eigenvectors will be computed. It must have length n
// if howmny == lapack.SelectedEV, and it is not referenced otherwise. // if howmny == lapack.EVSelected, and it is not referenced otherwise.
// If w_j is a real eigenvalue, the corresponding real eigenvector will be // If w_j is a real eigenvalue, the corresponding real eigenvector will be
// computed if selected[j] is true. // computed if selected[j] is true.
// If w_j and w_{j+1} are the real and imaginary parts of a complex eigenvalue, // If w_j and w_{j+1} are the real and imaginary parts of a complex eigenvalue,
@@ -53,9 +53,9 @@ import (
// selected[j+1] is true, and on return selected[j] will be set to true and // selected[j+1] is true, and on return selected[j] will be set to true and
// selected[j+1] will be set to false. // selected[j+1] will be set to false.
// //
// VL and VR are n×mm matrices. If howmny is lapack.AllEV or // VL and VR are n×mm matrices. If howmny is lapack.EVAll or
// lapack.AllEVMulQ, mm must be at least n. If howmny == // lapack.AllEVMulQ, mm must be at least n. If howmny is
// lapack.SelectedEV, mm must be large enough to store the selected // lapack.EVSelected, mm must be large enough to store the selected
// eigenvectors. Each selected real eigenvector occupies one column and each // eigenvectors. Each selected real eigenvector occupies one column and each
// selected complex eigenvector occupies two columns. If mm is not sufficiently // selected complex eigenvector occupies two columns. If mm is not sufficiently
// large, Dtrevc3 will panic. // large, Dtrevc3 will panic.
@@ -68,9 +68,9 @@ import (
// //
// On return, if side is lapack.EVLeft or lapack.EVRightLeft, // On return, if side is lapack.EVLeft or lapack.EVRightLeft,
// VL will contain: // VL will contain:
// if howmny == lapack.AllEV, the matrix Y of left eigenvectors of T, // if howmny == lapack.EVAll, the matrix Y of left eigenvectors of T,
// if howmny == lapack.AllEVMulQ, the matrix Q*Y, // if howmny == lapack.EVAllMulQ, the matrix Q*Y,
// if howmny == lapack.SelectedEV, the left eigenvectors of T specified by // if howmny == lapack.EVSelected, the left eigenvectors of T specified by
// selected, stored consecutively in the // selected, stored consecutively in the
// columns of VL, in the same order as their // columns of VL, in the same order as their
// eigenvalues. // eigenvalues.
@@ -78,9 +78,9 @@ import (
// //
// On return, if side is lapack.EVRight or lapack.EVRightLeft, // On return, if side is lapack.EVRight or lapack.EVRightLeft,
// VR will contain: // VR will contain:
// if howmny == lapack.AllEV, the matrix X of right eigenvectors of T, // if howmny == lapack.EVAll, the matrix X of right eigenvectors of T,
// if howmny == lapack.AllEVMulQ, the matrix Q*X, // if howmny == lapack.EVAllMulQ, the matrix Q*X,
// if howmny == lapack.SelectedEV, the left eigenvectors of T specified by // if howmny == lapack.EVSelected, the left eigenvectors of T specified by
// selected, stored consecutively in the // selected, stored consecutively in the
// columns of VR, in the same order as their // columns of VR, in the same order as their
// eigenvalues. // eigenvalues.
@@ -105,7 +105,7 @@ import (
// the eigenvectors. // the eigenvectors.
// //
// Dtrevc3 is an internal routine. It is exported for testing purposes. // Dtrevc3 is an internal routine. It is exported for testing purposes.
func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, selected []bool, n int, t []float64, ldt int, vl []float64, ldvl int, vr []float64, ldvr int, mm int, work []float64, lwork int) (m int) { func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.EVHowMany, selected []bool, n int, t []float64, ldt int, vl []float64, ldvl int, vr []float64, ldvr int, mm int, work []float64, lwork int) (m int) {
switch side { switch side {
default: default:
panic(badEVSide) panic(badEVSide)
@@ -113,8 +113,8 @@ func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, se
} }
switch howmny { switch howmny {
default: default:
panic(badHowMany) panic(badEVHowMany)
case lapack.AllEV, lapack.AllEVMulQ, lapack.SelectedEV: case lapack.EVAll, lapack.EVAllMulQ, lapack.EVSelected:
} }
switch { switch {
case n < 0: case n < 0:
@@ -125,7 +125,7 @@ func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, se
panic(badWork) panic(badWork)
} }
if lwork != -1 { if lwork != -1 {
if howmny == lapack.SelectedEV { if howmny == lapack.EVSelected {
if len(selected) != n { if len(selected) != n {
panic("lapack: bad selected length") panic("lapack: bad selected length")
} }
@@ -186,7 +186,7 @@ func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, se
// Use blocked version of back-transformation if sufficient workspace. // Use blocked version of back-transformation if sufficient workspace.
// Zero-out the workspace to avoid potential NaN propagation. // Zero-out the workspace to avoid potential NaN propagation.
if howmny == lapack.AllEVMulQ && lwork >= n+2*n*nbmin { if howmny == lapack.EVAllMulQ && lwork >= n+2*n*nbmin {
nb = min((lwork-n)/(2*n), nbmax) nb = min((lwork-n)/(2*n), nbmax)
impl.Dlaset(blas.All, n, 1+2*nb, 0, 0, work[:n+2*nb*n], 1+2*nb) impl.Dlaset(blas.All, n, 1+2*nb, 0, 0, work[:n+2*nb*n], 1+2*nb)
} else { } else {
@@ -261,7 +261,7 @@ func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, se
ip = -1 ip = -1
} }
if howmny == lapack.SelectedEV { if howmny == lapack.EVSelected {
if ip == 0 { if ip == 0 {
if !selected[ki] { if !selected[ki] {
continue continue
@@ -336,7 +336,7 @@ func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, se
} }
// Copy the vector x or Q*x to VR and normalize. // Copy the vector x or Q*x to VR and normalize.
switch { switch {
case howmny != lapack.AllEVMulQ: case howmny != lapack.EVAllMulQ:
// No back-transform: copy x to VR and normalize. // No back-transform: copy x to VR and normalize.
bi.Dcopy(ki+1, b[iv:], ldb, vr[is:], ldvr) bi.Dcopy(ki+1, b[iv:], ldb, vr[is:], ldvr)
ii := bi.Idamax(ki+1, vr[is:], ldvr) ii := bi.Idamax(ki+1, vr[is:], ldvr)
@@ -447,7 +447,7 @@ func (impl Implementation) Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, se
// Copy the vector x or Q*x to VR and normalize. // Copy the vector x or Q*x to VR and normalize.
switch { switch {
case howmny != lapack.AllEVMulQ: case howmny != lapack.EVAllMulQ:
// No back-transform: copy x to VR and normalize. // No back-transform: copy x to VR and normalize.
bi.Dcopy(ki+1, b[iv-1:], ldb, vr[is-1:], ldvr) bi.Dcopy(ki+1, b[iv-1:], ldb, vr[is-1:], ldvr)
bi.Dcopy(ki+1, b[iv:], ldb, vr[is:], ldvr) bi.Dcopy(ki+1, b[iv:], ldb, vr[is:], ldvr)
@@ -569,7 +569,7 @@ leftev:
// conjugate pair. // conjugate pair.
ip = 1 ip = 1
} }
if howmny == lapack.SelectedEV && !selected[ki] { if howmny == lapack.EVSelected && !selected[ki] {
continue continue
} }
@@ -648,7 +648,7 @@ leftev:
} }
// Copy the vector x or Q*x to VL and normalize. // Copy the vector x or Q*x to VL and normalize.
switch { switch {
case howmny != lapack.AllEVMulQ: case howmny != lapack.EVAllMulQ:
// No back-transform: copy x to VL and normalize. // No back-transform: copy x to VL and normalize.
bi.Dcopy(n-ki, b[ki*ldb+iv:], ldb, vl[ki*ldvl+is:], ldvl) bi.Dcopy(n-ki, b[ki*ldb+iv:], ldb, vl[ki*ldvl+is:], ldvl)
ii := bi.Idamax(n-ki, vl[ki*ldvl+is:], ldvl) + ki ii := bi.Idamax(n-ki, vl[ki*ldvl+is:], ldvl) + ki
@@ -767,7 +767,7 @@ leftev:
} }
// Copy the vector x or Q*x to VL and normalize. // Copy the vector x or Q*x to VL and normalize.
switch { switch {
case howmny != lapack.AllEVMulQ: case howmny != lapack.EVAllMulQ:
// No back-transform: copy x to VL and normalize. // No back-transform: copy x to VL and normalize.
bi.Dcopy(n-ki, b[ki*ldb+iv:], ldb, vl[ki*ldvl+is:], ldvl) bi.Dcopy(n-ki, b[ki*ldb+iv:], ldb, vl[ki*ldvl+is:], ldvl)
bi.Dcopy(n-ki, b[ki*ldb+iv+1:], ldb, vl[ki*ldvl+is+1:], ldvl) bi.Dcopy(n-ki, b[ki*ldb+iv+1:], ldb, vl[ki*ldvl+is+1:], ldvl)

View File

@@ -28,10 +28,10 @@ const (
badDirect = "lapack: bad direct" badDirect = "lapack: bad direct"
badE = "lapack: e has insufficient length" badE = "lapack: e has insufficient length"
badEVComp = "lapack: bad EVComp" badEVComp = "lapack: bad EVComp"
badEVHowMany = "lapack: bad EVHowMany"
badEVJob = "lapack: bad EVJob" badEVJob = "lapack: bad EVJob"
badEVSide = "lapack: bad EVSide" badEVSide = "lapack: bad EVSide"
badGSVDJob = "lapack: bad GSVDJob" badGSVDJob = "lapack: bad GSVDJob"
badHowMany = "lapack: bad HowMany"
badIlo = "lapack: ilo out of range" badIlo = "lapack: ilo out of range"
badIhi = "lapack: ihi out of range" badIhi = "lapack: ihi out of range"
badIpiv = "lapack: bad permutation length" badIpiv = "lapack: bad permutation length"

View File

@@ -187,12 +187,11 @@ const (
EVRightLeft EVSide = 'B' // Both right and left eigenvectors are computed. EVRightLeft EVSide = 'B' // Both right and left eigenvectors are computed.
) )
// HowMany specifies which eigenvectors will be computed. // EVHowMany specifies which eigenvectors are computed in Dtrevc3 and how.
type HowMany byte type EVHowMany byte
// HowMany constants for Dhseqr.
const ( const (
AllEV HowMany = 'A' // Compute all right and/or left eigenvectors. EVAll EVHowMany = 'A' // Compute all right and/or left eigenvectors.
AllEVMulQ HowMany = 'B' // Compute all right and/or left eigenvectors multiplied by an input matrix. EVAllMulQ EVHowMany = 'B' // Compute all right and/or left eigenvectors multiplied by an input matrix.
SelectedEV HowMany = 'S' // Compute selected right and/or left eigenvectors. EVSelected EVHowMany = 'S' // Compute selected right and/or left eigenvectors.
) )

View File

@@ -17,7 +17,7 @@ import (
) )
type Dtrevc3er interface { type Dtrevc3er interface {
Dtrevc3(side lapack.EVSide, howmny lapack.HowMany, selected []bool, n int, t []float64, ldt int, vl []float64, ldvl int, vr []float64, ldvr int, mm int, work []float64, lwork int) int Dtrevc3(side lapack.EVSide, howmny lapack.EVHowMany, selected []bool, n int, t []float64, ldt int, vl []float64, ldvl int, vr []float64, ldvr int, mm int, work []float64, lwork int) int
} }
func Dtrevc3Test(t *testing.T, impl Dtrevc3er) { func Dtrevc3Test(t *testing.T, impl Dtrevc3er) {
@@ -38,7 +38,7 @@ func Dtrevc3Test(t *testing.T, impl Dtrevc3er) {
} }
} }
func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack.HowMany, tmat blas64.General, optwork bool, rnd *rand.Rand) { func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack.EVHowMany, tmat blas64.General, optwork bool, rnd *rand.Rand) {
const tol = 1e-14 const tol = 1e-14
n := tmat.Rows n := tmat.Rows
@@ -48,7 +48,7 @@ func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack
var selected, selectedWant []bool var selected, selectedWant []bool
var mWant int // How many columns will the eigenvectors occupy. var mWant int // How many columns will the eigenvectors occupy.
if howmny == lapack.SelectedEV { if howmny == lapack.EVSelected {
selected = make([]bool, n) selected = make([]bool, n)
selectedWant = make([]bool, n) selectedWant = make([]bool, n)
// Dtrevc3 will compute only selected eigenvectors. Pick them // Dtrevc3 will compute only selected eigenvectors. Pick them
@@ -88,7 +88,7 @@ func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack
var vr blas64.General var vr blas64.General
if right { if right {
if howmny == lapack.AllEVMulQ { if howmny == lapack.EVAllMulQ {
vr = eye(n, n+extra) vr = eye(n, n+extra)
} else { } else {
// VR will be overwritten. // VR will be overwritten.
@@ -98,7 +98,7 @@ func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack
var vl blas64.General var vl blas64.General
if left { if left {
if howmny == lapack.AllEVMulQ { if howmny == lapack.EVAllMulQ {
vl = eye(n, n+extra) vl = eye(n, n+extra)
} else { } else {
// VL will be overwritten. // VL will be overwritten.
@@ -132,7 +132,7 @@ func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack
t.Errorf("%v: unexpected value of m. Want %v, got %v", prefix, mWant, m) t.Errorf("%v: unexpected value of m. Want %v, got %v", prefix, mWant, m)
} }
if howmny == lapack.SelectedEV { if howmny == lapack.EVSelected {
for i := range selected { for i := range selected {
if selected[i] != selectedWant[i] { if selected[i] != selectedWant[i] {
t.Errorf("%v: unexpected selected[%v]", prefix, i) t.Errorf("%v: unexpected selected[%v]", prefix, i)
@@ -146,7 +146,7 @@ func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack
for j := 0; j < n; { for j := 0; j < n; {
re := tmat.Data[j*tmat.Stride+j] re := tmat.Data[j*tmat.Stride+j]
if j == n-1 || tmat.Data[(j+1)*tmat.Stride+j] == 0 { if j == n-1 || tmat.Data[(j+1)*tmat.Stride+j] == 0 {
if howmny == lapack.SelectedEV && !selected[j] { if howmny == lapack.EVSelected && !selected[j] {
j++ j++
continue continue
} }
@@ -174,7 +174,7 @@ func testDtrevc3(t *testing.T, impl Dtrevc3er, side lapack.EVSide, howmny lapack
j++ j++
continue continue
} }
if howmny == lapack.SelectedEV && !selected[j] { if howmny == lapack.EVSelected && !selected[j] {
j += 2 j += 2
continue continue
} }