-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic.ijs
3826 lines (3575 loc) · 201 KB
/
basic.ijs
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
NB. Basic linear algebra operations
NB.
NB. trsmxxxx Solve linear monomial matrix equation
NB. with triangular matrix
NB.
NB. testbasicger Test rank 1 operations with general
NB. matrix
NB. testbasicher Test rank 1 operations with Hermitian
NB. (symmetric) matrix
NB. testbasicr Test rank 1 operations
NB.
NB. testbasicher2 Test rank 2 operations with Hermitian
NB. (symmetric) matrix
NB. testbasicr2 Test rank 2 operations
NB.
NB. testbasicsyrk Test rank k operations with symmetric
NB. matrix
NB. testbasicherk Test rank k operations with Hermitian
NB. matrix
NB. testbasicrk Test rank k operations
NB.
NB. testbasicsyr2k Test rank 2k operations with symmetric
NB. matrix
NB. testbasicher2k Test rank 2k operations with Hermitian
NB. matrix
NB. testbasicr2k Test rank 2k operations
NB.
NB. testbasicgemv Test matrix-vector operations with
NB. general matrix
NB. testbasichemv Test matrix-vector operations with
NB. Hermitian (symmetric) matrix
NB. testbasictrmv Test matrix-vector operations with
NB. triangular matrix
NB. testbasicmv Test matrix-vector operations
NB.
NB. testbasicgemm Test matrix-matrix operations with
NB. general matrix
NB. testbasicgemmt Test matrix-matrix operations which
NB. update result in triangular part only, by
NB. general matrices
NB. testbasicsymm Test matrix-matrix operations with
NB. symmetric matrix
NB. testbasichemm Test matrix-matrix operations with
NB. Hermitian matrix
NB. testbasictrmm Test matrix-matrix operations with
NB. triangular matrix
NB. testbasicmm Test matrix-matrix operations
NB.
NB. testbasictrsv Test equation solver with triangular
NB. matrix
NB. testbasicsv Test equation solver
NB.
NB. testbasictrsm Test matrix equation solver with
NB. triangular matrix
NB. testbasicsm Test matrix equation solver
NB.
NB. testbasic Adv. to make verb to test basic
NB. operations all levels
NB.
NB. Copyright 2010,2011,2013,2017,2018,2020,2021,2023,2024,
NB. 2025 Igor Zhuravlov
NB.
NB. This file is part of mt
NB.
NB. mt is free software: you can redistribute it and/or
NB. modify it under the terms of the GNU Lesser General
NB. Public License as published by the Free Software
NB. Foundation, either version 3 of the License, or (at your
NB. option) any later version.
NB.
NB. mt is distributed in the hope that it will be useful, but
NB. WITHOUT ANY WARRANTY; without even the implied warranty
NB. of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
NB. See the GNU Lesser General Public License for more
NB. details.
NB.
NB. You should have received a copy of the GNU Lesser General
NB. Public License along with mt. If not, see
NB. <http://www.gnu.org/licenses/>.
NB. =========================================================
NB. Concepts
NB.
NB. Conventions:
NB. 1) test suite here is aimed to benchmark BLAS and BLIS
NB. subroutines
NB. 2) ZCHKx is not tested with real alpha and beta, just as
NB. BLAS counterparts do
NB. =========================================================
NB. Configuration
coclass 'mt'
NB. =========================================================
NB. Local definitions
NB. ---------------------------------------------------------
NB. extract
NB.
NB. Description:
NB. Extract evenly spaced elements from vector
NB.
NB. Syntax:
NB. vec=. inc extract svec
NB. where
NB. inc ≠ 0, the increment for the elements of vec in svec
NB. svec - vector with evenly spaced elements of vec
NB. vec - vector to extract
NB.
NB. Examples:
NB. _2 extract_mt_ 11 22 33 44 55
NB. 55 33 11
NB.
NB. Notes:
NB. - the following sentences are equivalent:
NB. {."1 (- | inc) ]\ svec
NB. inc (] #~ 1 ,~ 1 #~ ((% |)~ <:@#) # 1 j. <:@|@[) svec
extract=: 4 : '|.^:(0 > x) {."1 (- | x) ]\ y'
NB. ---------------------------------------------------------
NB. expand
NB.
NB. Description:
NB. Conj. to make monad to expand vector in boxed list
NB.
NB. Syntax:
NB. out=. (iovec expand ioinc) inp
NB. where
NB. iovec - IO vec in inp and xvec in out
NB. ioinc - IO inc in inp and out
NB. vec - n-vector, the following holds:
NB. vec -: iovec {:: inp
NB. inc ≠ 0, the increment for the elements of vec, the
NB. following holds:
NB. inc -: ioinc {:: inp
NB. inc -: ioinc {:: out
NB. xvec - (1+(n-1)*|inc|)-vector, expanded by random
NB. number, the following holds:
NB. xvec -: iovec {:: out
NB. inp - m-vector of boxes
NB. out - inp with vec replaced by xvec
NB.
NB. Examples:
NB. (1 expand_mt_ 3) (_. ; 11 22 33 ; _. ; _2)
NB. +--+----------------+--+--+
NB. |_.|11 0.1 22 0.1 33|_.|_2|
NB. +--+----------------+--+--+
NB. where
NB. 0.1 - random number
NB. 33 22 11 - effective vector (reversed since inc < 0)
NB.
NB. Notes:
NB. - random filler is useful to detect errors as early as
NB. possible
NB. - filler must be non-zero to avoid problems in chkxxx
NB. which replace 0 by 1 before comparison and division
NB. - negative inc is used by caller to reverse vec
expand=: 2 : '<@((1 j. <:@|@(n&{::)) ((#!.(?0) }:) , _1 { :: ($0) ]) m&{::) m} ]'
NB. ---------------------------------------------------------
NB. shrink
NB.
NB. Description:
NB. Conj. to make conj. to make monad to shrink matrix in
NB. boxed list
NB.
NB. Syntax:
NB. out=. (getsz (iosmp shrink iomat) setsz) inp
NB. where
NB. getsz - monad to get size of sample matrix
NB. setsz - monad to set size of shrinked matrix
NB. iosmp - IO sample matrix in inp
NB. iomat - IO matrix to shrink in inp and shrinked matrix
NB. in out
NB. inp - m-vector of boxes
NB. out - inp with matrix shrinked instead of original
NB. one
NB.
NB. Examples:
NB. (# (1 shrink_mt_ 2) ({."1)) 0.7 ; (i. 2 5) ; (i. 4 3) ; 1.1 ; (i. 2 3)
NB. +---+---------+----+---+-----+
NB. |0.7|0 1 2 3 4|0 1|1.1|0 1 2|
NB. | |5 6 7 8 9|3 4| |3 4 5|
NB. | | |6 7| | |
NB. | | |9 10| | |
NB. +---+---------+----+---+-----+
NB. where
NB. # - monad to take size (rows here) of sample
NB. {."1 - monad to set size (columns here) of matrix
NB. 1 - IO sample matrix
NB. 2 - IO matrix to shrink
NB. i. 2 5 - sample matrix
NB. i. 4 3 - matrix to shrink
NB. to shrink (i. 4 3) to (2 {."1 i. 4 3)
NB.
NB. Notes:
NB. - shrink is a double conjunction
shrink=: {{2 : ('(((u@(' , (": m) , '&{::)) <@:v (' , (": n) , '&{::)) ' , (": n) , '} ])')}}
NB. ---------------------------------------------------------
NB. reverse
NB.
NB. Description:
NB. Conj. to make monad to reverse vector in boxed list
NB.
NB. Syntax:
NB. out=. (iovec reverse ioinc) inp
NB. where
NB. iovec - IO vec in inp and rvec in out
NB. ioinc - IO inc in inp and out
NB. vec - n-vector, the following holds:
NB. vec -: iovec {:: inp
NB. inc ≠ 0, the increment for the elements of vec, the
NB. following holds:
NB. inc -: ioinc {:: inp
NB. inc -: ioinc {:: out
NB. rvec - vec reversed iif (inc < 0), the following
NB. holds:
NB. rvec -: iovec {:: out
NB. inp - m-vector of boxes
NB. out - inp with vec replaced by rvec
NB.
NB. Examples:
NB. (1 reverse_mt_ 3) (_. ; 11 22 33 44 55 ; _. ; _2)
NB. +--+----------------+--+--+
NB. |_.|55 44 33 22 11|_.|_2|
NB. +--+----------------+--+--+
NB. where
NB. 55 33 11 - effective vector (reversed since inc < 0)
reverse=: 2 : '[:`]`(|.&.>&.(m&{))@.(*@(n&{::))'
NB. ---------------------------------------------------------
NB. ger
NB.
NB. Description:
NB. Adv. to make monad to perform the rank 1 operation:
NB. A := alpha * x * op(y) + A
NB. where
NB. op(y) - either y^T or y^H
NB.
NB. Syntax:
NB. Aupd=. (mul ger) alpha ; x ; incx ; y ; incy ; A
NB. where
NB. mul - dyad to compute the product (alpha * op(y)), is
NB. called as:
NB. product=. alpha mul y
NB. and is one of:
NB. * NB. op(y) = y^T
NB. (* +) NB. op(y) = y^H
ger=: 1 : 0
'alpha xx incx y incy A'=. y
xx=. incx extract_mt_ xx
y=. incy extract_mt_ y
A=. A + xx */ alpha u y
)
NB. ---------------------------------------------------------
NB. Monad op(y)
NB. gerc y^H
NB. geru y^T
NB.
NB. Description:
NB. Performs the rank 1 operation:
NB. A := alpha * x * op(y) + A
NB. where
NB. op(y) - either y^T or y^H
NB.
NB. Syntax:
NB. Aupd=. gerx alpha ; x ; incx ; y ; incy ; A
NB. where
NB. alpha - scalar
NB. x - (1+(m-1)*|incx|)-vector
NB. incx ≠ 0, the increment for the elements of x
NB. y - (1+(n-1)*|incy|)-vector
NB. incy ≠ 0, the increment for the elements of y
NB. A - m×n-matrix
NB. Aupd - an updated A
NB. m ≥ 0, the number of rows in A and Aupd
NB. n ≥ 0, the number of columns in A and Aupd
NB.
NB. Notes:
NB. - gerc implements BLAS' ZGERC
NB. - geru implements BLAS' DGER ZGERU
NB. - reference implementation
gerc=: (* +) ger
geru=: * ger
NB. ---------------------------------------------------------
NB. her
NB.
NB. Description:
NB. Conj. to make monad to perform the hermitian
NB. (symmetric) rank 1 operation:
NB. A := alpha * x * op(x) + A
NB. where
NB. A - Hermitian (symmetric)
NB. op(x) - either x^T or x^H
NB.
NB. Syntax:
NB. AAupd=. (ref her mul) alpha ; x ; incx ; AA
NB. where
NB. ref - monad to pick a triangular part, is one of:
NB. trlpick NB. LT
NB. trupick NB. UT
NB. mul - dyad to define the form of op(A), is one of:
NB. * NB. the symmetric operation: op(A) := A^T
NB. (* +) NB. the hermitian operation: op(A) := A^H
her=: 2 : 0
'alpha y incy AA'=. y
y=. incy extract_mt_ y
AA=. AA + u alpha (] */ v) y
)
NB. ---------------------------------------------------------
NB. Monad A R/W in A op(x)
NB. syrl SY LT x^T
NB. syru SY UT x^T
NB. herl HE LT x^H
NB. heru HE UT x^H
NB.
NB. Description:
NB. Performs the hermitian (symmetric) rank 1 operation:
NB. A := alpha * x * op(x) + A
NB. where
NB. A - Hermitian (symmetric)
NB.
NB. Syntax:
NB. AAupd=. xxrx alpha ; x ; incx ; AA
NB. where
NB. alpha - scalar, real
NB. x - (1+(n-1)*|incx|)-vector
NB. incx ≠ 0, the increment for the elements of x
NB. AA - n×n-matrix, contains either LT or UT or both
NB. part(s) of A
NB. AAupd - AA with either LT (for xxrl) or UT (for xxru)
NB. updated
NB. A - n×n-matrix, Hermitian (symmetric)
NB. n ≥ 0, the size of A, AA and AAupd
NB.
NB. Notes:
NB. - syrl models BLAS' DSYR('L',...) with the following
NB. extension: A can have complex datatype, too
NB. - syru models BLAS' DSYR('U',...) with the following
NB. extension: A can have complex datatype, too
NB. - herl models BLAS' ZHER('L',...)
NB. - heru models BLAS' ZHER('U',...)
NB. - reference implementation
syrl=: trlpick_mt_ her *
syru=: trupick_mt_ her *
herl=: trlpick_mt_ her (* +)
heru=: trupick_mt_ her (* +)
NB. ---------------------------------------------------------
NB. her2
NB.
NB. Description:
NB. Conj. to make monad to perform the hermitian
NB. (symmetric) rank 2 operation:
NB. A := alpha * x * op1(y) + op2(alpha) * y * op1(x) + A
NB. where
NB. A - Hermitian (symmetric)
NB. op1(x) - either x^T or x^H
NB. op2(alpha) - either alpha or conj(alpha)
NB.
NB. Syntax:
NB. AAupd=. (ref her2 trans) alpha ; x ; incx ; y ; incy ; AA
NB. where
NB. ref - monad to pick a triangular part, is one of:
NB. trlpick NB. LT
NB. trupick NB. UT
NB. trans - monad to define the form of op1(v) and op2(s),
NB. is one of:
NB. |: NB. the symmetric operation: op1(v) = v^T, op2(s) = s
NB. ct NB. the hermitian operation: op1(v) = v^H, op2(s) = conj(s)
her2=: 2 : 0
'alpha xx incx y incy AA'=. y
xx=. incx extract_mt_ xx
y=. incy extract_mt_ y
AA=. AA + u (+ v)~ xx */ alpha * v y
)
NB. ---------------------------------------------------------
NB. Monad A R/W in A op1(v) op2(alpha)
NB. syr2l SY LT v^T alpha
NB. syr2u SY UT v^T alpha
NB. her2l HE LT v^H conj(alpha)
NB. her2u HE UT v^H conj(alpha)
NB.
NB. Description:
NB. Performs the hermitian (symmetric) rank 2 operation:
NB. A := alpha * x * op1(y) + op2(alpha) * y * op1(x) + A
NB. where
NB. A - Hermitian (symmetric)
NB.
NB. Syntax:
NB. AAupd=. xxr2x alpha ; x ; incx ; y ; incy ; AA
NB. where
NB. alpha - scalar
NB. x - (1+(n-1)*|incx|)-vector
NB. incx ≠ 0, the increment for the elements of x
NB. y - (1+(n-1)*|incy|)-vector
NB. incy ≠ 0, the increment for the elements of y
NB. AA - n×n-matrix, contains either LT or UT or both
NB. part(s) of A
NB. AAupd - AA with either LT (for xxr2l) or UT (for
NB. xxr2u) updated
NB. A - n×n-matrix, Hermitian (symmetric)
NB. n ≥ 0, the size of A, AA and AAupd
NB.
NB. Notes:
NB. - syr2l models BLAS' DSYR2('L',...) with the following
NB. extension: A can have complex datatype, too
NB. - syr2u models BLAS' DSYR2('U',...) with the following
NB. extension: A can have complex datatype, too
NB. - her2l models BLAS' ZHER2('L',...)
NB. - her2u models BLAS' ZHER2('U',...)
NB. - reference implementation
syr2l=: trlpick_mt_ her2 |:
syr2u=: trupick_mt_ her2 |:
her2l=: trlpick_mt_ her2 ct_mt_
her2u=: trupick_mt_ her2 ct_mt_
NB. ---------------------------------------------------------
NB. herk
NB.
NB. Description:
NB. Conj. to make monad to perform the hermitian
NB. (symmetric) rank k operation:
NB. C := alpha * A * op(A) + beta * C
NB. or
NB. C := alpha * op(A) * A + beta * C
NB. where
NB. C - Hermitian (symmetric)
NB. op(A) - either A^T or A^H
NB.
NB. Syntax:
NB. CCupd=. (ctp herk mul) alpha ; A ; beta ; CC
NB. where
NB. ctp - dyad to compose a matrix from triangular parts,
NB. is one of:
NB. slxuy NB. take SLT from CC, and UT from the matrix computed
NB. suxly NB. take SUT from CC, and LT from the matrix computed
NB. mul - dyad to compute the product either (A * op(A)) or
NB. (op(A) * A), is called as:
NB. product=. mul A
herk=: 2 : '3&{:: u (0&{:: (* v~) 1&{::) + 2&{:: * 3&{::'
NB. ---------------------------------------------------------
NB. Monad C alpha,beta R/W in C op1(A) op2(A)
NB. syrkln SY any LT A A^T
NB. syrklt SY any LT A^T A
NB. syrkun SY any UT A A^T
NB. syrkut SY any UT A^T A
NB. herkln HE real LT A A^H
NB. herklc HE real LT A^H A
NB. herkun HE real UT A A^H
NB. herkuc HE real UT A^H A
NB.
NB. Description:
NB. Performs the hermitian (symmetric) rank k operation:
NB. C := alpha * op1(A) * op2(A) + beta * C
NB. where
NB. C - Hermitian (symmetric)
NB.
NB. Syntax:
NB. CCupd=. xxrkxx alpha ; A ; beta ; CC
NB. where
NB. alpha - scalar, must be real for herkxx
NB. A - na×ka-matrix
NB. beta - scalar, must be real for herkxx
NB. CC - n×n-matrix, contains either LT or UT or both
NB. part(s) of C
NB. CCupd - CC with either LT (for xxrklx) or UT (for
NB. xxrkux) updated
NB. C - n×n-matrix, Hermitian (symmetric)
NB. n ≥ 0, the size of C, CC and CCupd and the number
NB. of rows or columns in A
NB. k ≥ 0, the number of columns or rows in A
NB. ka = k for xxrkxn or ka = n otherwise
NB. na = n for xxrkxn or na = k otherwise
NB.
NB. Notes:
NB. - monad models BLAS'
NB. syrkln xSYRK('L','N',...)
NB. syrklt xSYRK('L','T',...) and DSYRK('L','C',...)
NB. syrkun xSYRK('U','N',...)
NB. syrkut xSYRK('U','T',...) and DSYRK('U','C',...)
NB. herkln ZHERK('L','N',...)
NB. herklc ZHERK('L','C',...)
NB. herkun ZHERK('U','N',...)
NB. herkuc ZHERK('U','C',...)
NB. - reference implementation
syrkln=: suxly_mt_ herk (mp_mt_ |: )
syrklt=: suxly_mt_ herk (mp_mt_~ |: )
syrkun=: slxuy_mt_ herk (mp_mt_ |: )
syrkut=: slxuy_mt_ herk (mp_mt_~ |: )
herkln=: suxly_mt_ herk (mp_mt_ ct_mt_)
herklc=: suxly_mt_ herk (mp_mt_~ ct_mt_)
herkun=: slxuy_mt_ herk (mp_mt_ ct_mt_)
herkuc=: slxuy_mt_ herk (mp_mt_~ ct_mt_)
NB. ---------------------------------------------------------
NB. her2k
NB.
NB. Description:
NB. Conj. to make monad to perform the hermitian
NB. (symmetric) rank 2k operation:
NB. C := alpha * A * op1(B) + op2(alpha) * B * op1(A) + beta * C (1)
NB. or
NB. C := alpha * op1(A) * B + op2(alpha) * op1(B) * A + beta * C (2)
NB. where
NB. C - Hermitian (symmetric)
NB. op1(M) - either M^T or M^H
NB. op2(alpha) - either alpha or conj(alpha)
NB.
NB. Syntax:
NB. CCupd=. (ctp`trans her2k kind) alpha ; A ; B ; beta ; CC
NB. where
NB. ctp - dyad to compose a matrix from triangular parts,
NB. is one of:
NB. slxuy NB. take SLT from CC, and UT from the matrix computed
NB. suxly NB. take SUT from CC, and LT from the matrix computed
NB. trans - monad to define the form of op1(M) and op2(s),
NB. is one of:
NB. |: NB. the symmetric operation: op1(M) = M^T, op2(s) = s
NB. ct NB. the hermitian operation: op1(M) = M^H, op2(s) = conj(s)
NB. kind - boolean scalar to define operation:
NB. 0 NB. (2)
NB. 1 NB. (1)
NB.
NB. Notes:
NB. - her2k's design solves a problem: how to allow C1 to see
NB. V2 in the train (V0 C1 V2 A3), the solution is: send V2
NB. not (V2 A3) into C1, implement A3 functionality inside
NB. C1 inline, use switch N4 to control A3 behavior, the
NB. resulting train becomes (V0`V2 C1 N4)
her2k=: 2 : '4&{:: [email protected] (0&{:: (+ [email protected])@:* 1&{:: (mp_mt_~ [email protected])~`(mp_mt_ [email protected])@.n 2&{::) + 3&{:: * 4&{::'
NB. ---------------------------------------------------------
NB. Monad C beta R/W in C op1(M) op2(M) op3(alpha)
NB. syr2kln SY any LT M M^T alpha
NB. syr2klt SY any LT M^T M alpha
NB. syr2kun SY any UT M M^T alpha
NB. syr2kut SY any UT M^T M alpha
NB. her2kln HE real LT M M^H conj(alpha)
NB. her2klc HE real LT M^H M conj(alpha)
NB. her2kun HE real UT M M^H conj(alpha)
NB. her2kuc HE real UT M^H M conj(alpha)
NB.
NB. Description:
NB. Performs the hermitian (symmetric) rank 2k operation:
NB. C := alpha * op1(A) * op2(B) + op3(alpha) * op1(B) * op2(A) + beta * C
NB. where
NB. C - Hermitian (symmetric)
NB.
NB. Syntax:
NB. CCupd=. xxr2kxx alpha ; A ; B ; beta ; CC
NB. where
NB. alpha - scalar
NB. A - nab×kab-matrix
NB. B - nab×kab-matrix
NB. beta - scalar, must be real for her2kxx
NB. CC - n×n-matrix, contains either LT or UT or both
NB. part(s) of C
NB. CCupd - CC with either LT (for xxr2klx) or UT (for
NB. xxr2kux) updated
NB. C - n×n-matrix, Hermitian (symmetric)
NB. n ≥ 0, the size of C, CC and CCupd and the number
NB. of rows or columns in A and B
NB. k ≥ 0, the number of columns or rows in A and B
NB. kab = k for xxr2kxn or kab = n otherwise
NB. nab = n for xxr2kxn or nab = k otherwise
NB.
NB. Notes:
NB. - monad models BLAS'
NB. syr2kln xSYR2K('L','N',...)
NB. syr2klt xSYR2K('L','T',...) and DSYR2K('L','C',...)
NB. syr2kun xSYR2K('U','N',...)
NB. syr2kut xSYR2K('U','T',...) and DSYR2K('U','C',...)
NB. her2kln ZHER2K('L','N',...)
NB. her2klc ZHER2K('L','C',...)
NB. her2kun ZHER2K('U','N',...)
NB. her2kuc ZHER2K('U','C',...)
NB. - reference implementation
syr2kln=: suxly_mt_`|: her2k 1
syr2klt=: suxly_mt_`|: her2k 0
syr2kun=: slxuy_mt_`|: her2k 1
syr2kut=: slxuy_mt_`|: her2k 0
her2kln=: suxly_mt_`ct_mt_ her2k 1
her2klc=: suxly_mt_`ct_mt_ her2k 0
her2kun=: slxuy_mt_`ct_mt_ her2k 1
her2kuc=: slxuy_mt_`ct_mt_ her2k 0
NB. ---------------------------------------------------------
NB. gemv
NB.
NB. Description:
NB. Adv. to make monad to perform the matrix-vector
NB. operation:
NB. y := alpha * op(A) * x + beta * y
NB.
NB. Syntax:
NB. yupd=. (trans gemv) alpha ; A ; x ; incx ; beta ; y ; incy
NB. where
NB. trans - monad to define the form of op(A), is one of:
NB. ] NB. op(A) := A
NB. |: NB. op(A) := A^T
NB. ct NB. op(A) := A^H
gemv=: 1 : 0
'alpha A xx incx beta ybak incy'=. y
xx=. incx extract_mt_ xx
y=. incy extract_mt_ ybak
y=. ((u A) mp_mt_ alpha * xx) + beta * y
y=. y (incy ([ ((* |)~ i.) negneg_mt_) #@[)} ybak
)
NB. ---------------------------------------------------------
NB. Monad op(A)
NB. gemvn A
NB. gemvt A^T
NB. gemvc A^H
NB.
NB. Description:
NB. Performs the matrix-vector operation:
NB. y := alpha * op(A) * x + beta * y
NB.
NB. Syntax:
NB. yupd=. gemvx alpha ; A ; x ; incx ; beta ; y ; incy
NB. where
NB. alpha - scalar
NB. A - m×n-matrix
NB. x - (1+(kx-1)*|incx|)-vector
NB. incx ≠ 0, the increment for the elements of x
NB. beta - scalar
NB. y - (1+(ky-1)*|incy|)-vector
NB. incy ≠ 0, the increment for the elements of y
NB. yupd - an updated y
NB. kx = n for gemvn or kx = m otherwise
NB. ky = m for gemvn or ky = n otherwise
NB. m ≥ 0, the number of rows in A
NB. n ≥ 0, the number of columns in A
NB.
NB. Notes:
NB. - monad models BLAS'
NB. gemvn xGEMV('N',...)
NB. gemvt xGEMV('T',...)
NB. gemvc DGEMV('T',...) and ZGEMV('C',...)
NB. - reference implementation
gemvn=: ] gemv
gemvt=: |: gemv
gemvc=: ct_mt_ gemv
NB. ---------------------------------------------------------
NB. hemv
NB.
NB. Description:
NB. Adv. to make monad to perform the matrix-vector
NB. operation:
NB. y := alpha * A * x + beta * y
NB. where
NB. A - Hermitian (symmetric)
NB.
NB. Syntax:
NB. yupd=. (ref hemv) alpha ; AA ; x ; incx ; beta ; y ; incy
NB. where
NB. ref - monad to restore A from triangular part, is one
NB. of:
NB. sy4gel NB. LT, A is symmetric
NB. sy4geu NB. UT, A is symmetric
NB. he4gel NB. LT, A is Hermitian
NB. he4geu NB. UT, A is Hermitian
hemv=: gemv
NB. ---------------------------------------------------------
NB. Monad A Reads in A
NB. symvl SY LT
NB. symvu SY UT
NB. hemvl HE LT
NB. hemvu HE UT
NB.
NB. Description:
NB. Performs the matrix-vector operation:
NB. y := alpha * A * x + beta * y
NB. where
NB. A - Hermitian (symmetric)
NB.
NB. Syntax:
NB. yupd=. xxmvx alpha ; AA ; x ; incx ; beta ; y ; incy
NB. where
NB. alpha - scalar
NB. AA - n×n-matrix, contains either LT or UT or both
NB. part(s) of A
NB. x - (1+(n-1)*|incx|)-vector
NB. incx ≠ 0, the increment for the elements of x
NB. beta - scalar
NB. y - (1+(n-1)*|incy|)-vector
NB. incy ≠ 0, the increment for the elements of y
NB. yupd - an updated y
NB. A - n×n-matrix, Hermitian (symmetric)
NB. n ≥ 0, the size of A and AA
NB.
NB. Notes:
NB. - symvl models BLAS' DSYMV('L',...) with the following
NB. extension: A can have complex datatype, too
NB. - symvu models BLAS' DSYMV('U',...) with the following
NB. extension: A can have complex datatype, too
NB. - hemvl models BLAS' ZHEMV('L',...)
NB. - hemvu models BLAS' ZHEMV('U',...)
NB. - reference implementation
symvl=: sy4gel_mt_ hemv
symvu=: sy4geu_mt_ hemv
hemvl=: he4gel_mt_ hemv
hemvu=: he4geu_mt_ hemv
NB. ---------------------------------------------------------
NB. trmv
NB.
NB. Description:
NB. Adv. to make monad to perform the matrix-vector
NB. operation:
NB. x := op(A) * x
NB. where
NB. A - triangular
NB.
NB. Syntax:
NB. xupd=. ((mp_mt_~ trans@ref) trmv) AA ; x ; incx
NB. where
NB. ref - monad to restore A from triangular part, is one
NB. of:
NB. trlpick NB. LT, A is L
NB. trl1pick NB. SLT, A is L1
NB. trupick NB. UT, A is U
NB. tru1pick NB. SUT, A is U1
NB. trans - monad to define the form of op(A), is one of:
NB. ] NB. op(A) := A
NB. |: NB. op(A) := A^T
NB. ct NB. op(A) := A^H
trmv=: 1 : 0
'AA ybak incy'=. y
y=. incy extract_mt_ ybak
y=. y u AA
y=. y (incy ([ ((* |)~ i.) negneg_mt_) #@[)} ybak
)
NB. ---------------------------------------------------------
NB. Monad A Reads in A op(A)
NB. trmvlnn L LT A
NB. trmvlnu L1 SLT A
NB. trmvltn L LT A^T
NB. trmvltu L1 SLT A^T
NB. trmvlcn L LT A^H
NB. trmvlcu L1 SLT A^H
NB. trmvunn U UT A
NB. trmvunu U1 SUT A
NB. trmvutn U UT A^T
NB. trmvutu U1 SUT A^T
NB. trmvucn U UT A^H
NB. trmvucu U1 SUT A^H
NB.
NB. Description:
NB. Performs the matrix-vector operation:
NB. x := op(A) * x
NB. where
NB. A - triangular
NB.
NB. Syntax:
NB. xupd=. trmvxxx AA ; x ; incx
NB. where
NB. AA - n×n-matrix, contains either non-zero or both
NB. part(s) of A
NB. x - (1+(n-1)*|incx|)-vector
NB. incx ≠ 0, the increment for the elements of x
NB. xupd - an updated x
NB. A - n×n-matrix, triangular
NB. n ≥ 0, the size of A and AA
NB.
NB. Notes:
NB. - monad models BLAS'
NB. trmvlnn xTRMV('L','N','N',...)
NB. trmvlnu xTRMV('L','N','U',...)
NB. trmvltn xTRMV('L','T','N',...)
NB. trmvltu xTRMV('L','T','U',...)
NB. trmvlcn xTRMV('L','C','N',...)
NB. trmvlcu xTRMV('L','C','U',...)
NB. trmvunn xTRMV('U','N','N',...)
NB. trmvunu xTRMV('U','N','U',...)
NB. trmvutn xTRMV('U','T','N',...)
NB. trmvutu xTRMV('U','T','U',...)
NB. trmvucn xTRMV('U','C','N',...)
NB. trmvucu xTRMV('U','C','U',...)
NB. - reference implementation
trmvlnn=: (mp_mt_~ trlpick_mt_ ) trmv
trmvlnu=: (mp_mt_~ trl1pick_mt_) trmv
trmvltn=: (mp_mt_~ |: @trlpick_mt_ ) trmv
trmvltu=: (mp_mt_~ |: @trl1pick_mt_) trmv
trmvlcn=: (mp_mt_~ ct_mt_@trlpick_mt_ ) trmv
trmvlcu=: (mp_mt_~ ct_mt_@trl1pick_mt_) trmv
trmvunn=: (mp_mt_~ trupick_mt_ ) trmv
trmvunu=: (mp_mt_~ tru1pick_mt_) trmv
trmvutn=: (mp_mt_~ |: @trupick_mt_ ) trmv
trmvutu=: (mp_mt_~ |: @tru1pick_mt_) trmv
trmvucn=: (mp_mt_~ ct_mt_@trupick_mt_ ) trmv
trmvucu=: (mp_mt_~ ct_mt_@tru1pick_mt_) trmv
NB. ---------------------------------------------------------
NB. gemm
NB.
NB. Description:
NB. Adv. to make monad to perform the matrix-matrix
NB. operation:
NB. C := alpha * op1(A) * op2(B) + beta * C
NB. where
NB. opX(M) - either M, M^T, conj(M) or M^H
NB.
NB. Syntax:
NB. Cupd=. (mul gemm) alpha ; A ; B ; beta ; C
NB. where
NB. mul - dyad to compute the product (op1(A) * op2(B)), is
NB. called as:
NB. product=. A mul B
gemm=: 1 : '(0&{:: * 1&{:: u 2&{::) + 3&{:: * 4&{::'
NB. ---------------------------------------------------------
NB. Monad op1(A) op2(B)
NB. gemmnn A B
NB. gemmnt A B^T
NB. gemmnj A conj(B)
NB. gemmnc A B^H
NB. gemmtn A^T B
NB. gemmtt A^T B^T
NB. gemmtj A^T conj(B)
NB. gemmtc A^T B^H
NB. gemmjn conj(A) B
NB. gemmjt conj(A) B^T
NB. gemmjj conj(A) conj(B)
NB. gemmjc conj(A) B^H
NB. gemmcn A^H B
NB. gemmct A^H B^T
NB. gemmcj A^H conj(B)
NB. gemmcc A^H B^H
NB.
NB. Description:
NB. Performs the matrix-matrix operation:
NB. C := alpha * op1(A) * op2(B) + beta * C
NB.
NB. Syntax:
NB. Cupd=. gemmxx alpha ; A ; B ; beta ; C
NB. where
NB. alpha - scalar
NB. A - ma×ka-matrix
NB. B - kb×nb-matrix
NB. beta - scalar
NB. C - m×n-matrix
NB. Cupd - an updated C
NB. m ≥ 0, the number of rows in C, Cupd and op1(A)
NB. n ≥ 0, the number of columns in C, Cupd and op2(B)
NB. k ≥ 0, the number of columns in op1(A) and the
NB. number of rows in op2(B)
NB. ma = m for gemmnx and gemmjx, or ma = k otherwise
NB. ka = k for gemmnx and gemmjx, or ka = m otherwise
NB. kb = k for gemmxn and gemmxj, or kb = n otherwise
NB. nb = n for gemmxn and gemmxj, or nb = k otherwise
NB.
NB. Notes:
NB. - monad models BLAS'
NB. gemmnn xGEMM('N','N',...)
NB. gemmnt xGEMM('N','T',...)
NB. gemmnc xGEMM('N','C',...)
NB. gemmtn xGEMM('T','N',...)
NB. gemmtt xGEMM('T','T',...)
NB. gemmtc xGEMM('T','C',...)
NB. gemmcn xGEMM('C','N',...)
NB. gemmct xGEMM('C','T',...)
NB. gemmcc xGEMM('C','C',...)
NB. - reference implementation
gemmnn=: mp_mt_ gemm
gemmnt=: (mp_mt_ |: ) gemm
gemmnj=: (mp_mt_ + ) gemm
gemmnc=: (mp_mt_ ct_mt_) gemm
gemmtn=: (mp_mt_~ |: )~ gemm
gemmtt=: mp_mt_& |: gemm
gemmtj=: ((mp_mt_~ |: )~ + ) gemm
gemmtc=: ((mp_mt_~ |: )~ ct_mt_) gemm
gemmjn=: (mp_mt_~ + )~ gemm
gemmjt=: ((mp_mt_~ + )~ |: ) gemm
gemmjj=: mp_mt_&:+ gemm
gemmjc=: ((mp_mt_~ + )~ ct_mt_) gemm
gemmcn=: (mp_mt_~ ct_mt_)~ gemm
gemmct=: ((mp_mt_~ ct_mt_)~ |: ) gemm
gemmcj=: ((mp_mt_~ ct_mt_)~ + ) gemm
gemmcc=: mp_mt_& ct_mt_ gemm
NB. ---------------------------------------------------------
NB. hemm
NB.
NB. Description:
NB. Adv. to make monad to perform the matrix-matrix
NB. operation:
NB. C := alpha * op1(A) * op2(B) + beta * C (1)
NB. or
NB. C := alpha * op2(B) * op1(A) + beta * C (2)
NB. where
NB. A - Hermitian (symmetric)
NB. op1(A) - either A or conj(A)
NB. op2(B) - either B, B^T, conj(B) or B^H
NB.
NB. Syntax:
NB. Cupd=. (mul hemm) alpha ; AA ; B ; beta ; C
NB. where
NB. mul - dyad to restore A from triangular part, and to
NB. compute the product either (op1(A) * op2(B)) or
NB. (op2(B) * op1(A)), is called as:
NB. product=. AA mul B
hemm=: gemm
NB. ---------------------------------------------------------
NB. Monad A Side Reads in A op1(A) op2(B)
NB. symmllnn SY (1) LT A B
NB. symmllnt SY (1) LT A B^T
NB. symmllnj SY (1) LT A conj(B)
NB. symmllnc SY (1) LT A B^H
NB. symmlljn SY (1) LT conj(A) B
NB. symmlljt SY (1) LT conj(A) B^T
NB. symmlljj SY (1) LT conj(A) conj(B)
NB. symmlljc SY (1) LT conj(A) B^H
NB. symmlunn SY (1) UT A B
NB. symmlunt SY (1) UT A B^T
NB. symmlunj SY (1) UT A conj(B)
NB. symmlunc SY (1) UT A B^H
NB. symmlujn SY (1) UT conj(A) B
NB. symmlujt SY (1) UT conj(A) B^T
NB. symmlujj SY (1) UT conj(A) conj(B)
NB. symmlujc SY (1) UT conj(A) B^H
NB. symmrlnn SY (2) LT A B
NB. symmrlnt SY (2) LT A B^T
NB. symmrlnj SY (2) LT A conj(B)
NB. symmrlnc SY (2) LT A B^H
NB. symmrljn SY (2) LT conj(A) B
NB. symmrljt SY (2) LT conj(A) B^T
NB. symmrljj SY (2) LT conj(A) conj(B)
NB. symmrljc SY (2) LT conj(A) B^H
NB. symmrunn SY (2) UT A B
NB. symmrunt SY (2) UT A B^T
NB. symmrunj SY (2) UT A conj(B)
NB. symmrunc SY (2) UT A B^H
NB. symmrujn SY (2) UT conj(A) B
NB. symmrujt SY (2) UT conj(A) B^T
NB. symmrujj SY (2) UT conj(A) conj(B)
NB. symmrujc SY (2) UT conj(A) B^H
NB. hemmllnn HE (1) LT A B
NB. hemmllnt HE (1) LT A B^T
NB. hemmllnj HE (1) LT A conj(B)
NB. hemmllnc HE (1) LT A B^H
NB. hemmlljn HE (1) LT conj(A) B
NB. hemmlljt HE (1) LT conj(A) B^T
NB. hemmlljj HE (1) LT conj(A) conj(B)
NB. hemmlljc HE (1) LT conj(A) B^H
NB. hemmlunn HE (1) UT A B
NB. hemmlunt HE (1) UT A B^T
NB. hemmlunj HE (1) UT A conj(B)
NB. hemmlunc HE (1) UT A B^H
NB. hemmlujn HE (1) UT conj(A) B
NB. hemmlujt HE (1) UT conj(A) B^T
NB. hemmlujj HE (1) UT conj(A) conj(B)
NB. hemmlujc HE (1) UT conj(A) B^H
NB. hemmrlnn HE (2) LT A B
NB. hemmrlnt HE (2) LT A B^T
NB. hemmrlnj HE (2) LT A conj(B)