OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / blas / blas64 / conv_symmetric.go
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 blas64
6
7 import "gonum.org/v1/gonum/blas"
8
9 // SymmetricCols represents a matrix using the conventional column-major storage scheme.
10 type SymmetricCols Symmetric
11
12 // From fills the receiver with elements from a. The receiver
13 // must have the same dimensions and uplo as a and have adequate
14 // backing data storage.
15 func (t SymmetricCols) From(a Symmetric) {
16         if t.N != a.N {
17                 panic("blas64: mismatched dimension")
18         }
19         if t.Uplo != a.Uplo {
20                 panic("blas64: mismatched BLAS uplo")
21         }
22         switch a.Uplo {
23         default:
24                 panic("blas64: bad BLAS uplo")
25         case blas.Upper:
26                 for i := 0; i < a.N; i++ {
27                         for j := i; j < a.N; j++ {
28                                 t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
29                         }
30                 }
31         case blas.Lower:
32                 for i := 0; i < a.N; i++ {
33                         for j := 0; j <= i; j++ {
34                                 t.Data[i+j*t.Stride] = a.Data[i*a.Stride+j]
35                         }
36                 }
37         }
38 }
39
40 // From fills the receiver with elements from a. The receiver
41 // must have the same dimensions and uplo as a and have adequate
42 // backing data storage.
43 func (t Symmetric) From(a SymmetricCols) {
44         if t.N != a.N {
45                 panic("blas64: mismatched dimension")
46         }
47         if t.Uplo != a.Uplo {
48                 panic("blas64: mismatched BLAS uplo")
49         }
50         switch a.Uplo {
51         default:
52                 panic("blas64: bad BLAS uplo")
53         case blas.Upper:
54                 for i := 0; i < a.N; i++ {
55                         for j := i; j < a.N; j++ {
56                                 t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
57                         }
58                 }
59         case blas.Lower:
60                 for i := 0; i < a.N; i++ {
61                         for j := 0; j <= i; j++ {
62                                 t.Data[i*t.Stride+j] = a.Data[i+j*a.Stride]
63                         }
64                 }
65         }
66 }
67
68 // SymmetricBandCols represents a symmetric matrix using the band column-major storage scheme.
69 type SymmetricBandCols SymmetricBand
70
71 // From fills the receiver with elements from a. The receiver
72 // must have the same dimensions, bandwidth and uplo as a and
73 // have adequate backing data storage.
74 func (t SymmetricBandCols) From(a SymmetricBand) {
75         if t.N != a.N {
76                 panic("blas64: mismatched dimension")
77         }
78         if t.K != a.K {
79                 panic("blas64: mismatched bandwidth")
80         }
81         if a.Stride < a.K+1 {
82                 panic("blas64: short stride for source")
83         }
84         if t.Stride < t.K+1 {
85                 panic("blas64: short stride for destination")
86         }
87         if t.Uplo != a.Uplo {
88                 panic("blas64: mismatched BLAS uplo")
89         }
90         dst := BandCols{
91                 Rows: t.N, Cols: t.N,
92                 Stride: t.Stride,
93                 Data:   t.Data,
94         }
95         src := Band{
96                 Rows: a.N, Cols: a.N,
97                 Stride: a.Stride,
98                 Data:   a.Data,
99         }
100         switch a.Uplo {
101         default:
102                 panic("blas64: bad BLAS uplo")
103         case blas.Upper:
104                 dst.KU = t.K
105                 src.KU = a.K
106         case blas.Lower:
107                 dst.KL = t.K
108                 src.KL = a.K
109         }
110         dst.From(src)
111 }
112
113 // From fills the receiver with elements from a. The receiver
114 // must have the same dimensions, bandwidth and uplo as a and
115 // have adequate backing data storage.
116 func (t SymmetricBand) From(a SymmetricBandCols) {
117         if t.N != a.N {
118                 panic("blas64: mismatched dimension")
119         }
120         if t.K != a.K {
121                 panic("blas64: mismatched bandwidth")
122         }
123         if a.Stride < a.K+1 {
124                 panic("blas64: short stride for source")
125         }
126         if t.Stride < t.K+1 {
127                 panic("blas64: short stride for destination")
128         }
129         if t.Uplo != a.Uplo {
130                 panic("blas64: mismatched BLAS uplo")
131         }
132         dst := Band{
133                 Rows: t.N, Cols: t.N,
134                 Stride: t.Stride,
135                 Data:   t.Data,
136         }
137         src := BandCols{
138                 Rows: a.N, Cols: a.N,
139                 Stride: a.Stride,
140                 Data:   a.Data,
141         }
142         switch a.Uplo {
143         default:
144                 panic("blas64: bad BLAS uplo")
145         case blas.Upper:
146                 dst.KU = t.K
147                 src.KU = a.K
148         case blas.Lower:
149                 dst.KL = t.K
150                 src.KL = a.K
151         }
152         dst.From(src)
153 }