gonum.org/v1/gonum@v0.14.0/lapack/gonum/ilaenv.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  // Ilaenv returns algorithm tuning parameters for the algorithm given by the
     8  // input string. ispec specifies the parameter to return:
     9  //
    10  //	1: The optimal block size for a blocked algorithm.
    11  //	2: The minimum block size for a blocked algorithm.
    12  //	3: The block size of unprocessed data at which a blocked algorithm should
    13  //	   crossover to an unblocked version.
    14  //	4: The number of shifts.
    15  //	5: The minimum column dimension for blocking to be used.
    16  //	6: The crossover point for SVD (to use QR factorization or not).
    17  //	7: The number of processors.
    18  //	8: The crossover point for multi-shift in QR and QZ methods for non-symmetric eigenvalue problems.
    19  //	9: Maximum size of the subproblems in divide-and-conquer algorithms.
    20  //	10: ieee infinity and NaN arithmetic can be trusted not to trap.
    21  //	11: ieee infinity arithmetic can be trusted not to trap.
    22  //	12...16: parameters for Dhseqr and related functions. See Iparmq for more
    23  //	         information.
    24  //
    25  // Ilaenv is an internal routine. It is exported for testing purposes.
    26  func (impl Implementation) Ilaenv(ispec int, name string, opts string, n1, n2, n3, n4 int) int {
    27  	// TODO(btracey): Replace this with a constant lookup? A list of constants?
    28  	sname := name[0] == 'S' || name[0] == 'D'
    29  	cname := name[0] == 'C' || name[0] == 'Z'
    30  	if !sname && !cname {
    31  		panic(badName)
    32  	}
    33  	c2 := name[1:3]
    34  	c3 := name[3:6]
    35  	c4 := c3[1:3]
    36  
    37  	switch ispec {
    38  	default:
    39  		panic(badIspec)
    40  	case 1:
    41  		switch c2 {
    42  		default:
    43  			panic(badName)
    44  		case "GE":
    45  			switch c3 {
    46  			default:
    47  				panic(badName)
    48  			case "TRF":
    49  				if sname {
    50  					return 64
    51  				}
    52  				return 64
    53  			case "QRF", "RQF", "LQF", "QLF":
    54  				if sname {
    55  					return 32
    56  				}
    57  				return 32
    58  			case "HRD":
    59  				if sname {
    60  					return 32
    61  				}
    62  				return 32
    63  			case "BRD":
    64  				if sname {
    65  					return 32
    66  				}
    67  				return 32
    68  			case "TRI":
    69  				if sname {
    70  					return 64
    71  				}
    72  				return 64
    73  			}
    74  		case "PO":
    75  			switch c3 {
    76  			default:
    77  				panic(badName)
    78  			case "TRF":
    79  				if sname {
    80  					return 64
    81  				}
    82  				return 64
    83  			}
    84  		case "SY":
    85  			switch c3 {
    86  			default:
    87  				panic(badName)
    88  			case "TRF":
    89  				if sname {
    90  					return 64
    91  				}
    92  				return 64
    93  			case "TRD":
    94  				return 32
    95  			case "GST":
    96  				return 64
    97  			}
    98  		case "HE":
    99  			switch c3 {
   100  			default:
   101  				panic(badName)
   102  			case "TRF":
   103  				return 64
   104  			case "TRD":
   105  				return 32
   106  			case "GST":
   107  				return 64
   108  			}
   109  		case "OR":
   110  			switch c3[0] {
   111  			default:
   112  				panic(badName)
   113  			case 'G':
   114  				switch c3[1:] {
   115  				default:
   116  					panic(badName)
   117  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   118  					return 32
   119  				}
   120  			case 'M':
   121  				switch c3[1:] {
   122  				default:
   123  					panic(badName)
   124  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   125  					return 32
   126  				}
   127  			}
   128  		case "UN":
   129  			switch c3[0] {
   130  			default:
   131  				panic(badName)
   132  			case 'G':
   133  				switch c3[1:] {
   134  				default:
   135  					panic(badName)
   136  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   137  					return 32
   138  				}
   139  			case 'M':
   140  				switch c3[1:] {
   141  				default:
   142  					panic(badName)
   143  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   144  					return 32
   145  				}
   146  			}
   147  		case "GB":
   148  			switch c3 {
   149  			default:
   150  				panic(badName)
   151  			case "TRF":
   152  				if sname {
   153  					if n4 <= 64 {
   154  						return 1
   155  					}
   156  					return 32
   157  				}
   158  				if n4 <= 64 {
   159  					return 1
   160  				}
   161  				return 32
   162  			}
   163  		case "PB":
   164  			switch c3 {
   165  			default:
   166  				panic(badName)
   167  			case "TRF":
   168  				if sname {
   169  					if n2 <= 64 {
   170  						return 1
   171  					}
   172  					return 32
   173  				}
   174  				if n2 <= 64 {
   175  					return 1
   176  				}
   177  				return 32
   178  			}
   179  		case "TR":
   180  			switch c3 {
   181  			default:
   182  				panic(badName)
   183  			case "TRI":
   184  				if sname {
   185  					return 64
   186  				}
   187  				return 64
   188  			case "EVC":
   189  				if sname {
   190  					return 64
   191  				}
   192  				return 64
   193  			}
   194  		case "LA":
   195  			switch c3 {
   196  			default:
   197  				panic(badName)
   198  			case "UUM":
   199  				if sname {
   200  					return 64
   201  				}
   202  				return 64
   203  			}
   204  		case "ST":
   205  			if sname && c3 == "EBZ" {
   206  				return 1
   207  			}
   208  			panic(badName)
   209  		}
   210  	case 2:
   211  		switch c2 {
   212  		default:
   213  			panic(badName)
   214  		case "GE":
   215  			switch c3 {
   216  			default:
   217  				panic(badName)
   218  			case "QRF", "RQF", "LQF", "QLF":
   219  				if sname {
   220  					return 2
   221  				}
   222  				return 2
   223  			case "HRD":
   224  				if sname {
   225  					return 2
   226  				}
   227  				return 2
   228  			case "BRD":
   229  				if sname {
   230  					return 2
   231  				}
   232  				return 2
   233  			case "TRI":
   234  				if sname {
   235  					return 2
   236  				}
   237  				return 2
   238  			}
   239  		case "SY":
   240  			switch c3 {
   241  			default:
   242  				panic(badName)
   243  			case "TRF":
   244  				if sname {
   245  					return 8
   246  				}
   247  				return 8
   248  			case "TRD":
   249  				if sname {
   250  					return 2
   251  				}
   252  				panic(badName)
   253  			}
   254  		case "HE":
   255  			if c3 == "TRD" {
   256  				return 2
   257  			}
   258  			panic(badName)
   259  		case "OR":
   260  			if !sname {
   261  				panic(badName)
   262  			}
   263  			switch c3[0] {
   264  			default:
   265  				panic(badName)
   266  			case 'G':
   267  				switch c4 {
   268  				default:
   269  					panic(badName)
   270  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   271  					return 2
   272  				}
   273  			case 'M':
   274  				switch c4 {
   275  				default:
   276  					panic(badName)
   277  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   278  					return 2
   279  				}
   280  			}
   281  		case "UN":
   282  			switch c3[0] {
   283  			default:
   284  				panic(badName)
   285  			case 'G':
   286  				switch c4 {
   287  				default:
   288  					panic(badName)
   289  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   290  					return 2
   291  				}
   292  			case 'M':
   293  				switch c4 {
   294  				default:
   295  					panic(badName)
   296  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   297  					return 2
   298  				}
   299  			}
   300  		}
   301  	case 3:
   302  		switch c2 {
   303  		default:
   304  			panic(badName)
   305  		case "GE":
   306  			switch c3 {
   307  			default:
   308  				panic(badName)
   309  			case "QRF", "RQF", "LQF", "QLF":
   310  				if sname {
   311  					return 128
   312  				}
   313  				return 128
   314  			case "HRD":
   315  				if sname {
   316  					return 128
   317  				}
   318  				return 128
   319  			case "BRD":
   320  				if sname {
   321  					return 128
   322  				}
   323  				return 128
   324  			}
   325  		case "SY":
   326  			if sname && c3 == "TRD" {
   327  				return 32
   328  			}
   329  			panic(badName)
   330  		case "HE":
   331  			if c3 == "TRD" {
   332  				return 32
   333  			}
   334  			panic(badName)
   335  		case "OR":
   336  			switch c3[0] {
   337  			default:
   338  				panic(badName)
   339  			case 'G':
   340  				switch c4 {
   341  				default:
   342  					panic(badName)
   343  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   344  					return 128
   345  				}
   346  			}
   347  		case "UN":
   348  			switch c3[0] {
   349  			default:
   350  				panic(badName)
   351  			case 'G':
   352  				switch c4 {
   353  				default:
   354  					panic(badName)
   355  				case "QR", "RQ", "LQ", "QL", "HR", "TR", "BR":
   356  					return 128
   357  				}
   358  			}
   359  		}
   360  	case 4:
   361  		// Used by xHSEQR
   362  		return 6
   363  	case 5:
   364  		// Not used
   365  		return 2
   366  	case 6:
   367  		// Used by xGELSS and xGESVD
   368  		return int(float64(min(n1, n2)) * 1.6)
   369  	case 7:
   370  		// Not used
   371  		return 1
   372  	case 8:
   373  		// Used by xHSEQR
   374  		return 50
   375  	case 9:
   376  		// used by xGELSD and xGESDD
   377  		return 25
   378  	case 10:
   379  		// Go guarantees ieee
   380  		return 1
   381  	case 11:
   382  		// Go guarantees ieee
   383  		return 1
   384  	case 12, 13, 14, 15, 16:
   385  		// Dhseqr and related functions for eigenvalue problems.
   386  		return impl.Iparmq(ispec, name, opts, n1, n2, n3, n4)
   387  	}
   388  }