OSDN Git Service

new repo
[bytom/vapor.git] / vendor / gonum.org / v1 / gonum / blas / cblas64 / cblas64.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 cblas64
6
7 import (
8         "gonum.org/v1/gonum/blas"
9         "gonum.org/v1/gonum/blas/gonum"
10 )
11
12 var cblas64 blas.Complex64 = gonum.Implementation{}
13
14 // Use sets the BLAS complex64 implementation to be used by subsequent BLAS calls.
15 // The default implementation is cgo.Implementation.
16 func Use(b blas.Complex64) {
17         cblas64 = b
18 }
19
20 // Implementation returns the current BLAS complex64 implementation.
21 //
22 // Implementation allows direct calls to the current the BLAS complex64 implementation
23 // giving finer control of parameters.
24 func Implementation() blas.Complex64 {
25         return cblas64
26 }
27
28 // Vector represents a vector with an associated element increment.
29 type Vector struct {
30         Inc  int
31         Data []complex64
32 }
33
34 // General represents a matrix using the conventional storage scheme.
35 type General struct {
36         Rows, Cols int
37         Stride     int
38         Data       []complex64
39 }
40
41 // Band represents a band matrix using the band storage scheme.
42 type Band struct {
43         Rows, Cols int
44         KL, KU     int
45         Stride     int
46         Data       []complex64
47 }
48
49 // Triangular represents a triangular matrix using the conventional storage scheme.
50 type Triangular struct {
51         N      int
52         Stride int
53         Data   []complex64
54         Uplo   blas.Uplo
55         Diag   blas.Diag
56 }
57
58 // TriangularBand represents a triangular matrix using the band storage scheme.
59 type TriangularBand struct {
60         N, K   int
61         Stride int
62         Data   []complex64
63         Uplo   blas.Uplo
64         Diag   blas.Diag
65 }
66
67 // TriangularPacked represents a triangular matrix using the packed storage scheme.
68 type TriangularPacked struct {
69         N    int
70         Data []complex64
71         Uplo blas.Uplo
72         Diag blas.Diag
73 }
74
75 // Symmetric represents a symmetric matrix using the conventional storage scheme.
76 type Symmetric struct {
77         N      int
78         Stride int
79         Data   []complex64
80         Uplo   blas.Uplo
81 }
82
83 // SymmetricBand represents a symmetric matrix using the band storage scheme.
84 type SymmetricBand struct {
85         N, K   int
86         Stride int
87         Data   []complex64
88         Uplo   blas.Uplo
89 }
90
91 // SymmetricPacked represents a symmetric matrix using the packed storage scheme.
92 type SymmetricPacked struct {
93         N    int
94         Data []complex64
95         Uplo blas.Uplo
96 }
97
98 // Hermitian represents an Hermitian matrix using the conventional storage scheme.
99 type Hermitian Symmetric
100
101 // HermitianBand represents an Hermitian matrix using the band storage scheme.
102 type HermitianBand SymmetricBand
103
104 // HermitianPacked represents an Hermitian matrix using the packed storage scheme.
105 type HermitianPacked SymmetricPacked
106
107 // Level 1
108
109 const negInc = "cblas64: negative vector increment"
110
111 // Dotu computes the dot product of the two vectors without
112 // complex conjugation:
113 //  x^T * y
114 func Dotu(n int, x, y Vector) complex64 {
115         return cblas64.Cdotu(n, x.Data, x.Inc, y.Data, y.Inc)
116 }
117
118 // Dotc computes the dot product of the two vectors with
119 // complex conjugation:
120 //  x^H * y.
121 func Dotc(n int, x, y Vector) complex64 {
122         return cblas64.Cdotc(n, x.Data, x.Inc, y.Data, y.Inc)
123 }
124
125 // Nrm2 computes the Euclidean norm of the vector x:
126 //  sqrt(\sum_i x[i] * x[i]).
127 //
128 // Nrm2 will panic if the vector increment is negative.
129 func Nrm2(n int, x Vector) float32 {
130         if x.Inc < 0 {
131                 panic(negInc)
132         }
133         return cblas64.Scnrm2(n, x.Data, x.Inc)
134 }
135
136 // Asum computes the sum of magnitudes of the real and imaginary parts of
137 // elements of the vector x:
138 //  \sum_i (|Re x[i]| + |Im x[i]|).
139 //
140 // Asum will panic if the vector increment is negative.
141 func Asum(n int, x Vector) float32 {
142         if x.Inc < 0 {
143                 panic(negInc)
144         }
145         return cblas64.Scasum(n, x.Data, x.Inc)
146 }
147
148 // Iamax returns the index of an element of x with the largest sum of
149 // magnitudes of the real and imaginary parts (|Re x[i]|+|Im x[i]|).
150 // If there are multiple such indices, the earliest is returned.
151 //
152 // Iamax returns -1 if n == 0.
153 //
154 // Iamax will panic if the vector increment is negative.
155 func Iamax(n int, x Vector) int {
156         if x.Inc < 0 {
157                 panic(negInc)
158         }
159         return cblas64.Icamax(n, x.Data, x.Inc)
160 }
161
162 // Swap exchanges the elements of two vectors:
163 //  x[i], y[i] = y[i], x[i] for all i.
164 func Swap(n int, x, y Vector) {
165         cblas64.Cswap(n, x.Data, x.Inc, y.Data, y.Inc)
166 }
167
168 // Copy copies the elements of x into the elements of y:
169 //  y[i] = x[i] for all i.
170 func Copy(n int, x, y Vector) {
171         cblas64.Ccopy(n, x.Data, x.Inc, y.Data, y.Inc)
172 }
173
174 // Axpy computes
175 //  y = alpha * x + y,
176 // where x and y are vectors, and alpha is a scalar.
177 func Axpy(n int, alpha complex64, x, y Vector) {
178         cblas64.Caxpy(n, alpha, x.Data, x.Inc, y.Data, y.Inc)
179 }
180
181 // Scal computes
182 //  x = alpha * x,
183 // where x is a vector, and alpha is a scalar.
184 //
185 // Scal will panic if the vector increment is negative.
186 func Scal(n int, alpha complex64, x Vector) {
187         if x.Inc < 0 {
188                 panic(negInc)
189         }
190         cblas64.Cscal(n, alpha, x.Data, x.Inc)
191 }
192
193 // Dscal computes
194 //  x = alpha * x,
195 // where x is a vector, and alpha is a real scalar.
196 //
197 // Dscal will panic if the vector increment is negative.
198 func Dscal(n int, alpha float32, x Vector) {
199         if x.Inc < 0 {
200                 panic(negInc)
201         }
202         cblas64.Csscal(n, alpha, x.Data, x.Inc)
203 }
204
205 // Level 2
206
207 // Gemv computes
208 //  y = alpha * A * x + beta * y,   if t == blas.NoTrans,
209 //  y = alpha * A^T * x + beta * y, if t == blas.Trans,
210 //  y = alpha * A^H * x + beta * y, if t == blas.ConjTrans,
211 // where A is an m×n dense matrix, x and y are vectors, and alpha and beta are
212 // scalars.
213 func Gemv(t blas.Transpose, alpha complex64, a General, x Vector, beta complex64, y Vector) {
214         cblas64.Cgemv(t, a.Rows, a.Cols, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc)
215 }
216
217 // Gbmv computes
218 //  y = alpha * A * x + beta * y,   if t == blas.NoTrans,
219 //  y = alpha * A^T * x + beta * y, if t == blas.Trans,
220 //  y = alpha * A^H * x + beta * y, if t == blas.ConjTrans,
221 // where A is an m×n band matrix, x and y are vectors, and alpha and beta are
222 // scalars.
223 func Gbmv(t blas.Transpose, alpha complex64, a Band, x Vector, beta complex64, y Vector) {
224         cblas64.Cgbmv(t, a.Rows, a.Cols, a.KL, a.KU, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc)
225 }
226
227 // Trmv computes
228 //  x = A * x,   if t == blas.NoTrans,
229 //  x = A^T * x, if t == blas.Trans,
230 //  x = A^H * x, if t == blas.ConjTrans,
231 // where A is an n×n triangular matrix, and x is a vector.
232 func Trmv(t blas.Transpose, a Triangular, x Vector) {
233         cblas64.Ctrmv(a.Uplo, t, a.Diag, a.N, a.Data, a.Stride, x.Data, x.Inc)
234 }
235
236 // Tbmv computes
237 //  x = A * x,   if t == blas.NoTrans,
238 //  x = A^T * x, if t == blas.Trans,
239 //  x = A^H * x, if t == blas.ConjTrans,
240 // where A is an n×n triangular band matrix, and x is a vector.
241 func Tbmv(t blas.Transpose, a TriangularBand, x Vector) {
242         cblas64.Ctbmv(a.Uplo, t, a.Diag, a.N, a.K, a.Data, a.Stride, x.Data, x.Inc)
243 }
244
245 // Tpmv computes
246 //  x = A * x,   if t == blas.NoTrans,
247 //  x = A^T * x, if t == blas.Trans,
248 //  x = A^H * x, if t == blas.ConjTrans,
249 // where A is an n×n triangular matrix in packed format, and x is a vector.
250 func Tpmv(t blas.Transpose, a TriangularPacked, x Vector) {
251         cblas64.Ctpmv(a.Uplo, t, a.Diag, a.N, a.Data, x.Data, x.Inc)
252 }
253
254 // Trsv solves
255 //  A * x = b,   if t == blas.NoTrans,
256 //  A^T * x = b, if t == blas.Trans,
257 //  A^H * x = b, if t == blas.ConjTrans,
258 // where A is an n×n triangular matrix and x is a vector.
259 //
260 // At entry to the function, x contains the values of b, and the result is
261 // stored in-place into x.
262 //
263 // No test for singularity or near-singularity is included in this
264 // routine. Such tests must be performed before calling this routine.
265 func Trsv(t blas.Transpose, a Triangular, x Vector) {
266         cblas64.Ctrsv(a.Uplo, t, a.Diag, a.N, a.Data, a.Stride, x.Data, x.Inc)
267 }
268
269 // Tbsv solves
270 //  A * x = b,   if t == blas.NoTrans,
271 //  A^T * x = b, if t == blas.Trans,
272 //  A^H * x = b, if t == blas.ConjTrans,
273 // where A is an n×n triangular band matrix, and x is a vector.
274 //
275 // At entry to the function, x contains the values of b, and the result is
276 // stored in-place into x.
277 //
278 // No test for singularity or near-singularity is included in this
279 // routine. Such tests must be performed before calling this routine.
280 func Tbsv(t blas.Transpose, a TriangularBand, x Vector) {
281         cblas64.Ctbsv(a.Uplo, t, a.Diag, a.N, a.K, a.Data, a.Stride, x.Data, x.Inc)
282 }
283
284 // Tpsv solves
285 //  A * x = b,   if t == blas.NoTrans,
286 //  A^T * x = b, if t == blas.Trans,
287 //  A^H * x = b, if t == blas.ConjTrans,
288 // where A is an n×n triangular matrix in packed format and x is a vector.
289 //
290 // At entry to the function, x contains the values of b, and the result is
291 // stored in-place into x.
292 //
293 // No test for singularity or near-singularity is included in this
294 // routine. Such tests must be performed before calling this routine.
295 func Tpsv(t blas.Transpose, a TriangularPacked, x Vector) {
296         cblas64.Ctpsv(a.Uplo, t, a.Diag, a.N, a.Data, x.Data, x.Inc)
297 }
298
299 // Hemv computes
300 //  y = alpha * A * x + beta * y,
301 // where A is an n×n Hermitian matrix, x and y are vectors, and alpha and
302 // beta are scalars.
303 func Hemv(alpha complex64, a Hermitian, x Vector, beta complex64, y Vector) {
304         cblas64.Chemv(a.Uplo, a.N, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc)
305 }
306
307 // Hbmv performs
308 //  y = alpha * A * x + beta * y,
309 // where A is an n×n Hermitian band matrix, x and y are vectors, and alpha
310 // and beta are scalars.
311 func Hbmv(alpha complex64, a HermitianBand, x Vector, beta complex64, y Vector) {
312         cblas64.Chbmv(a.Uplo, a.N, a.K, alpha, a.Data, a.Stride, x.Data, x.Inc, beta, y.Data, y.Inc)
313 }
314
315 // Hpmv performs
316 //  y = alpha * A * x + beta * y,
317 // where A is an n×n Hermitian matrix in packed format, x and y are vectors,
318 // and alpha and beta are scalars.
319 func Hpmv(alpha complex64, a HermitianPacked, x Vector, beta complex64, y Vector) {
320         cblas64.Chpmv(a.Uplo, a.N, alpha, a.Data, x.Data, x.Inc, beta, y.Data, y.Inc)
321 }
322
323 // Geru performs a rank-1 update
324 //  A += alpha * x * y^T,
325 // where A is an m×n dense matrix, x and y are vectors, and alpha is a scalar.
326 func Geru(alpha complex64, x, y Vector, a General) {
327         cblas64.Cgeru(a.Rows, a.Cols, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride)
328 }
329
330 // Gerc performs a rank-1 update
331 //  A += alpha * x * y^H,
332 // where A is an m×n dense matrix, x and y are vectors, and alpha is a scalar.
333 func Gerc(alpha complex64, x, y Vector, a General) {
334         cblas64.Cgerc(a.Rows, a.Cols, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride)
335 }
336
337 // Her performs a rank-1 update
338 //  A += alpha * x * y^T,
339 // where A is an m×n Hermitian matrix, x and y are vectors, and alpha is a scalar.
340 func Her(alpha float32, x Vector, a Hermitian) {
341         cblas64.Cher(a.Uplo, a.N, alpha, x.Data, x.Inc, a.Data, a.Stride)
342 }
343
344 // Hpr performs a rank-1 update
345 //  A += alpha * x * x^H,
346 // where A is an n×n Hermitian matrix in packed format, x is a vector, and
347 // alpha is a scalar.
348 func Hpr(alpha float32, x Vector, a HermitianPacked) {
349         cblas64.Chpr(a.Uplo, a.N, alpha, x.Data, x.Inc, a.Data)
350 }
351
352 // Her2 performs a rank-2 update
353 //  A += alpha * x * y^H + conj(alpha) * y * x^H,
354 // where A is an n×n Hermitian matrix, x and y are vectors, and alpha is a scalar.
355 func Her2(alpha complex64, x, y Vector, a Hermitian) {
356         cblas64.Cher2(a.Uplo, a.N, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data, a.Stride)
357 }
358
359 // Hpr2 performs a rank-2 update
360 //  A += alpha * x * y^H + conj(alpha) * y * x^H,
361 // where A is an n×n Hermitian matrix in packed format, x and y are vectors,
362 // and alpha is a scalar.
363 func Hpr2(alpha complex64, x, y Vector, a HermitianPacked) {
364         cblas64.Chpr2(a.Uplo, a.N, alpha, x.Data, x.Inc, y.Data, y.Inc, a.Data)
365 }
366
367 // Level 3
368
369 // Gemm computes
370 //  C = alpha * A * B + beta * C,
371 // where A, B, and C are dense matrices, and alpha and beta are scalars.
372 // tA and tB specify whether A or B are transposed or conjugated.
373 func Gemm(tA, tB blas.Transpose, alpha complex64, a, b General, beta complex64, c General) {
374         var m, n, k int
375         if tA == blas.NoTrans {
376                 m, k = a.Rows, a.Cols
377         } else {
378                 m, k = a.Cols, a.Rows
379         }
380         if tB == blas.NoTrans {
381                 n = b.Cols
382         } else {
383                 n = b.Rows
384         }
385         cblas64.Cgemm(tA, tB, m, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride)
386 }
387
388 // Symm performs
389 //  C = alpha * A * B + beta * C, if s == blas.Left,
390 //  C = alpha * B * A + beta * C, if s == blas.Right,
391 // where A is an n×n or m×m symmetric matrix, B and C are m×n matrices, and
392 // alpha and beta are scalars.
393 func Symm(s blas.Side, alpha complex64, a Symmetric, b General, beta complex64, c General) {
394         var m, n int
395         if s == blas.Left {
396                 m, n = a.N, b.Cols
397         } else {
398                 m, n = b.Rows, a.N
399         }
400         cblas64.Csymm(s, a.Uplo, m, n, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride)
401 }
402
403 // Syrk performs a symmetric rank-k update
404 //  C = alpha * A * A^T + beta * C, if t == blas.NoTrans,
405 //  C = alpha * A^T * A + beta * C, if t == blas.Trans,
406 // where C is an n×n symmetric matrix, A is an n×k matrix if t == blas.NoTrans
407 // and a k×n matrix otherwise, and alpha and beta are scalars.
408 func Syrk(t blas.Transpose, alpha complex64, a General, beta complex64, c Symmetric) {
409         var n, k int
410         if t == blas.NoTrans {
411                 n, k = a.Rows, a.Cols
412         } else {
413                 n, k = a.Cols, a.Rows
414         }
415         cblas64.Csyrk(c.Uplo, t, n, k, alpha, a.Data, a.Stride, beta, c.Data, c.Stride)
416 }
417
418 // Syr2k performs a symmetric rank-2k update
419 //  C = alpha * A * B^T + alpha * B * A^T + beta * C, if t == blas.NoTrans,
420 //  C = alpha * A^T * B + alpha * B^T * A + beta * C, if t == blas.Trans,
421 // where C is an n×n symmetric matrix, A and B are n×k matrices if
422 // t == blas.NoTrans and k×n otherwise, and alpha and beta are scalars.
423 func Syr2k(t blas.Transpose, alpha complex64, a, b General, beta complex64, c Symmetric) {
424         var n, k int
425         if t == blas.NoTrans {
426                 n, k = a.Rows, a.Cols
427         } else {
428                 n, k = a.Cols, a.Rows
429         }
430         cblas64.Csyr2k(c.Uplo, t, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride)
431 }
432
433 // Trmm performs
434 //  B = alpha * A * B,   if tA == blas.NoTrans and s == blas.Left,
435 //  B = alpha * A^T * B, if tA == blas.Trans and s == blas.Left,
436 //  B = alpha * A^H * B, if tA == blas.ConjTrans and s == blas.Left,
437 //  B = alpha * B * A,   if tA == blas.NoTrans and s == blas.Right,
438 //  B = alpha * B * A^T, if tA == blas.Trans and s == blas.Right,
439 //  B = alpha * B * A^H, if tA == blas.ConjTrans and s == blas.Right,
440 // where A is an n×n or m×m triangular matrix, B is an m×n matrix, and alpha is
441 // a scalar.
442 func Trmm(s blas.Side, tA blas.Transpose, alpha complex64, a Triangular, b General) {
443         cblas64.Ctrmm(s, a.Uplo, tA, a.Diag, b.Rows, b.Cols, alpha, a.Data, a.Stride, b.Data, b.Stride)
444 }
445
446 // Trsm solves
447 //  A * X = alpha * B,   if tA == blas.NoTrans and s == blas.Left,
448 //  A^T * X = alpha * B, if tA == blas.Trans and s == blas.Left,
449 //  A^H * X = alpha * B, if tA == blas.ConjTrans and s == blas.Left,
450 //  X * A = alpha * B,   if tA == blas.NoTrans and s == blas.Right,
451 //  X * A^T = alpha * B, if tA == blas.Trans and s == blas.Right,
452 //  X * A^H = alpha * B, if tA == blas.ConjTrans and s == blas.Right,
453 // where A is an n×n or m×m triangular matrix, X and B are m×n matrices, and
454 // alpha is a scalar.
455 //
456 // At entry to the function, b contains the values of B, and the result is
457 // stored in-place into b.
458 //
459 // No check is made that A is invertible.
460 func Trsm(s blas.Side, tA blas.Transpose, alpha complex64, a Triangular, b General) {
461         cblas64.Ctrsm(s, a.Uplo, tA, a.Diag, b.Rows, b.Cols, alpha, a.Data, a.Stride, b.Data, b.Stride)
462 }
463
464 // Hemm performs
465 //  C = alpha * A * B + beta * C, if s == blas.Left,
466 //  C = alpha * B * A + beta * C, if s == blas.Right,
467 // where A is an n×n or m×m Hermitian matrix, B and C are m×n matrices, and
468 // alpha and beta are scalars.
469 func Hemm(s blas.Side, alpha complex64, a Hermitian, b General, beta complex64, c General) {
470         var m, n int
471         if s == blas.Left {
472                 m, n = a.N, b.Cols
473         } else {
474                 m, n = b.Rows, a.N
475         }
476         cblas64.Chemm(s, a.Uplo, m, n, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride)
477 }
478
479 // Herk performs the Hermitian rank-k update
480 //  C = alpha * A * A^H + beta*C, if t == blas.NoTrans,
481 //  C = alpha * A^H * A + beta*C, if t == blas.ConjTrans,
482 // where C is an n×n Hermitian matrix, A is an n×k matrix if t == blas.NoTrans
483 // and a k×n matrix otherwise, and alpha and beta are scalars.
484 func Herk(t blas.Transpose, alpha float32, a General, beta float32, c Hermitian) {
485         var n, k int
486         if t == blas.NoTrans {
487                 n, k = a.Rows, a.Cols
488         } else {
489                 n, k = a.Cols, a.Rows
490         }
491         cblas64.Cherk(c.Uplo, t, n, k, alpha, a.Data, a.Stride, beta, c.Data, c.Stride)
492 }
493
494 // Her2k performs the Hermitian rank-2k update
495 //  C = alpha * A * B^H + conj(alpha) * B * A^H + beta * C, if t == blas.NoTrans,
496 //  C = alpha * A^H * B + conj(alpha) * B^H * A + beta * C, if t == blas.ConjTrans,
497 // where C is an n×n Hermitian matrix, A and B are n×k matrices if t == NoTrans
498 // and k×n matrices otherwise, and alpha and beta are scalars.
499 func Her2k(t blas.Transpose, alpha complex64, a, b General, beta float32, c Hermitian) {
500         var n, k int
501         if t == blas.NoTrans {
502                 n, k = a.Rows, a.Cols
503         } else {
504                 n, k = a.Cols, a.Rows
505         }
506         cblas64.Cher2k(c.Uplo, t, n, k, alpha, a.Data, a.Stride, b.Data, b.Stride, beta, c.Data, c.Stride)
507 }