-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlas.hpp
2784 lines (2761 loc) · 64.9 KB
/
Blas.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef BLAS_HEADER
#define BLAS_HEADER
#include <cstring>
#include <cmath>
#include <algorithm>
/*!\class Blas
* \brief A template class containing BLAS routines.
* Blas contains the BLAS routines as static members.
* Any routine can be called using <tt>Blas<type>::routine(...)</tt>
* \tparam The template type \c real is meant to be double, but can be any floating point type.
*/
template<class real> class Blas
{
private:
// constants
static constexpr real ZERO = real(0.0);//!< A constant zero (0.0) value
static constexpr real ONE = real(1.0);//!< A constant one (1.0) value
public:
// BLAS SRC (alphabetically)
/*! §dasum
*
* §dasum takes the sum of the absolute values.
* \param[in] n number of elements in input vector(s).
* \param[in] dx an array, dimension $(1+(\{n}-1)|\{incx}|)$.
* \param[in] incx storage spacing between elements of §dx.
* \return The sum of §dx 's absolute values.
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date November 2017 */
static real dasum(int const n, real const* const dx, int const incx)
{
if (n<=0 || incx<=0)
{
return ZERO;
}
int i;
real dtemp = ZERO;
if (incx==1)
{
// code for increment equal to 1
// clean-up loop
int m = n%6;
if (m!=0)
{
for (i=0; i<m; i++)
{
dtemp += std::fabs(dx[i]);
}
if (n<6)
{
return dtemp;
}
}
for (i=m; i<n; i+=6)
{
dtemp += std::fabs(dx[i]) +std::fabs(dx[i+1])+std::fabs(dx[i+2])
+std::fabs(dx[i+3])+std::fabs(dx[i+4])+std::fabs(dx[i+5]);
}
}
else
{
// code for increment not equal to 1
int nincx = n*incx;
for (i=0; i<nincx; i+=incx)
{
dtemp += std::fabs(dx[i]);
}
}
return dtemp;
}
/*! §daxpy
*
* §daxpy constant times a vector plus a vector.
* Uses unrolled loops for increments equal to one.
* \param[in] n number of elements in input vector(s)
* \param[in] da On entry, §da specifies the scalar $\alpha$.
* \param[in] dx an array, dimension $(1 + (\{n}-1)|\{incx}|)$
* \param[in] incx storage spacing between elements of §dx
* \param[in,out] dy an array, dimension $(1 + (\{n}-1)|\{incy}|)$
* \param[in] incy storage spacing between elements of §dy
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date November 2017 */
static void daxpy(int const n, real const da, real const* const dx, int const incx,
real* const dy, int const incy)
{
if (n<=0)
{
return;
}
if (da==ZERO)
{
return;
}
int i;
if (incx==1 && incy==1)
{
// code for both increments equal to 1
// clean-up loop
int m = n%4;
if (m!=0)
{
for (i=0; i<m; i++)
{
dy[i] = dy[i] + da*dx[i];
}
}
if (n<4)
{
return;
}
for (i=m; i<n; i+=4)
{
dy[i] += da*dx[i];
dy[i+1] += da*dx[i+1];
dy[i+2] += da*dx[i+2];
dy[i+3] += da*dx[i+3];
}
}
else
{
// code for unequal increments or equal increments not equal to 1
int ix = 0;
int iy = 0;
if (incx<0)
{
ix = (1-n)*incx;
}
if (incy<0)
{
iy = (1-n)*incy;
}
for (i=0; i<n; i++)
{
dy[iy] += da*dx[ix];
ix += incx;
iy += incy;
}
}
}
/*! §dcopy
*
* §dcopy copies a vector, §x, to a vector, §y.
* uses unrolled loops for increments equal to one.
* \param[in] n number of elements in input vector(s)
* \param[in] dx an array, dimension $(1 + (\{n}-1)|\{incx}|)$
* \param[in] incx storage spacing between elements of §dx
* \param[out] dy an array, dimension $(1 + (\{n}-1)|\{incy}|)$
* \param[in] incy storage spacing between elements of §dy
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date November 2017 */
static void dcopy(int const n, real const* const dx, int const incx, real* const dy,
int const incy)
{
if (n < 0)
{
return;
}
int i;
if (incx == 1 && incy == 1)
{
// code for both increments equal to 1
// clean-up loop
int m = n % 7;
if (m != 0)
{
for (i = 0; i < m; i++)
{
dy[i] = dx[i];
}
if (n < 7)
{
return;
}
}
for (i = m; i < n; i += 7)
{
dy[i] = dx[i];
dy[i+1] = dx[i+1];
dy[i+2] = dx[i+2];
dy[i+3] = dx[i+3];
dy[i+4] = dx[i+4];
dy[i+5] = dx[i+5];
dy[i+6] = dx[i+6];
}
} else
{
// code for unequal increments or equal increments not equal to 1
int ix = 0;
int iy = 0;
if (incx < 0)
{
ix = (-n + 1) * incx;
}
if (incy < 0)
{
iy = (-n + 1) * incy;
}
for (i = 0; i < n; i++)
{
dy[iy] = dx[ix];
ix += incx;
iy += incy;
}
}
}
/*! §ddot
*
* §ddot forms the dot product of two vectors.
* uses unrolled loops for increments equal to one.
* \param[in] n number of elements in input vector(s)
* \param[in] dx an array, dimension $(1 + (\{n}-1)|\{incx}|)$
* \param[in] incx storage spacing between elements of §dx
* \param[in] dy an array, dimension $(1 + (\{n}-1)|\{incy}|)$
* \param[in] incy storage spacing between elements of §dy
* \return The dot product of §dx and §dy
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date November 2017 */
static real ddot(int const n, real const* const dx, int const incx, real const* const dy,
int const incy)
{
if (n<=0)
{
return ZERO;
}
int i;
real dtemp = ZERO;
if (incx==1 && incy==1)
{
// code for both increments equal to 1
// clean-up loop
int m = n % 5;
if (m!=0)
{
for (i=0; i<m; i++)
{
dtemp += dx[i]*dy[i];
}
if (n<5)
{
return dtemp;
}
}
for (i=m; i<n; i+=5)
{
dtemp += dx[i]*dy[i] + dx[i+1]*dy[i+1] + dx[i+2]*dy[i+2]
+ dx[i+3]*dy[i+3] + dx[i+4]*dy[i+4];
}
}
else
{
// code for unequal increments or equal increments not equal to 1
int ix = 0;
int iy = 0;
if (incx<0)
{
ix = (-n+1)*incx;
}
if (incy<0)
{
iy = (-n+1)*incy;
}
for (i=0; i<n; i++)
{
dtemp += dx[ix]*dy[iy];
ix += incx;
iy += incy;
}
}
return dtemp;
}
/*! §dgemm
*
* §dgemm performs one of the matrix-matrix operations\n
* $C = \alpha\ op(A)op(B) + \beta C$,\n
* where $op(X)$ is one of\n
* $op(X) = X$ or $op(X) = X^T$,\n
* $\alpha$ and $\beta$ are scalars, and $A$, $B$ and $C$ are matrices,
* with $op(A)$ an §m by §k matrix, $op(B)$ a §k by §n matrix and §C an §m by §n matrix.
* \param[in] transa
* On entry, §transa specifies the form of $op(A)$ to be used in the matrix multiplication
* as follows:\n
* §transa = 'N' or 'n': $op(A)\equiv A$.\n
* §transa = 'T' or 't': $op(A)\equiv A^T$.\n
* §transa = 'C' or 'c': $op(A)\equiv A^T$.
*
* \param[in] transb
* On entry, §transb specifies the form of $op(B)$ to be used in the matrix multiplication
* as follows:\n
* §transb = 'N' or 'n': $op(B)\equiv B$.\n
* §transb = 'T' or 't': $op(B)\equiv B^T$.\n
* §transb = 'C' or 'c': $op(B)\equiv B^T$.
*
* \param[in] m
* On entry, §m specifies the number of rows of the matrix $op(A)$ and of the matrix §C.
* §m must be at least zero.
*
* \param[in] n
* On entry, §n specifies the number of columns of the matrix $op(B)$ and the number of
* columns of the matrix §C. §n must be at least zero.
*
* \param[in] k
* On entry, §k specifies the number of columns of the matrix $op(A)$ and the number of
* rows of the matrix $op(B)$. §k must be at least zero.
*
* \param[in] alpha On entry, §alpha specifies the scalar $\alpha$.
* \param[in] A
* an array of dimension (§lda, §ka), where §ka is §k when §transa = 'N' or 'n', and is §m
* otherwise.\n
* Before entry with §transa = 'N' or 'n', the leading §m by §k part of the array §A must
* contain the matrix $A$, otherwise the leading §k by §m part of the array §A must contain
* the matrix $A$.
*
* \param[in] lda
* On entry, §lda specifies the first dimension of §A as declared in the calling
* (sub)program.\n When §transa = 'N' or 'n' then §lda must be at least $\max(1,\{m})$,
* otherwise §lda must be at least $\max(1,\{k})$.
*
* \param[in] B
* an array of dimension (§ldb, §kb), where §kb is §n when §transb = 'N' or 'n', and is §k
* otherwise.\n Before entry with §transb = 'N' or 'n', the leading §k by §n part of the
* array §B must contain the matrix $B$, otherwise the leading §n by §k part of the array
* §B must contain the matrix $B$.
*
* \param[in] ldb
* On entry, §ldb specifies the first dimension of §B as declared in the calling
* (sub)program.\n When §transb = 'N' or 'n' then §ldb must be at least $\max(1,\{k})$,
* otherwise §ldb must be at least $\max(1,\{n})$.
*
* \param[in] beta
* On entry, §beta specifies the scalar $\beta$.
* When §beta is supplied as zero then §C need not be set on input.
*
* \param[in,out] C
* an array of dimension (§ldc, §n).\n
* Before entry, the leading §m by §n part of the array §C must contain the matrix $C$,
* except when §beta is zero, in which case §C need not be set on entry.\n
* On exit, the array §C is overwritten by the §m by §n matrix
* $\alpha\ op(A)op(B) + \beta C$.
*
* \param[in] ldc
* On entry, §ldc specifies the first dimension of §C as declared in the calling
* (sub)program. §ldc must be at least $\max(1,\{m})$.
*
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date December 2016
* \remark
* -- Written on 8-February-1989.\n
* Jack Dongarra, Argonne National Laboratory.\n
* Iain Duff, AERE Harwell.\n
* Jeremy Du Croz, Numerical Algorithms Group Ltd.\n
* Sven Hammarling, Numerical Algorithms Group Ltd. */
static void dgemm(char const* const transa, char const* const transb, int const m, int const n,
int const k, real const alpha, real const* const A, int const lda,
real const* const B, int const ldb, real const beta, real* const C,
int const ldc)
{
// Set nota and notb as true if A and B respectively are not transposed and set nrowa
// and nrowb as the number of rows and columns of A and the number of rows of B respectively.
char uptransa = toupper(transa[0]);
char uptransb = toupper(transb[0]);
bool nota = (uptransa == 'N');
bool notb = (uptransb == 'N');
int nrowa, nrowb;
if (nota)
{
nrowa = m;
} else
{
nrowa = k;
}
if (notb)
{
nrowb = k;
} else
{
nrowb = n;
}
// Test the input parameters.
int info = 0;
if (!nota && uptransa!='C' && uptransa!='T')
{
info = 1;
}
else if (!notb && uptransb!='C' && uptransb!='T')
{
info = 2;
}
else if (m < 0)
{
info = 3;
}
else if (n < 0)
{
info = 4;
}
else if (k < 0)
{
info = 5;
}
else if (lda < std::max(1, nrowa))
{
info = 8;
}
else if (ldb < std::max(1, nrowb))
{
info = 10;
}
else if (ldc < std::max(1, m))
{
info = 13;
}
if (info != 0)
{
xerbla("DGEMM", info);
return;
}
// Quick return if possible.
if (m==0 || n==0 || ((alpha==ZERO || k==0) && beta==ONE))
{
return;
}
// And if alpha==zero.
int i, j, l;
int acol, bcol, ccol;
if (alpha == ZERO)
{
if (beta == ZERO)
{
for (j = 0; j < n; j++)
{
ccol = ldc*j;
for (i = 0; i < m; i++)
{
C[i + ccol] = ZERO;
}
}
}
else
{
for (j = 0; j < n; j++)
{
ccol = ldc*j;
for (i = 0; i < m; i++)
{
C[i + ccol] *= beta;
}
}
}
return;
}
// Start the operations.
real temp;
if (notb)
{
if (nota)
{
// Form C = alpha*A*B + beta*C.
for (j = 0; j < n; j++)
{
ccol = ldc*j;
if (beta == ZERO)
{
for (i = 0; i < m; i++)
{
C[i + ccol] = ZERO;
}
}
else if (beta != ONE)
{
for (i = 0; i < m; i++)
{
C[i + ccol] *= beta;
}
}
bcol = ldb*j;
for (l = 0; l < k; l++)
{
acol = lda*l;
temp = alpha * B[l + bcol];
for (i = 0; i < m; i++)
{
C[i + ccol] += temp * A[i + acol];
}
}
}
}
else
{
// Form C = alpha * A^T * B + beta * C
for (j = 0; j < n; j++)
{
bcol = ldb*j;
ccol = ldc*j;
for (i = 0; i < m; i++)
{
acol = lda*i;
temp = ZERO;
for (l = 0; l < k; l++)
{
temp += A[l + acol] * B[l + bcol];
}
if (beta == ZERO)
{
C[i + ccol] = alpha*temp;
}
else
{
C[i + ccol] = alpha * temp + beta * C[i + ccol];
}
}
}
}
}
else
{
if (nota)
{
// Form C = alpha * A * B^T + beta * C
for (j = 0; j < n; j++)
{
ccol = ldc*j;
if (beta == ZERO)
{
for (i = 0; i < m; i++)
{
C[i + ccol] = ZERO;
}
}
else if (beta != ONE)
{
for (i = 0; i < m; i++)
{
C[i + ccol] *= beta;
}
}
for (l = 0; l < k; l++)
{
acol = lda*l;
bcol = ldb*l;
temp = alpha * B[j + bcol];
for (i = 0; i < m; i++)
{
C[i + ccol] += temp * A[i + acol];
}
}
}
}
else
{
// Form C = alpha * A^T * B^T + beta * C
for (j = 0; j < n; j++)
{
ccol = ldc*j;
for (i = 0; i < m; i++)
{
acol = lda*i;
temp = ZERO;
for (l = 0; l < k; l++)
{
temp += A[l + acol] * B[j + ldb * l];
}
if (beta == ZERO)
{
C[i + ccol] = alpha*temp;
}
else
{
C[i + ccol] = alpha * temp + beta * C[i + ccol];
}
}
}
}
}
}
/*! §dgemv
*
* §dgemv performs one of the matrix-vector operations\n
* $y = \alpha Ax + \beta y$, or $y = \alpha A^Tx + \beta y$,\n
* where $\alpha$ and $\beta$ are scalars, $x$ and $y$ are vectors and $A$ is an §m by §n
* matrix.
* \param[in] trans
* On entry, §trans specifies the operation to be performed as follows:\n
* §trans = 'N' or 'n': $y\equiv\alpha Ax + \beta y$.\n
* §trans = 'T' or 't': $y\equiv\alpha A^Tx + \beta y$.\n
* §trans = 'C' or 'c': $y\equiv\alpha A^Tx + \beta y$.
*
* \param[in] m
* specifies the number of rows of the matrix $A$. §m must be at least zero.
*
* \param[in] n
* specifies the number of columns of the matrix $A$. §n must be at least zero.
*
* \param[in] alpha specifies the scalar $\alpha$.
* \param[in] A
* an array of dimension (§lda, §n).\n
* Before entry, the leading §m by §n part of the array §A must contain the matrix of
* coefficients.
*
* \param[in] lda
* specifies the first dimension of §A as declared in the calling function.
* §lda must be at least $\max(1,\{m})$.
*
* \param[in] x
* an array of dimension at least $(1 + (\{n}-1)|\{incx}|)$ when §trans = 'N' or 'n' and at
* least $(1 + (\{m}-1)|\{incx}|)$ otherwise.\n
* Before entry, the incremented array §x must contain the vector $x$.
*
* \param[in] incx specifies the increment for the elements of §x. §incx must not be zero.
* \param[in] beta
* specifies the scalar $\beta$.\n
* When §beta is supplied as zero then §y need not be set on input.
*
* \param[in,out] y
* an array of dimension at least $(1 + (\{m}-1)|\{incy}|)$ when §trans = 'N' or 'n' and at
* least $(1 + (\{n}-1)|\{incy}|)$ otherwise.\n
* Before entry with §beta non-zero, the incremented array §y must contain the vector
* $y$.\n
* On exit, §y is overwritten by the updated vector $y$.
*
* \param[in] incy specifies the increment for the elements of §y. §incy must not be zero.
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date December 2016
* \remark
* The vector and matrix arguments are not referenced when §n = 0, or §m = 0.\n\n
* -- Written on 22-October-1986.\n
* Jack Dongarra, Argonne National Laboratory.\n
* Jeremy Du Croz, Nag Central Office.\n
* Sven Hammarling, Nag Central Office.\n
* Richard Hanson, Sandia National Labs. */
static void dgemv(char const* const trans, int const m, int const n, real const alpha,
real const* const A, int const lda, real const* const x, int const incx,
real const beta, real* const y, int const incy)
{
// Test the input parameters.
int info = 0;
char uptrans = toupper(trans[0]);
if (uptrans!='N' && uptrans!='T' && uptrans!='C')
{
info = 1;
}
else if (m < 0)
{
info = 2;
}
else if (n < 0)
{
info = 3;
}
else if (lda < std::max(1, m))
{
info = 6;
}
else if (incx == 0)
{
info = 8;
}
else if (incy == 0)
{
info = 11;
}
if (info != 0)
{
xerbla("DGEMV", info);
return;
}
// Quick return if possible.
if (m==0 || n==0 || (alpha==ZERO && beta==ONE))
{
return;
}
// Set lenx and leny, the lengths of the vectors x and y,
// and set up the start points in x and y.
int kx, ky, lenx, leny;
if (uptrans=='N')
{
lenx = n;
leny = m;
}
else
{
lenx = m;
leny = n;
}
if (incx > 0)
{
kx = 0;
} else
{
kx = -(lenx-1) * incx;
}
if (incy > 0)
{
ky = 0;
}
else
{
ky = -(leny-1) * incy;
}
// Start the operations. In this version the elements of A are accessed sequentially with
// one pass through A.
int i, iy;
// First form y := beta*y.
if (beta != ONE)
{
if (incy == 1)
{
if (beta == ZERO)
{
for (i = 0; i < leny; i++)
{
y[i] = ZERO;
}
}
else
{
for (i = 0; i < leny; i++)
{
y[i] *= beta;
}
}
}
else
{
iy = ky;
if (beta == ZERO)
{
for (i = 0; i < leny; i++)
{
y[iy] = ZERO;
iy += incy;
}
}
else
{
for (i = 0; i < leny; i++)
{
y[iy] *= beta;
iy += incy;
}
}
}
}
if (alpha == ZERO)
{
return;
}
int ix, j, jx, jy, colj;
real temp;
if (uptrans == 'N')
{
// Form y := alpha*A*x + y.
jx = kx;
if (incy == 1)
{
for (j = 0; j < n; j++)
{
colj = lda*j;
temp = alpha * x[jx];
for (i = 0; i < m; i++)
{
y[i] += temp * A[i + colj];
}
jx += incx;
}
}
else
{
for (j = 0; j < n; j++)
{
colj = lda*j;
temp = alpha * x[jx];
iy = ky;
for (i = 0; i < m; i++)
{
y[iy] += temp * A[i + colj];
iy += incy;
}
jx += incx;
}
}
}
else
{
// Form y : = alpha*A^T*x + y.
jy = ky;
if (incx == 1)
{
for (j = 0; j < n; j++)
{
colj = lda*j;
temp = ZERO;
for (i = 0; i < m; i++)
{
temp += A[i + colj] * x[i];
}
y[jy] += alpha*temp;
jy += incy;
}
}
else
{
for (j = 0; j < n; j++)
{
colj = lda*j;
temp = ZERO;
ix = kx;
for (i = 0; i < m; i++)
{
temp += A[i + colj] * x[ix];
ix += incx;
}
y[jy] += alpha*temp;
jy += incy;
}
}
}
}
/*! §dger
*
* §dger performs the rank 1 operation\n
* $A = \alpha xy^T + A$,\n
* where $\alpha$ is a scalar, $x$ is an §m element vector,
* $y$ is an §n element vector and $A$ is an §m by §n matrix.
* \param[in] m
* On entry, §m specifies the number of rows of the matrix $A$. §m must be at least zero.
*
* \param[in] n
* On entry, §n specifies the number of columns of the matrix $A$.
* §n must be at least zero.
*
* \param[in] alpha On entry, §alpha specifies the scalar $\alpha$.
* \param[in] x
* an array of dimension at least $(1 + (\{m}-1)|\{incx}|)$.\n
* Before entry, the incremented array §x must contain the m element vector $x$.
*
* \param[in] incx
* On entry, §incx specifies the increment for the elements of §x. §incx must not be zero.
*
* \param[in] y
* an array of dimension at least $(1 + (\{n}-1)|\{incy}|)$.\n
* Before entry, the incremented array §y must contain the §n element vector $y$.
*
* \param[in] incy
* On entry, §incy specifies the increment for the elements of §y. §incy must not be zero.
*
* \param[in,out] A
* an array of dimension (§lda, §n).\n
* Before entry, the leading §m by §n part of the array §A must contain the matrix of
* coefficients.\n
* On exit, §A is overwritten by the updated matrix.
*
* \param[in] lda
* On entry, §lda specifies the first dimension of §A as declared in the calling
* (sub)program. §lda must be at least $\max(1,\{m})$.
*
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.
* \date December 2016
* \remark
* The vector and matrix arguments are not referenced when §n = 0, or §m = 0.\n\n
* -- Written on 22-October-1986.\n
* Jack Dongarra, Argonne National Laboratory.\n
* Jeremy Du Croz, Nag Central Office.\n
* Sven Hammarling, Nag Central Office.\n
* Richard Hanson, Sandia National Labs. */
static void dger(int const m, int const n, real const alpha, real const* const x,
int const incx, real const* const y, int const incy, real* const A,
int const lda)
{
real temp;
// Test the input parameters.
int info = 0;
if (m < 0)
{
info = 1;
}
else if (n < 0)
{
info = 2;
}
else if (incx == 0)
{
info = 5;
}
else if (incy == 0)
{
info = 7;
}
else if (lda < std::max(1, m))
{
info = 9;
}
if (info != 0)
{
xerbla("DGER", info);
return;
}
// Quick return if possible.
if (m==0 || n==0 || alpha==ZERO)
{
return;
}
// Start the operations.
// In this version the elements of A are accessed sequentially with one pass through A.
int i, j, jy, colj;
if (incy > 0)
{
jy = 0;
}
else
{
jy = -(n-1) * incy;
}
if (incx == 1)
{
for (j = 0; j < n; j++)
{
if (y[jy] != ZERO)
{
colj = lda*j;
temp = alpha * y[jy];
for (i = 0; i < m; i++)
{
A[i + colj] += x[i] * temp;
}
}
jy += incy;
}
}
else
{
int ix, kx;
if (incx > 0)
{
kx = 0;
}
else
{
kx = -(m-1) * incx;
}
for (j = 0; j < n; j++)
{
if (y[jy] != ZERO)
{
colj = lda*j;
temp = alpha * y[jy];
ix = kx;
for (i = 0; i < m; i++)
{
A[i + colj] += x[ix] * temp;
ix += incx;
}
}
jy += incy;
}
}
}
/*! §dnrm2
*
* §dnrm2 returns the euclidean norm of a vector:\n
* $\sqrt{x^T*x}$
* \param[in] n number of elements in input vector(s)
* \param[in] x an array, dimension $(1 + (\{n}-1)|\{incx}|)$
* \param[in] incx storage spacing between elements of §x
* \return The Euclidean norm of §x.
* \authors Univ.of Tennessee
* \authors Univ.of California Berkeley
* \authors Univ.of Colorado Denver
* \authors NAG Ltd.