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.
7 import "gonum.org/v1/gonum/blas"
9 // GeneralCols represents a matrix using the conventional column-major storage scheme.
10 type GeneralCols General
12 // From fills the receiver with elements from a. The receiver
13 // must have the same dimensions as a and have adequate backing
15 func (t GeneralCols) From(a General) {
16 if t.Rows != a.Rows || t.Cols != a.Cols {
17 panic("blas64: mismatched dimension")
19 if len(t.Data) < (t.Cols-1)*t.Stride+t.Rows {
20 panic("blas64: short data slice")
22 for i := 0; i < a.Rows; i++ {
23 for j, v := range a.Data[i*a.Stride : i*a.Stride+a.Cols] {
24 t.Data[i+j*t.Stride] = v
29 // From fills the receiver with elements from a. The receiver
30 // must have the same dimensions as a and have adequate backing
32 func (t General) From(a GeneralCols) {
33 if t.Rows != a.Rows || t.Cols != a.Cols {
34 panic("blas64: mismatched dimension")
36 if len(t.Data) < (t.Rows-1)*t.Stride+t.Cols {
37 panic("blas64: short data slice")
39 for j := 0; j < a.Cols; j++ {
40 for i, v := range a.Data[j*a.Stride : j*a.Stride+a.Rows] {
41 t.Data[i*t.Stride+j] = v
46 // TriangularCols represents a matrix using the conventional column-major storage scheme.
47 type TriangularCols Triangular
49 // From fills the receiver with elements from a. The receiver
50 // must have the same dimensions, uplo and diag as a and have
51 // adequate backing data storage.
52 func (t TriangularCols) From(a Triangular) {
54 panic("blas64: mismatched dimension")
57 panic("blas64: mismatched BLAS uplo")
60 panic("blas64: mismatched BLAS diag")
64 panic("blas64: bad BLAS uplo")
66 for i := 0; i < a.N; i++ {
67 for j := i; j < a.N; j++ {
68 t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
72 for i := 0; i < a.N; i++ {
73 for j := 0; j <= i; j++ {
74 t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
78 for i := 0; i < a.N; i++ {
79 for j := 0; j < a.N; j++ {
80 t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
86 // From fills the receiver with elements from a. The receiver
87 // must have the same dimensions, uplo and diag as a and have
88 // adequate backing data storage.
89 func (t Triangular) From(a TriangularCols) {
91 panic("blas64: mismatched dimension")
94 panic("blas64: mismatched BLAS uplo")
97 panic("blas64: mismatched BLAS diag")
101 panic("blas64: bad BLAS uplo")
103 for i := 0; i < a.N; i++ {
104 for j := i; j < a.N; j++ {
105 t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
109 for i := 0; i < a.N; i++ {
110 for j := 0; j <= i; j++ {
111 t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
115 for i := 0; i < a.N; i++ {
116 for j := 0; j < a.N; j++ {
117 t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
123 // BandCols represents a matrix using the band column-major storage scheme.
126 // From fills the receiver with elements from a. The receiver
127 // must have the same dimensions and bandwidth as a and have
128 // adequate backing data storage.
129 func (t BandCols) From(a Band) {
130 if t.Rows != a.Rows || t.Cols != a.Cols {
131 panic("blas64: mismatched dimension")
133 if t.KL != a.KL || t.KU != a.KU {
134 panic("blas64: mismatched bandwidth")
136 if a.Stride < a.KL+a.KU+1 {
137 panic("blas64: short stride for source")
139 if t.Stride < t.KL+t.KU+1 {
140 panic("blas64: short stride for destination")
142 for i := 0; i < a.Rows; i++ {
143 for j := max(0, i-a.KL); j < min(i+a.KU+1, a.Cols); j++ {
144 t.Data[i+t.KU-j+j*t.Stride] = a.Data[j+a.KL-i+i*a.Stride]
149 // From fills the receiver with elements from a. The receiver
150 // must have the same dimensions and bandwidth as a and have
151 // adequate backing data storage.
152 func (t Band) From(a BandCols) {
153 if t.Rows != a.Rows || t.Cols != a.Cols {
154 panic("blas64: mismatched dimension")
156 if t.KL != a.KL || t.KU != a.KU {
157 panic("blas64: mismatched bandwidth")
159 if a.Stride < a.KL+a.KU+1 {
160 panic("blas64: short stride for source")
162 if t.Stride < t.KL+t.KU+1 {
163 panic("blas64: short stride for destination")
165 for j := 0; j < a.Cols; j++ {
166 for i := max(0, j-a.KU); i < min(j+a.KL+1, a.Rows); i++ {
167 t.Data[j+a.KL-i+i*a.Stride] = a.Data[i+t.KU-j+j*t.Stride]
172 // TriangularBandCols represents a symmetric matrix using the band column-major storage scheme.
173 type TriangularBandCols TriangularBand
175 // From fills the receiver with elements from a. The receiver
176 // must have the same dimensions, bandwidth and uplo as a and
177 // have adequate backing data storage.
178 func (t TriangularBandCols) From(a TriangularBand) {
180 panic("blas64: mismatched dimension")
183 panic("blas64: mismatched bandwidth")
185 if a.Stride < a.K+1 {
186 panic("blas64: short stride for source")
188 if t.Stride < t.K+1 {
189 panic("blas64: short stride for destination")
191 if t.Uplo != a.Uplo {
192 panic("blas64: mismatched BLAS uplo")
194 if t.Diag != a.Diag {
195 panic("blas64: mismatched BLAS diag")
198 Rows: t.N, Cols: t.N,
203 Rows: a.N, Cols: a.N,
209 panic("blas64: bad BLAS uplo")
220 // From fills the receiver with elements from a. The receiver
221 // must have the same dimensions, bandwidth and uplo as a and
222 // have adequate backing data storage.
223 func (t TriangularBand) From(a TriangularBandCols) {
225 panic("blas64: mismatched dimension")
228 panic("blas64: mismatched bandwidth")
230 if a.Stride < a.K+1 {
231 panic("blas64: short stride for source")
233 if t.Stride < t.K+1 {
234 panic("blas64: short stride for destination")
236 if t.Uplo != a.Uplo {
237 panic("blas64: mismatched BLAS uplo")
239 if t.Diag != a.Diag {
240 panic("blas64: mismatched BLAS diag")
243 Rows: t.N, Cols: t.N,
248 Rows: a.N, Cols: a.N,
254 panic("blas64: bad BLAS uplo")
265 func min(a, b int) int {
272 func max(a, b int) int {