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

     1  // Copyright ©2020 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"
     8  
     9  // Dlagtm performs one of the matrix-matrix operations
    10  //  C = alpha * A * B + beta * C   if trans == blas.NoTrans
    11  //  C = alpha * Aᵀ * B + beta * C  if trans == blas.Trans or blas.ConjTrans
    12  // where A is an m×m tridiagonal matrix represented by its diagonals dl, d, du,
    13  // B and C are m×n dense matrices, and alpha and beta are scalars.
    14  func (impl Implementation) Dlagtm(trans blas.Transpose, m, n int, alpha float64, dl, d, du []float64, b []float64, ldb int, beta float64, c []float64, ldc int) {
    15  	switch {
    16  	case trans != blas.NoTrans && trans != blas.Trans && trans != blas.ConjTrans:
    17  		panic(badTrans)
    18  	case m < 0:
    19  		panic(mLT0)
    20  	case n < 0:
    21  		panic(nLT0)
    22  	case ldb < max(1, n):
    23  		panic(badLdB)
    24  	case ldc < max(1, n):
    25  		panic(badLdC)
    26  	}
    27  
    28  	if m == 0 || n == 0 {
    29  		return
    30  	}
    31  
    32  	switch {
    33  	case len(dl) < m-1:
    34  		panic(shortDL)
    35  	case len(d) < m:
    36  		panic(shortD)
    37  	case len(du) < m-1:
    38  		panic(shortDU)
    39  	case len(b) < (m-1)*ldb+n:
    40  		panic(shortB)
    41  	case len(c) < (m-1)*ldc+n:
    42  		panic(shortC)
    43  	}
    44  
    45  	if beta != 1 {
    46  		if beta == 0 {
    47  			for i := 0; i < m; i++ {
    48  				ci := c[i*ldc : i*ldc+n]
    49  				for j := range ci {
    50  					ci[j] = 0
    51  				}
    52  			}
    53  		} else {
    54  			for i := 0; i < m; i++ {
    55  				ci := c[i*ldc : i*ldc+n]
    56  				for j := range ci {
    57  					ci[j] *= beta
    58  				}
    59  			}
    60  		}
    61  	}
    62  
    63  	if alpha == 0 {
    64  		return
    65  	}
    66  
    67  	if m == 1 {
    68  		if alpha == 1 {
    69  			for j := 0; j < n; j++ {
    70  				c[j] += d[0] * b[j]
    71  			}
    72  		} else {
    73  			for j := 0; j < n; j++ {
    74  				c[j] += alpha * d[0] * b[j]
    75  			}
    76  		}
    77  		return
    78  	}
    79  
    80  	if trans != blas.NoTrans {
    81  		dl, du = du, dl
    82  	}
    83  
    84  	if alpha == 1 {
    85  		for j := 0; j < n; j++ {
    86  			c[j] += d[0]*b[j] + du[0]*b[ldb+j]
    87  		}
    88  		for i := 1; i < m-1; i++ {
    89  			for j := 0; j < n; j++ {
    90  				c[i*ldc+j] += dl[i-1]*b[(i-1)*ldb+j] + d[i]*b[i*ldb+j] + du[i]*b[(i+1)*ldb+j]
    91  			}
    92  		}
    93  		for j := 0; j < n; j++ {
    94  			c[(m-1)*ldc+j] += dl[m-2]*b[(m-2)*ldb+j] + d[m-1]*b[(m-1)*ldb+j]
    95  		}
    96  	} else {
    97  		for j := 0; j < n; j++ {
    98  			c[j] += alpha * (d[0]*b[j] + du[0]*b[ldb+j])
    99  		}
   100  		for i := 1; i < m-1; i++ {
   101  			for j := 0; j < n; j++ {
   102  				c[i*ldc+j] += alpha * (dl[i-1]*b[(i-1)*ldb+j] + d[i]*b[i*ldb+j] + du[i]*b[(i+1)*ldb+j])
   103  			}
   104  		}
   105  		for j := 0; j < n; j++ {
   106  			c[(m-1)*ldc+j] += alpha * (dl[m-2]*b[(m-2)*ldb+j] + d[m-1]*b[(m-1)*ldb+j])
   107  		}
   108  	}
   109  }