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