gonum.org/v1/gonum@v0.14.0/blas/blas32/conv.go (about)

     1  // Code generated by "go generate gonum.org/v1/gonum/blas”; DO NOT EDIT.
     2  
     3  // Copyright ©2015 The Gonum Authors. All rights reserved.
     4  // Use of this source code is governed by a BSD-style
     5  // license that can be found in the LICENSE file.
     6  
     7  package blas32
     8  
     9  import "gonum.org/v1/gonum/blas"
    10  
    11  // GeneralCols represents a matrix using the conventional column-major storage scheme.
    12  type GeneralCols General
    13  
    14  // From fills the receiver with elements from a. The receiver
    15  // must have the same dimensions as a and have adequate backing
    16  // data storage.
    17  func (t GeneralCols) From(a General) {
    18  	if t.Rows != a.Rows || t.Cols != a.Cols {
    19  		panic("blas32: mismatched dimension")
    20  	}
    21  	if len(t.Data) < (t.Cols-1)*t.Stride+t.Rows {
    22  		panic("blas32: short data slice")
    23  	}
    24  	for i := 0; i < a.Rows; i++ {
    25  		for j, v := range a.Data[i*a.Stride : i*a.Stride+a.Cols] {
    26  			t.Data[i+j*t.Stride] = v
    27  		}
    28  	}
    29  }
    30  
    31  // From fills the receiver with elements from a. The receiver
    32  // must have the same dimensions as a and have adequate backing
    33  // data storage.
    34  func (t General) From(a GeneralCols) {
    35  	if t.Rows != a.Rows || t.Cols != a.Cols {
    36  		panic("blas32: mismatched dimension")
    37  	}
    38  	if len(t.Data) < (t.Rows-1)*t.Stride+t.Cols {
    39  		panic("blas32: short data slice")
    40  	}
    41  	for j := 0; j < a.Cols; j++ {
    42  		for i, v := range a.Data[j*a.Stride : j*a.Stride+a.Rows] {
    43  			t.Data[i*t.Stride+j] = v
    44  		}
    45  	}
    46  }
    47  
    48  // TriangularCols represents a matrix using the conventional column-major storage scheme.
    49  type TriangularCols Triangular
    50  
    51  // From fills the receiver with elements from a. The receiver
    52  // must have the same dimensions, uplo and diag as a and have
    53  // adequate backing data storage.
    54  func (t TriangularCols) From(a Triangular) {
    55  	if t.N != a.N {
    56  		panic("blas32: mismatched dimension")
    57  	}
    58  	if t.Uplo != a.Uplo {
    59  		panic("blas32: mismatched BLAS uplo")
    60  	}
    61  	if t.Diag != a.Diag {
    62  		panic("blas32: mismatched BLAS diag")
    63  	}
    64  	switch a.Uplo {
    65  	default:
    66  		panic("blas32: bad BLAS uplo")
    67  	case blas.Upper:
    68  		for i := 0; i < a.N; i++ {
    69  			for j := i; j < a.N; j++ {
    70  				t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
    71  			}
    72  		}
    73  	case blas.Lower:
    74  		for i := 0; i < a.N; i++ {
    75  			for j := 0; j <= i; j++ {
    76  				t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
    77  			}
    78  		}
    79  	case blas.All:
    80  		for i := 0; i < a.N; i++ {
    81  			for j := 0; j < a.N; j++ {
    82  				t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
    83  			}
    84  		}
    85  	}
    86  }
    87  
    88  // From fills the receiver with elements from a. The receiver
    89  // must have the same dimensions, uplo and diag as a and have
    90  // adequate backing data storage.
    91  func (t Triangular) From(a TriangularCols) {
    92  	if t.N != a.N {
    93  		panic("blas32: mismatched dimension")
    94  	}
    95  	if t.Uplo != a.Uplo {
    96  		panic("blas32: mismatched BLAS uplo")
    97  	}
    98  	if t.Diag != a.Diag {
    99  		panic("blas32: mismatched BLAS diag")
   100  	}
   101  	switch a.Uplo {
   102  	default:
   103  		panic("blas32: bad BLAS uplo")
   104  	case blas.Upper:
   105  		for i := 0; i < a.N; i++ {
   106  			for j := i; j < a.N; j++ {
   107  				t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
   108  			}
   109  		}
   110  	case blas.Lower:
   111  		for i := 0; i < a.N; i++ {
   112  			for j := 0; j <= i; j++ {
   113  				t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
   114  			}
   115  		}
   116  	case blas.All:
   117  		for i := 0; i < a.N; i++ {
   118  			for j := 0; j < a.N; j++ {
   119  				t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
   120  			}
   121  		}
   122  	}
   123  }
   124  
   125  // BandCols represents a matrix using the band column-major storage scheme.
   126  type BandCols Band
   127  
   128  // From fills the receiver with elements from a. The receiver
   129  // must have the same dimensions and bandwidth as a and have
   130  // adequate backing data storage.
   131  func (t BandCols) From(a Band) {
   132  	if t.Rows != a.Rows || t.Cols != a.Cols {
   133  		panic("blas32: mismatched dimension")
   134  	}
   135  	if t.KL != a.KL || t.KU != a.KU {
   136  		panic("blas32: mismatched bandwidth")
   137  	}
   138  	if a.Stride < a.KL+a.KU+1 {
   139  		panic("blas32: short stride for source")
   140  	}
   141  	if t.Stride < t.KL+t.KU+1 {
   142  		panic("blas32: short stride for destination")
   143  	}
   144  	for i := 0; i < a.Rows; i++ {
   145  		for j := max(0, i-a.KL); j < min(i+a.KU+1, a.Cols); j++ {
   146  			t.Data[i+t.KU-j+j*t.Stride] = a.Data[j+a.KL-i+i*a.Stride]
   147  		}
   148  	}
   149  }
   150  
   151  // From fills the receiver with elements from a. The receiver
   152  // must have the same dimensions and bandwidth as a and have
   153  // adequate backing data storage.
   154  func (t Band) From(a BandCols) {
   155  	if t.Rows != a.Rows || t.Cols != a.Cols {
   156  		panic("blas32: mismatched dimension")
   157  	}
   158  	if t.KL != a.KL || t.KU != a.KU {
   159  		panic("blas32: mismatched bandwidth")
   160  	}
   161  	if a.Stride < a.KL+a.KU+1 {
   162  		panic("blas32: short stride for source")
   163  	}
   164  	if t.Stride < t.KL+t.KU+1 {
   165  		panic("blas32: short stride for destination")
   166  	}
   167  	for j := 0; j < a.Cols; j++ {
   168  		for i := max(0, j-a.KU); i < min(j+a.KL+1, a.Rows); i++ {
   169  			t.Data[j+a.KL-i+i*a.Stride] = a.Data[i+t.KU-j+j*t.Stride]
   170  		}
   171  	}
   172  }
   173  
   174  // TriangularBandCols represents a triangular matrix using the band column-major storage scheme.
   175  type TriangularBandCols TriangularBand
   176  
   177  // From fills the receiver with elements from a. The receiver
   178  // must have the same dimensions, bandwidth and uplo as a and
   179  // have adequate backing data storage.
   180  func (t TriangularBandCols) From(a TriangularBand) {
   181  	if t.N != a.N {
   182  		panic("blas32: mismatched dimension")
   183  	}
   184  	if t.K != a.K {
   185  		panic("blas32: mismatched bandwidth")
   186  	}
   187  	if a.Stride < a.K+1 {
   188  		panic("blas32: short stride for source")
   189  	}
   190  	if t.Stride < t.K+1 {
   191  		panic("blas32: short stride for destination")
   192  	}
   193  	if t.Uplo != a.Uplo {
   194  		panic("blas32: mismatched BLAS uplo")
   195  	}
   196  	if t.Diag != a.Diag {
   197  		panic("blas32: mismatched BLAS diag")
   198  	}
   199  	dst := BandCols{
   200  		Rows: t.N, Cols: t.N,
   201  		Stride: t.Stride,
   202  		Data:   t.Data,
   203  	}
   204  	src := Band{
   205  		Rows: a.N, Cols: a.N,
   206  		Stride: a.Stride,
   207  		Data:   a.Data,
   208  	}
   209  	switch a.Uplo {
   210  	default:
   211  		panic("blas32: bad BLAS uplo")
   212  	case blas.Upper:
   213  		dst.KU = t.K
   214  		src.KU = a.K
   215  	case blas.Lower:
   216  		dst.KL = t.K
   217  		src.KL = a.K
   218  	}
   219  	dst.From(src)
   220  }
   221  
   222  // From fills the receiver with elements from a. The receiver
   223  // must have the same dimensions, bandwidth and uplo as a and
   224  // have adequate backing data storage.
   225  func (t TriangularBand) From(a TriangularBandCols) {
   226  	if t.N != a.N {
   227  		panic("blas32: mismatched dimension")
   228  	}
   229  	if t.K != a.K {
   230  		panic("blas32: mismatched bandwidth")
   231  	}
   232  	if a.Stride < a.K+1 {
   233  		panic("blas32: short stride for source")
   234  	}
   235  	if t.Stride < t.K+1 {
   236  		panic("blas32: short stride for destination")
   237  	}
   238  	if t.Uplo != a.Uplo {
   239  		panic("blas32: mismatched BLAS uplo")
   240  	}
   241  	if t.Diag != a.Diag {
   242  		panic("blas32: mismatched BLAS diag")
   243  	}
   244  	dst := Band{
   245  		Rows: t.N, Cols: t.N,
   246  		Stride: t.Stride,
   247  		Data:   t.Data,
   248  	}
   249  	src := BandCols{
   250  		Rows: a.N, Cols: a.N,
   251  		Stride: a.Stride,
   252  		Data:   a.Data,
   253  	}
   254  	switch a.Uplo {
   255  	default:
   256  		panic("blas32: bad BLAS uplo")
   257  	case blas.Upper:
   258  		dst.KU = t.K
   259  		src.KU = a.K
   260  	case blas.Lower:
   261  		dst.KL = t.K
   262  		src.KL = a.K
   263  	}
   264  	dst.From(src)
   265  }
   266  
   267  func min(a, b int) int {
   268  	if a < b {
   269  		return a
   270  	}
   271  	return b
   272  }
   273  
   274  func max(a, b int) int {
   275  	if a > b {
   276  		return a
   277  	}
   278  	return b
   279  }