/
factor.hpp
967 lines (859 loc) · 27.2 KB
/
factor.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
/*
Copyright (c) 2009-2016, Jack Poulson
All rights reserved.
This file is part of Elemental and is under the BSD 2-Clause License,
which can be found in the LICENSE file in the root directory, or at
http://opensource.org/licenses/BSD-2-Clause
*/
#ifndef EL_FACTOR_HPP
#define EL_FACTOR_HPP
#include <El/lapack_like/perm.hpp>
#include <El/lapack_like/util.hpp>
#include <El/lapack_like/factor/ldl/sparse/symbolic.hpp>
#include <El/lapack_like/factor/ldl/sparse/numeric.hpp>
namespace El {
// Cholesky
// ========
template<typename Field>
void Cholesky( UpperOrLower uplo, Matrix<Field>& A );
template<typename Field>
void Cholesky
( UpperOrLower uplo, AbstractDistMatrix<Field>& A, bool scalapack=false );
template<typename Field>
void Cholesky( UpperOrLower uplo, DistMatrix<Field,STAR,STAR>& A );
template<typename Field>
void ReverseCholesky( UpperOrLower uplo, Matrix<Field>& A );
template<typename Field>
void ReverseCholesky( UpperOrLower uplo, AbstractDistMatrix<Field>& A );
template<typename Field>
void ReverseCholesky( UpperOrLower uplo, DistMatrix<Field,STAR,STAR>& A );
template<typename Field>
void Cholesky( UpperOrLower uplo, Matrix<Field>& A, Permutation& P );
template<typename Field>
void Cholesky
( UpperOrLower uplo, AbstractDistMatrix<Field>& A, DistPermutation& P );
template<typename Field>
void CholeskyMod
( UpperOrLower uplo,
Matrix<Field>& T,
Base<Field> alpha,
Matrix<Field>& V );
template<typename Field>
void CholeskyMod
( UpperOrLower uplo,
AbstractDistMatrix<Field>& T,
Base<Field> alpha,
AbstractDistMatrix<Field>& V );
template<typename Field>
void HPSDCholesky( UpperOrLower uplo, Matrix<Field>& A );
template<typename Field>
void HPSDCholesky( UpperOrLower uplo, AbstractDistMatrix<Field>& A );
namespace cholesky {
template<typename Field>
void SolveAfter
( UpperOrLower uplo,
Orientation orientation,
const Matrix<Field>& A,
Matrix<Field>& B );
template<typename Field>
void SolveAfter
( UpperOrLower uplo,
Orientation orientation,
const AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& B );
template<typename Field>
void SolveAfter
( UpperOrLower uplo,
Orientation orientation,
const Matrix<Field>& A,
const Permutation& P,
Matrix<Field>& B );
template<typename Field>
void SolveAfter
( UpperOrLower uplo,
Orientation orientation,
const AbstractDistMatrix<Field>& A,
const DistPermutation& P,
AbstractDistMatrix<Field>& B );
} // namespace cholesky
// LDL
// ===
namespace LDLPivotTypeNS {
enum LDLPivotType
{
BUNCH_KAUFMAN_A,
BUNCH_KAUFMAN_C,
BUNCH_KAUFMAN_D,
BUNCH_KAUFMAN_BOUNDED,
BUNCH_PARLETT,
LDL_WITHOUT_PIVOTING
/* TODO(poulson): Diagonal pivoting? */
};
}
using namespace LDLPivotTypeNS;
template<typename Real>
Real LDLPivotConstant( LDLPivotType pivType )
{
// TODO(poulson): Check that the Bunch-Parlett choice is optimal
switch( pivType )
{
case BUNCH_KAUFMAN_A:
case BUNCH_PARLETT: return (1+Sqrt(Real(17)))/8;
case BUNCH_KAUFMAN_D: return Real(0.525);
default:
LogicError("No default constant exists for this pivot type");
return 0;
}
}
struct LDLPivot
{
Int nb;
Int from[2];
};
template<typename Real>
struct LDLPivotCtrl {
LDLPivotType pivotType;
Real gamma;
LDLPivotCtrl( LDLPivotType piv=BUNCH_KAUFMAN_A )
: pivotType(piv), gamma(LDLPivotConstant<Real>(piv)) { }
};
// Return the L (and D) from an LDL factorization of A (without pivoting)
// ----------------------------------------------------------------------
template<typename Field>
void LDL( Matrix<Field>& A, bool conjugate );
template<typename Field>
void LDL( AbstractDistMatrix<Field>& A, bool conjugate );
template<typename Field>
void LDL( DistMatrix<Field,STAR,STAR>& A, bool conjugate );
// Return an implicit representation of a pivoted LDL factorization of A
// ---------------------------------------------------------------------
template<typename Field>
void LDL
( Matrix<Field>& A,
Matrix<Field>& dSub,
Permutation& P,
bool conjugate,
const LDLPivotCtrl<Base<Field>>& ctrl=LDLPivotCtrl<Base<Field>>() );
template<typename Field>
void LDL
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& dSub,
DistPermutation& P,
bool conjugate,
const LDLPivotCtrl<Base<Field>>& ctrl=LDLPivotCtrl<Base<Field>>() );
// All fronts of L are required to be initialized to the expansions of the
// original sparse matrix before calling LDL.
template<typename Field>
void LDL
( const ldl::NodeInfo& info,
ldl::Front<Field>& L,
LDLFrontType newType=LDL_2D );
template<typename Field>
void LDL
( const ldl::DistNodeInfo& info,
ldl::DistFront<Field>& L,
LDLFrontType newType=LDL_2D );
namespace ldl {
// Compute the inertia triplet of a Hermitian matrix's LDL^H factorization
// -----------------------------------------------------------------------
template<typename Field>
InertiaType Inertia
( const Matrix<Base<Field>>& d,
const Matrix<Field>& dSub );
template<typename Field>
InertiaType Inertia
( const AbstractDistMatrix<Base<Field>>& d,
const AbstractDistMatrix<Field>& dSub );
// Multiply vectors using an implicit representation of an LDL factorization
// -------------------------------------------------------------------------
template<typename Field>
void MultiplyAfter
( const Matrix<Field>& A,
Matrix<Field>& B,
bool conjugated );
template<typename Field>
void MultiplyAfter
( const AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& B,
bool conjugated );
// Multiply vectors using an implicit representation of a pivoted LDL fact.
// ------------------------------------------------------------------------
template<typename Field>
void MultiplyAfter
( const Matrix<Field>& A,
const Matrix<Field>& dSub,
const Permutation& P,
Matrix<Field>& B,
bool conjugated );
template<typename Field>
void MultiplyAfter
( const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& dSub,
const DistPermutation& P,
AbstractDistMatrix<Field>& B,
bool conjugated );
// Solve linear systems using an implicit LDL factorization
// --------------------------------------------------------
template<typename Field>
void SolveAfter
( const Matrix<Field>& A,
Matrix<Field>& B,
bool conjugated );
template<typename Field>
void SolveAfter
( const AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& B,
bool conjugated );
// Solve linear system with the implicit representations of L, D, and P
// --------------------------------------------------------------------
template<typename Field>
void SolveAfter
( const Matrix<Field>& A,
const Matrix<Field>& dSub,
const Permutation& P,
Matrix<Field>& B,
bool conjugated );
template<typename Field>
void SolveAfter
( const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& dSub,
const DistPermutation& P,
AbstractDistMatrix<Field>& B,
bool conjugated );
} // namespace ldl
// Solve a linear system with a regularized factorization
// ======================================================
enum RegSolveAlg
{
REG_SOLVE_FGMRES,
REG_SOLVE_LGMRES
};
template<typename Real>
struct RegSolveCtrl
{
RegSolveAlg alg=REG_SOLVE_FGMRES;
Real relTol;
Real relTolRefine;
Int maxIts=4;
Int maxRefineIts=2;
Int restart=4;
bool progress=false;
bool time=false;
RegSolveCtrl()
{
const Real eps = limits::Epsilon<Real>();
relTol = Pow(eps,Real(0.5));
relTolRefine = Pow(eps,Real(0.8));
}
};
namespace reg_ldl {
template<typename Field>
Int RegularizedSolveAfter
( const SparseMatrix<Field>& A,
const Matrix<Base<Field>>& reg,
const SparseLDLFactorization<Field>& sparseLDLFact,
Matrix<Field>& B,
Base<Field> relTolRefine,
Int maxRefineIts,
bool progress=false,
bool time=false );
template<typename Field>
Int RegularizedSolveAfter
( const DistSparseMatrix<Field>& A,
const DistMultiVec<Base<Field>>& reg,
const DistSparseLDLFactorization<Field>& sparseLDLFact,
DistMultiVec<Field>& B,
Base<Field> relTolRefine,
Int maxRefineIts,
bool progress=false,
bool time=false );
template<typename Field>
Int RegularizedSolveAfter
( const SparseMatrix<Field>& A,
const Matrix<Base<Field>>& reg,
const Matrix<Base<Field>>& d,
const SparseLDLFactorization<Field>& sparseLDLFact,
Matrix<Field>& B,
Base<Field> relTolRefine,
Int maxRefineIts,
bool progress=false,
bool time=false );
template<typename Field>
Int RegularizedSolveAfter
( const DistSparseMatrix<Field>& A,
const DistMultiVec<Base<Field>>& reg,
const DistMultiVec<Base<Field>>& d,
const DistSparseLDLFactorization<Field>& sparseLDLFact,
DistMultiVec<Field>& B,
Base<Field> relTolRefine,
Int maxRefineIts,
bool progress=false,
bool time=false );
template<typename Field>
Int SolveAfter
( const SparseMatrix<Field>& A,
const Matrix<Base<Field>>& reg,
const SparseLDLFactorization<Field>& sparseLDLFact,
Matrix<Field>& B,
const RegSolveCtrl<Base<Field>>& ctrl );
template<typename Field>
Int SolveAfter
( const DistSparseMatrix<Field>& A,
const DistMultiVec<Base<Field>>& reg,
const DistSparseLDLFactorization<Field>& sparseLDLFact,
DistMultiVec<Field>& B,
const RegSolveCtrl<Base<Field>>& ctrl );
template<typename Field>
Int SolveAfter
( const SparseMatrix<Field>& A,
const Matrix<Base<Field>>& reg,
const Matrix<Base<Field>>& d,
const SparseLDLFactorization<Field>& sparseLDLFact,
Matrix<Field>& B,
const RegSolveCtrl<Base<Field>>& ctrl );
template<typename Field>
Int SolveAfter
( const DistSparseMatrix<Field>& A,
const DistMultiVec<Base<Field>>& reg,
const DistMultiVec<Base<Field>>& d,
const DistSparseLDLFactorization<Field>& sparseLDLFact,
DistMultiVec<Field>& B,
const RegSolveCtrl<Base<Field>>& ctrl );
} // namespace reg_ldl
// LU
// ==
// NOTE: This is not yet made use of, but the fully-pivoted version of LU
// should (soon?) accept it as an argument and potentially return one or
// more of the permutation matrices as the identity
namespace LUPivotTypeNS {
enum LUPivotType
{
LU_PARTIAL,
LU_FULL,
LU_ROOK, /* not yet supported */
LU_WITHOUT_PIVOTING
};
}
using namespace LUPivotTypeNS;
// LU without pivoting
// -------------------
template<typename Field>
void LU( Matrix<Field>& A );
template<typename Field>
void LU( AbstractDistMatrix<Field>& A );
template<typename Field>
void LU( DistMatrix<Field,STAR,STAR>& A );
// LU with partial pivoting
// ------------------------
template<typename Field>
void LU( Matrix<Field>& A, Permutation& P );
template<typename Field>
void LU( AbstractDistMatrix<Field>& A, DistPermutation& P );
// LU with full pivoting
// ---------------------
// P A Q^T = L U
template<typename Field>
void LU
( Matrix<Field>& A,
Permutation& P,
Permutation& Q );
template<typename Field>
void LU
( AbstractDistMatrix<Field>& A,
DistPermutation& P,
DistPermutation& Q );
// Low-rank modification of a partially-pivoted LU factorization
// -------------------------------------------------------------
// NOTE: This routine currently performs a sequence of rank-one updates
// and will eventually be generalized to a (much faster) single-pass
// algorithm.
template<typename Field>
void LUMod
( Matrix<Field>& A,
Permutation& P,
const Matrix<Field>& U,
const Matrix<Field>& V,
bool conjugate=true,
Base<Field> tau=Base<Field>(1)/Base<Field>(10) );
template<typename Field>
void LUMod
( AbstractDistMatrix<Field>& A,
DistPermutation& P,
const AbstractDistMatrix<Field>& U,
const AbstractDistMatrix<Field>& V,
bool conjugate=true,
Base<Field> tau=Base<Field>(1)/Base<Field>(10) );
namespace lu {
// Solve linear systems using an implicit unpivoted LU factorization
// -----------------------------------------------------------------
template<typename Field>
void SolveAfter
( Orientation orientation,
const Matrix<Field>& A,
Matrix<Field>& B );
template<typename Field>
void SolveAfter
( Orientation orientation,
const AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& B );
// Solve linear systems using an implicit partially-pivoted LU factorization
// -------------------------------------------------------------------------
template<typename Field>
void SolveAfter
( Orientation orientation,
const Matrix<Field>& A,
const Permutation& P,
Matrix<Field>& B );
template<typename Field>
void SolveAfter
( Orientation orientation,
const AbstractDistMatrix<Field>& A,
const DistPermutation& P,
AbstractDistMatrix<Field>& B );
// Solve linear systems using an implicit fully-pivoted LU factorization
// ---------------------------------------------------------------------
template<typename Field>
void SolveAfter
( Orientation orientation,
const Matrix<Field>& A,
const Permutation& P,
const Permutation& Q,
Matrix<Field>& B );
template<typename Field>
void SolveAfter
( Orientation orientation,
const AbstractDistMatrix<Field>& A,
const DistPermutation& P,
const DistPermutation& Q,
AbstractDistMatrix<Field>& B );
} // namespace lu
// LQ
// ==
// Overwrite A with both L and the scaled Householder vectors
// ----------------------------------------------------------
template<typename Field>
void LQ
( Matrix<Field>& A,
Matrix<Field>& householderScalars,
Matrix<Base<Field>>& signature );
template<typename Field>
void LQ
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& householderScalars,
AbstractDistMatrix<Base<Field>>& signature );
namespace lq {
// Apply Q using its implicit representation
// -----------------------------------------
template<typename Field>
void ApplyQ
( LeftOrRight side, Orientation orientation,
const Matrix<Field>& A,
const Matrix<Field>& householderScalars,
const Matrix<Base<Field>>& signature,
Matrix<Field>& B );
template<typename Field>
void ApplyQ
( LeftOrRight side, Orientation orientation,
const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& householderScalars,
const AbstractDistMatrix<Base<Field>>& signature,
AbstractDistMatrix<Field>& B );
// Solve a linear system with the implicit representations of L and Q
// ------------------------------------------------------------------
template<typename Field>
void SolveAfter
( Orientation orientation,
const Matrix<Field>& A,
const Matrix<Field>& householderScalars,
const Matrix<Base<Field>>& signature,
const Matrix<Field>& B,
Matrix<Field>& X );
template<typename Field>
void SolveAfter
( Orientation orientation,
const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& householderScalars,
const AbstractDistMatrix<Base<Field>>& signature,
const AbstractDistMatrix<Field>& B,
AbstractDistMatrix<Field>& X );
// Overwrite A with L
// ------------------
template<typename Field>
void ExplicitTriang( Matrix<Field>& A );
template<typename Field>
void ExplicitTriang( AbstractDistMatrix<Field>& A );
// Overwrite A with Q
// ------------------
template<typename Field>
void ExplicitUnitary( Matrix<Field>& A );
template<typename Field>
void ExplicitUnitary( AbstractDistMatrix<Field>& A );
// Return both L and Q such that A = L Q
// -------------------------------------
template<typename Field>
void Explicit( Matrix<Field>& L, Matrix<Field>& A );
template<typename Field>
void Explicit( AbstractDistMatrix<Field>& L, AbstractDistMatrix<Field>& A );
} // namespace lq
// QR factorization
// ================
template<typename Real>
struct QRCtrl
{
bool colPiv=false;
bool boundRank=false;
Int maxRank=0;
bool adaptive=false;
Real tol=Real(0);
bool alwaysRecomputeNorms=false;
// Selecting for the smallest norm first is an important preprocessing
// step for LLL suggested by Wubben et al.
//
// Ideally a black-box reduction operation could be provided by the user
// instead, as it is often the case that one may desire a custom pivoting
// rule.
bool smallestFirst=false;
};
// Return an implicit representation of Q and R such that A = Q R
// --------------------------------------------------------------
template<typename Field>
void QR
( Matrix<Field>& A,
Matrix<Field>& householderScalars,
Matrix<Base<Field>>& signature );
template<typename Field>
void QR
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& householderScalars,
AbstractDistMatrix<Base<Field>>& signature );
// Return an implicit representation of (Q,R,Omega) such that A Omega^T ~= Q R
// ---------------------------------------------------------------------------
template<typename Field>
void QR
( Matrix<Field>& A,
Matrix<Field>& householderScalars,
Matrix<Base<Field>>& signature,
Permutation& Omega,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void QR
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& householderScalars,
AbstractDistMatrix<Base<Field>>& signature,
DistPermutation& Omega,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
namespace qr {
// Apply Q using its implicit representation
// -----------------------------------------
template<typename Field>
void ApplyQ
( LeftOrRight side,
Orientation orientation,
const Matrix<Field>& A,
const Matrix<Field>& householderScalars,
const Matrix<Base<Field>>& signature,
Matrix<Field>& B );
template<typename Field>
void ApplyQ
( LeftOrRight side,
Orientation orientation,
const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& householderScalars,
const AbstractDistMatrix<Base<Field>>& signature,
AbstractDistMatrix<Field>& B );
// Solve a linear system with the implicit QR factorization
// --------------------------------------------------------
template<typename Field>
void SolveAfter
( Orientation orientation,
const Matrix<Field>& A,
const Matrix<Field>& householderScalars,
const Matrix<Base<Field>>& signature,
const Matrix<Field>& B,
Matrix<Field>& X );
template<typename Field>
void SolveAfter
( Orientation orientation,
const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& householderScalars,
const AbstractDistMatrix<Base<Field>>& signature,
const AbstractDistMatrix<Field>& B,
AbstractDistMatrix<Field>& X );
// TODO(poulson): Version which involves permutation matrix
// Cholesky-based QR
// -----------------
template<typename Field>
void Cholesky( Matrix<Field>& A, Matrix<Field>& R );
template<typename Field>
void Cholesky( AbstractDistMatrix<Field>& A, AbstractDistMatrix<Field>& R );
// Return R (with non-negative diagonal) such that A = Q R or A Omega^T = Q R
// --------------------------------------------------------------------------
template<typename Field>
void ExplicitTriang
( Matrix<Field>& A,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void ExplicitTriang
( AbstractDistMatrix<Field>& A,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
// Return Q such that either A = Q R or A Omega^T = Q R
// ----------------------------------------------------
template<typename Field>
void ExplicitUnitary
( Matrix<Field>& A,
bool thinQ=true,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void ExplicitUnitary
( AbstractDistMatrix<Field>& A,
bool thinQ=true,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
// Return both Q and R such that A = Q R or A Omega^T = Q R
// --------------------------------------------------------
template<typename Field>
void Explicit
( Matrix<Field>& A,
Matrix<Field>& R,
bool thinQ=true,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void Explicit
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& R,
bool thinQ=true,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
// Return (Q,R,Omega) such that A Omega^T = Q R
// --------------------------------------------
// NOTE: Column-pivoting is performed regardless of the value of ctrl.colPiv
template<typename Field>
void Explicit
( Matrix<Field>& A,
Matrix<Field>& R,
Matrix<Int>& Omega,
bool thinQ=true,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void Explicit
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& R,
AbstractDistMatrix<Int>& Omega,
bool thinQ=true,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
// Swap neighboring columns (j,j+1) and update the QR factorization
// ----------------------------------------------------------------
template<typename Field>
void NeighborColSwap
( Matrix<Field>& Q,
Matrix<Field>& R,
Int j );
// Swap disjoint sets of neighboring columns and update the QR factorization
// -------------------------------------------------------------------------
template<typename Field>
void DisjointNeighborColSwaps
( Matrix<Field>& Q,
Matrix<Field>& R,
const Matrix<Int>& colSwaps );
template<typename Field>
struct TreeData
{
Matrix<Field> QR0, householderScalars0;
Matrix<Base<Field>> signature0;
vector<Matrix<Field>> QRList;
vector<Matrix<Field>> householderScalarsList;
vector<Matrix<Base<Field>>> signatureList;
TreeData( Int numStages=0 )
: QRList(numStages),
householderScalarsList(numStages),
signatureList(numStages)
{ }
TreeData( TreeData<Field>&& treeData )
: QR0(move(treeData.QR0)),
householderScalars0(move(treeData.householderScalars0)),
signature0(move(treeData.signature0)),
QRList(move(treeData.QRList)),
householderScalarsList(move(treeData.householderScalarsList)),
signatureList(move(treeData.signatureList))
{ }
TreeData<Field>& operator=( TreeData<Field>&& treeData )
{
QR0 = move(treeData.QR0);
householderScalars0 = move(treeData.householderScalars0);
signature0 = move(treeData.signature0);
QRList = move(treeData.QRList);
householderScalarsList = move(treeData.householderScalarsList);
signatureList = move(treeData.signatureList);
return *this;
}
};
// Return an implicit tall-skinny QR factorization
template<typename Field>
TreeData<Field> TS( const AbstractDistMatrix<Field>& A );
// Return an explicit tall-skinny QR factorization
template<typename Field>
void ExplicitTS( AbstractDistMatrix<Field>& A, AbstractDistMatrix<Field>& R );
namespace ts {
template<typename Field>
Matrix<Field>& RootQR
( const AbstractDistMatrix<Field>& A, TreeData<Field>& treeData );
template<typename Field>
const Matrix<Field>& RootQR
( const AbstractDistMatrix<Field>& A, const TreeData<Field>& treeData );
template<typename Field>
void Reduce( const AbstractDistMatrix<Field>& A, TreeData<Field>& treeData );
template<typename Field>
void Scatter( AbstractDistMatrix<Field>& A, const TreeData<Field>& treeData );
} // namespace ts
} // namespace qr
// RQ
// ==
template<typename Field>
void RQ
( Matrix<Field>& A,
Matrix<Field>& householderScalars,
Matrix<Base<Field>>& signature );
template<typename Field>
void RQ
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& householderScalars,
AbstractDistMatrix<Base<Field>>& signature );
namespace rq {
template<typename Field>
void ApplyQ
( LeftOrRight side,
Orientation orientation,
const Matrix<Field>& A,
const Matrix<Field>& householderScalars,
const Matrix<Base<Field>>& signature,
Matrix<Field>& B );
template<typename Field>
void ApplyQ
( LeftOrRight side,
Orientation orientation,
const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& householderScalars,
const AbstractDistMatrix<Base<Field>>& signature,
AbstractDistMatrix<Field>& B );
template<typename Field>
void SolveAfter
( Orientation orientation,
const Matrix<Field>& A,
const Matrix<Field>& householderScalars,
const Matrix<Base<Field>>& signature,
const Matrix<Field>& B,
Matrix<Field>& X );
template<typename Field>
void SolveAfter
( Orientation orientation,
const AbstractDistMatrix<Field>& A,
const AbstractDistMatrix<Field>& householderScalars,
const AbstractDistMatrix<Base<Field>>& signature,
const AbstractDistMatrix<Field>& B,
AbstractDistMatrix<Field>& X );
// TODO(poulson): Think about ensuring this ordering is consistent with
// lq::Explicit
template<typename Field>
void Cholesky( Matrix<Field>& A, Matrix<Field>& R );
template<typename Field>
void Cholesky( AbstractDistMatrix<Field>& A, AbstractDistMatrix<Field>& R );
template<typename Field>
void ExplicitTriang( Matrix<Field>& A );
template<typename Field>
void ExplicitTriang( AbstractDistMatrix<Field>& A );
} // namespace rq
// Generalized QR
// ==============
template<typename Field>
void GQR
( Matrix<Field>& A,
Matrix<Field>& householderScalarsA,
Matrix<Base<Field>>& signatureA,
Matrix<Field>& B,
Matrix<Field>& householderScalarsB,
Matrix<Base<Field>>& signatureB );
template<typename Field>
void GQR
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& householderScalarsA,
AbstractDistMatrix<Base<Field>>& signatureA,
AbstractDistMatrix<Field>& B,
AbstractDistMatrix<Field>& householderScalarsB,
AbstractDistMatrix<Base<Field>>& signatureB );
namespace gqr {
template<typename Field>
void ExplicitTriang( Matrix<Field>& A, Matrix<Field>& B );
template<typename Field>
void ExplicitTriang
( AbstractDistMatrix<Field>& A, AbstractDistMatrix<Field>& B );
} // namespace gqr
// Generalized RQ
// ==============
template<typename Field>
void GRQ
( Matrix<Field>& A,
Matrix<Field>& householderScalarsA,
Matrix<Base<Field>>& signatureA,
Matrix<Field>& B,
Matrix<Field>& householderScalarsB,
Matrix<Base<Field>>& signatureB );
template<typename Field>
void GRQ
( AbstractDistMatrix<Field>& A,
AbstractDistMatrix<Field>& householderScalarsA,
AbstractDistMatrix<Base<Field>>& signatureA,
AbstractDistMatrix<Field>& B,
AbstractDistMatrix<Field>& householderScalarsB,
AbstractDistMatrix<Base<Field>>& signatureB );
namespace grq {
template<typename Field>
void ExplicitTriang( Matrix<Field>& A, Matrix<Field>& B );
template<typename Field>
void ExplicitTriang
( AbstractDistMatrix<Field>& A, AbstractDistMatrix<Field>& B );
} // namespace grq
// Interpolative Decomposition
// ===========================
template<typename Field>
void ID
( const Matrix<Field>& A,
Permutation& P,
Matrix<Field>& Z,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void ID
( const AbstractDistMatrix<Field>& A,
DistPermutation& P,
AbstractDistMatrix<Field>& Z,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void ID
( Matrix<Field>& A,
Permutation& P,
Matrix<Field>& Z,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>(),
bool canOverwrite=false );
template<typename Field>
void ID
( AbstractDistMatrix<Field>& A,
DistPermutation& P,
AbstractDistMatrix<Field>& Z,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>(),
bool canOverwrite=false );
// Skeleton
// ========
template<typename Field>
void Skeleton
( const Matrix<Field>& A,
Permutation& PR,
Permutation& PC,
Matrix<Field>& Z,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
template<typename Field>
void Skeleton
( const AbstractDistMatrix<Field>& A,
DistPermutation& PR,
DistPermutation& PC,
AbstractDistMatrix<Field>& Z,
const QRCtrl<Base<Field>>& ctrl=QRCtrl<Base<Field>>() );
} // namespace El
#include <El/lapack_like/factor/qr/ProxyHouseholder.hpp>
#endif // ifndef EL_FACTOR_HPP