/
solvers.cs
executable file
·15568 lines (13495 loc) · 622 KB
/
solvers.cs
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
/*************************************************************************
ALGLIB 4.00.0 (source code generated 2023-05-21)
Copyright (c) Sergey Bochkanov (ALGLIB project).
>>> SOURCE LICENSE >>>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation (www.fsf.org); either version 2 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
A copy of the GNU General Public License is available at
http://www.fsf.org/licensing/licenses
>>> END OF LICENSE >>>
*************************************************************************/
#pragma warning disable 1691
#pragma warning disable 162
#pragma warning disable 164
#pragma warning disable 219
#pragma warning disable 8981
using System;
public partial class alglib
{
/*************************************************************************
*************************************************************************/
public class polynomialsolverreport : alglibobject
{
//
// Public declarations
//
public double maxerr { get { return _innerobj.maxerr; } set { _innerobj.maxerr = value; } }
public polynomialsolverreport()
{
_innerobj = new polynomialsolver.polynomialsolverreport();
}
public override alglib.alglibobject make_copy()
{
return new polynomialsolverreport((polynomialsolver.polynomialsolverreport)_innerobj.make_copy());
}
//
// Although some of declarations below are public, you should not use them
// They are intended for internal use only
//
private polynomialsolver.polynomialsolverreport _innerobj;
public polynomialsolver.polynomialsolverreport innerobj { get { return _innerobj; } }
public polynomialsolverreport(polynomialsolver.polynomialsolverreport obj)
{
_innerobj = obj;
}
}
/*************************************************************************
Polynomial root finding.
This function returns all roots of the polynomial
P(x) = a0 + a1*x + a2*x^2 + ... + an*x^n
Both real and complex roots are returned (see below).
INPUT PARAMETERS:
A - array[N+1], polynomial coefficients:
* A[0] is constant term
* A[N] is a coefficient of X^N
N - polynomial degree
OUTPUT PARAMETERS:
X - array of complex roots:
* for isolated real root, X[I] is strictly real: IMAGE(X[I])=0
* complex roots are always returned in pairs - roots occupy
positions I and I+1, with:
* X[I+1]=Conj(X[I])
* IMAGE(X[I]) > 0
* IMAGE(X[I+1]) = -IMAGE(X[I]) < 0
* multiple real roots may have non-zero imaginary part due
to roundoff errors. There is no reliable way to distinguish
real root of multiplicity 2 from two complex roots in
the presence of roundoff errors.
Rep - report, additional information, following fields are set:
* Rep.MaxErr - max( |P(xi)| ) for i=0..N-1. This field
allows to quickly estimate "quality" of the roots being
returned.
NOTE: this function uses companion matrix method to find roots. In case
internal EVD solver fails do find eigenvalues, exception is
generated.
NOTE: roots are not "polished" and no matrix balancing is performed
for them.
-- ALGLIB --
Copyright 24.02.2014 by Bochkanov Sergey
*************************************************************************/
public static void polynomialsolve(double[] a, int n, out complex[] x, out polynomialsolverreport rep)
{
x = new complex[0];
rep = new polynomialsolverreport();
polynomialsolver.polynomialsolve(a, n, ref x, rep.innerobj, null);
}
public static void polynomialsolve(double[] a, int n, out complex[] x, out polynomialsolverreport rep, alglib.xparams _params)
{
x = new complex[0];
rep = new polynomialsolverreport();
polynomialsolver.polynomialsolve(a, n, ref x, rep.innerobj, _params);
}
}
public partial class alglib
{
/*************************************************************************
*************************************************************************/
public class densesolverreport : alglibobject
{
//
// Public declarations
//
public int terminationtype { get { return _innerobj.terminationtype; } set { _innerobj.terminationtype = value; } }
public double r1 { get { return _innerobj.r1; } set { _innerobj.r1 = value; } }
public double rinf { get { return _innerobj.rinf; } set { _innerobj.rinf = value; } }
public densesolverreport()
{
_innerobj = new directdensesolvers.densesolverreport();
}
public override alglib.alglibobject make_copy()
{
return new densesolverreport((directdensesolvers.densesolverreport)_innerobj.make_copy());
}
//
// Although some of declarations below are public, you should not use them
// They are intended for internal use only
//
private directdensesolvers.densesolverreport _innerobj;
public directdensesolvers.densesolverreport innerobj { get { return _innerobj; } }
public densesolverreport(directdensesolvers.densesolverreport obj)
{
_innerobj = obj;
}
}
/*************************************************************************
*************************************************************************/
public class densesolverlsreport : alglibobject
{
//
// Public declarations
//
public int terminationtype { get { return _innerobj.terminationtype; } set { _innerobj.terminationtype = value; } }
public double r2 { get { return _innerobj.r2; } set { _innerobj.r2 = value; } }
public double[,] cx { get { return _innerobj.cx; } set { _innerobj.cx = value; } }
public int n { get { return _innerobj.n; } set { _innerobj.n = value; } }
public int k { get { return _innerobj.k; } set { _innerobj.k = value; } }
public densesolverlsreport()
{
_innerobj = new directdensesolvers.densesolverlsreport();
}
public override alglib.alglibobject make_copy()
{
return new densesolverlsreport((directdensesolvers.densesolverlsreport)_innerobj.make_copy());
}
//
// Although some of declarations below are public, you should not use them
// They are intended for internal use only
//
private directdensesolvers.densesolverlsreport _innerobj;
public directdensesolvers.densesolverlsreport innerobj { get { return _innerobj; } }
public densesolverlsreport(directdensesolvers.densesolverlsreport obj)
{
_innerobj = obj;
}
}
/*************************************************************************
Dense solver for A*x=b with N*N real matrix A and N*1 real vectorx x and
b. This is "slow-but-feature rich" version of the linear solver. Faster
version is RMatrixSolveFast() function.
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* iterative refinement
* O(N^3) complexity
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system
! and performs iterative refinement, which results in
! significant performance penalty when compared with "fast"
! version which just performs LU decomposition and calls
! triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations. It is also very significant on small matrices.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, RMatrixSolveFast() function.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
Rep - additional report, the following fields are set:
* rep.terminationtype >0 for success
-3 for badly conditioned matrix
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* rep.terminationtype>0 => solution
* rep.terminationtype=-3 => filled by zeros
! FREE EDITION OF ALGLIB:
!
! Free Edition of ALGLIB supports following important features for this
! function:
! * C++ version: x64 SIMD support using C++ intrinsics
! * C# version: x64 SIMD support using NET5/NetCore hardware intrinsics
!
! We recommend you to read 'Compiling ALGLIB' section of the ALGLIB
! Reference Manual in order to find out how to activate SIMD support
! in ALGLIB.
! COMMERCIAL EDITION OF ALGLIB:
!
! Commercial Edition of ALGLIB includes following important improvements
! of this function:
! * high-performance native backend with same C# interface (C# version)
! * multithreading support (C++ and C# versions)
! * hardware vendor (Intel) implementations of linear algebra primitives
! (C++ and C# versions, x86/x64 platform)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
public static void rmatrixsolve(double[,] a, int n, double[] b, out double[] x, out densesolverreport rep)
{
x = new double[0];
rep = new densesolverreport();
directdensesolvers.rmatrixsolve(a, n, b, ref x, rep.innerobj, null);
}
public static void rmatrixsolve(double[,] a, int n, double[] b, out double[] x, out densesolverreport rep, alglib.xparams _params)
{
x = new double[0];
rep = new densesolverreport();
directdensesolvers.rmatrixsolve(a, n, b, ref x, rep.innerobj, _params);
}
public static void rmatrixsolve(double[,] a, double[] b, out double[] x, out densesolverreport rep)
{
int n;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.len(b)))
throw new alglibexception("Error while calling 'rmatrixsolve': looks like one of arguments has wrong size");
x = new double[0];
rep = new densesolverreport();
n = ap.rows(a);
directdensesolvers.rmatrixsolve(a, n, b, ref x, rep.innerobj, null);
return;
}
public static void rmatrixsolve(double[,] a, double[] b, out double[] x, out densesolverreport rep, alglib.xparams _params)
{
int n;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.len(b)))
throw new alglibexception("Error while calling 'rmatrixsolve': looks like one of arguments has wrong size");
x = new double[0];
rep = new densesolverreport();
n = ap.rows(a);
directdensesolvers.rmatrixsolve(a, n, b, ref x, rep.innerobj, _params);
return;
}
/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where A is NxN non-denegerate
real matrix, x and b are vectors. This is a "fast" version of linear
solver which does NOT provide any additional functions like condition
number estimation or iterative refinement.
Algorithm features:
* efficient algorithm O(N^3) complexity
* no performance overhead from additional functionality
If you need condition number estimation or iterative refinement, use more
feature-rich version - RMatrixSolve().
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
B - array[N]:
* result=true => overwritten by solution
* result=false => filled by zeros
RETURNS:
True, if the system was solved
False, for an extremely badly conditioned or exactly singular system
! FREE EDITION OF ALGLIB:
!
! Free Edition of ALGLIB supports following important features for this
! function:
! * C++ version: x64 SIMD support using C++ intrinsics
! * C# version: x64 SIMD support using NET5/NetCore hardware intrinsics
!
! We recommend you to read 'Compiling ALGLIB' section of the ALGLIB
! Reference Manual in order to find out how to activate SIMD support
! in ALGLIB.
! COMMERCIAL EDITION OF ALGLIB:
!
! Commercial Edition of ALGLIB includes following important improvements
! of this function:
! * high-performance native backend with same C# interface (C# version)
! * multithreading support (C++ and C# versions)
! * hardware vendor (Intel) implementations of linear algebra primitives
! (C++ and C# versions, x86/x64 platform)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB --
Copyright 16.03.2015 by Bochkanov Sergey
*************************************************************************/
public static bool rmatrixsolvefast(double[,] a, int n, double[] b)
{
return directdensesolvers.rmatrixsolvefast(a, n, b, null);
}
public static bool rmatrixsolvefast(double[,] a, int n, double[] b, alglib.xparams _params)
{
return directdensesolvers.rmatrixsolvefast(a, n, b, _params);
}
public static bool rmatrixsolvefast(double[,] a, double[] b)
{
int n;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.len(b)))
throw new alglibexception("Error while calling 'rmatrixsolvefast': looks like one of arguments has wrong size");
n = ap.rows(a);
bool result = directdensesolvers.rmatrixsolvefast(a, n, b, null);
return result;
}
public static bool rmatrixsolvefast(double[,] a, double[] b, alglib.xparams _params)
{
int n;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.len(b)))
throw new alglibexception("Error while calling 'rmatrixsolvefast': looks like one of arguments has wrong size");
n = ap.rows(a);
bool result = directdensesolvers.rmatrixsolvefast(a, n, b, _params);
return result;
}
/*************************************************************************
Dense solver.
Similar to RMatrixSolve() but solves task with multiple right parts (where
b and x are NxM matrices). This is "slow-but-robust" version of linear
solver with additional functionality like condition number estimation.
There also exists faster version - RMatrixSolveMFast().
Algorithm features:
* automatic detection of degenerate cases
* condition number estimation
* optional iterative refinement
* O(N^3+M*N^2) complexity
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system
! and performs iterative refinement, which results in
! significant performance penalty when compared with "fast"
! version which just performs LU decomposition and calls
! triangular solver.
!
! This performance penalty is especially visible in the
! multithreaded mode, because both condition number estimation
! and iterative refinement are inherently sequential
! calculations. It also very significant on small matrices.
!
! Thus, if you need high performance and if you are pretty sure
! that your system is well conditioned, we strongly recommend
! you to use faster solver, RMatrixSolveMFast() function.
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
RFS - iterative refinement switch:
* True - refinement is used.
Less performance, more precision.
* False - refinement is not used.
More performance, less precision.
OUTPUT PARAMETERS
Rep - additional report, following fields are set:
* rep.terminationtype >0 for success
-3 for badly conditioned or exactly singular matrix
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* rep.terminationtype>0 => solution
* rep.terminationtype=-3 => filled by zeros
! FREE EDITION OF ALGLIB:
!
! Free Edition of ALGLIB supports following important features for this
! function:
! * C++ version: x64 SIMD support using C++ intrinsics
! * C# version: x64 SIMD support using NET5/NetCore hardware intrinsics
!
! We recommend you to read 'Compiling ALGLIB' section of the ALGLIB
! Reference Manual in order to find out how to activate SIMD support
! in ALGLIB.
! COMMERCIAL EDITION OF ALGLIB:
!
! Commercial Edition of ALGLIB includes following important improvements
! of this function:
! * high-performance native backend with same C# interface (C# version)
! * multithreading support (C++ and C# versions)
! * hardware vendor (Intel) implementations of linear algebra primitives
! (C++ and C# versions, x86/x64 platform)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
public static void rmatrixsolvem(double[,] a, int n, double[,] b, int m, bool rfs, out double[,] x, out densesolverreport rep)
{
x = new double[0,0];
rep = new densesolverreport();
directdensesolvers.rmatrixsolvem(a, n, b, m, rfs, ref x, rep.innerobj, null);
}
public static void rmatrixsolvem(double[,] a, int n, double[,] b, int m, bool rfs, out double[,] x, out densesolverreport rep, alglib.xparams _params)
{
x = new double[0,0];
rep = new densesolverreport();
directdensesolvers.rmatrixsolvem(a, n, b, m, rfs, ref x, rep.innerobj, _params);
}
public static void rmatrixsolvem(double[,] a, double[,] b, bool rfs, out double[,] x, out densesolverreport rep)
{
int n;
int m;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixsolvem': looks like one of arguments has wrong size");
x = new double[0,0];
rep = new densesolverreport();
n = ap.rows(a);
m = ap.cols(b);
directdensesolvers.rmatrixsolvem(a, n, b, m, rfs, ref x, rep.innerobj, null);
return;
}
public static void rmatrixsolvem(double[,] a, double[,] b, bool rfs, out double[,] x, out densesolverreport rep, alglib.xparams _params)
{
int n;
int m;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixsolvem': looks like one of arguments has wrong size");
x = new double[0,0];
rep = new densesolverreport();
n = ap.rows(a);
m = ap.cols(b);
directdensesolvers.rmatrixsolvem(a, n, b, m, rfs, ref x, rep.innerobj, _params);
return;
}
/*************************************************************************
Dense solver.
Similar to RMatrixSolve() but solves task with multiple right parts (where
b and x are NxM matrices). This is "fast" version of linear solver which
does NOT offer additional functions like condition number estimation or
iterative refinement.
Algorithm features:
* O(N^3+M*N^2) complexity
* no additional functionality, highest performance
INPUT PARAMETERS
A - array[0..N-1,0..N-1], system matrix
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
RFS - iterative refinement switch:
* True - refinement is used.
Less performance, more precision.
* False - refinement is not used.
More performance, less precision.
OUTPUT PARAMETERS
Rep - additional report, following fields are set:
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
B - array[N]:
* result=true => overwritten by solution
* result=false => filled by zeros
RETURNS:
True for well-conditioned matrix
False for extremely badly conditioned or exactly singular problem
! FREE EDITION OF ALGLIB:
!
! Free Edition of ALGLIB supports following important features for this
! function:
! * C++ version: x64 SIMD support using C++ intrinsics
! * C# version: x64 SIMD support using NET5/NetCore hardware intrinsics
!
! We recommend you to read 'Compiling ALGLIB' section of the ALGLIB
! Reference Manual in order to find out how to activate SIMD support
! in ALGLIB.
! COMMERCIAL EDITION OF ALGLIB:
!
! Commercial Edition of ALGLIB includes following important improvements
! of this function:
! * high-performance native backend with same C# interface (C# version)
! * multithreading support (C++ and C# versions)
! * hardware vendor (Intel) implementations of linear algebra primitives
! (C++ and C# versions, x86/x64 platform)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
public static bool rmatrixsolvemfast(double[,] a, int n, double[,] b, int m)
{
return directdensesolvers.rmatrixsolvemfast(a, n, b, m, null);
}
public static bool rmatrixsolvemfast(double[,] a, int n, double[,] b, int m, alglib.xparams _params)
{
return directdensesolvers.rmatrixsolvemfast(a, n, b, m, _params);
}
public static bool rmatrixsolvemfast(double[,] a, double[,] b)
{
int n;
int m;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixsolvemfast': looks like one of arguments has wrong size");
n = ap.rows(a);
m = ap.cols(b);
bool result = directdensesolvers.rmatrixsolvemfast(a, n, b, m, null);
return result;
}
public static bool rmatrixsolvemfast(double[,] a, double[,] b, alglib.xparams _params)
{
int n;
int m;
if( (ap.rows(a)!=ap.cols(a)) || (ap.rows(a)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixsolvemfast': looks like one of arguments has wrong size");
n = ap.rows(a);
m = ap.cols(b);
bool result = directdensesolvers.rmatrixsolvemfast(a, n, b, m, _params);
return result;
}
/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where A is NxN non-denegerate
real matrix given by its LU decomposition, x and b are real vectors. This
is "slow-but-robust" version of the linear LU-based solver. Faster version
is RMatrixLUSolveFast() function.
Algorithm features:
* automatic detection of degenerate cases
* O(N^2) complexity
* condition number estimation
No iterative refinement is provided because exact form of original matrix
is not known to subroutine. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in 10-15x performance penalty when compared
! with "fast" version which just calls triangular solver.
!
! This performance penalty is insignificant when compared with
! cost of large LU decomposition. However, if you call this
! function many times for the same left side, this overhead
! BECOMES significant. It also becomes significant for small-
! scale problems.
!
! In such cases we strongly recommend you to use faster solver,
! RMatrixLUSolveFast() function.
INPUT PARAMETERS
LUA - array[N,N], LU decomposition, RMatrixLU result
P - array[N], pivots array, RMatrixLU result
N - size of A
B - array[N], right part
OUTPUT PARAMETERS
Rep - additional report, the following fields are set:
* rep.terminationtype >0 for success
-3 for badly conditioned matrix
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N], it contains:
* rep.terminationtype>0 => solution
* rep.terminationtype=-3 => filled by zeros
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
public static void rmatrixlusolve(double[,] lua, int[] p, int n, double[] b, out double[] x, out densesolverreport rep)
{
x = new double[0];
rep = new densesolverreport();
directdensesolvers.rmatrixlusolve(lua, p, n, b, ref x, rep.innerobj, null);
}
public static void rmatrixlusolve(double[,] lua, int[] p, int n, double[] b, out double[] x, out densesolverreport rep, alglib.xparams _params)
{
x = new double[0];
rep = new densesolverreport();
directdensesolvers.rmatrixlusolve(lua, p, n, b, ref x, rep.innerobj, _params);
}
public static void rmatrixlusolve(double[,] lua, int[] p, double[] b, out double[] x, out densesolverreport rep)
{
int n;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)) || (ap.rows(lua)!=ap.len(b)))
throw new alglibexception("Error while calling 'rmatrixlusolve': looks like one of arguments has wrong size");
x = new double[0];
rep = new densesolverreport();
n = ap.rows(lua);
directdensesolvers.rmatrixlusolve(lua, p, n, b, ref x, rep.innerobj, null);
return;
}
public static void rmatrixlusolve(double[,] lua, int[] p, double[] b, out double[] x, out densesolverreport rep, alglib.xparams _params)
{
int n;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)) || (ap.rows(lua)!=ap.len(b)))
throw new alglibexception("Error while calling 'rmatrixlusolve': looks like one of arguments has wrong size");
x = new double[0];
rep = new densesolverreport();
n = ap.rows(lua);
directdensesolvers.rmatrixlusolve(lua, p, n, b, ref x, rep.innerobj, _params);
return;
}
/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where A is NxN non-denegerate
real matrix given by its LU decomposition, x and b are real vectors. This
is "fast-without-any-checks" version of the linear LU-based solver. Slower
but more robust version is RMatrixLUSolve() function.
Algorithm features:
* O(N^2) complexity
* fast algorithm without ANY additional checks, just triangular solver
INPUT PARAMETERS
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1], right part
OUTPUT PARAMETERS
B - array[N]:
* result=true => overwritten by solution
* result=false => filled by zeros
RETURNS:
True, if the system was solved
False, for an extremely badly conditioned or exactly singular system
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
public static bool rmatrixlusolvefast(double[,] lua, int[] p, int n, double[] b)
{
return directdensesolvers.rmatrixlusolvefast(lua, p, n, b, null);
}
public static bool rmatrixlusolvefast(double[,] lua, int[] p, int n, double[] b, alglib.xparams _params)
{
return directdensesolvers.rmatrixlusolvefast(lua, p, n, b, _params);
}
public static bool rmatrixlusolvefast(double[,] lua, int[] p, double[] b)
{
int n;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)))
throw new alglibexception("Error while calling 'rmatrixlusolvefast': looks like one of arguments has wrong size");
n = ap.rows(lua);
bool result = directdensesolvers.rmatrixlusolvefast(lua, p, n, b, null);
return result;
}
public static bool rmatrixlusolvefast(double[,] lua, int[] p, double[] b, alglib.xparams _params)
{
int n;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)))
throw new alglibexception("Error while calling 'rmatrixlusolvefast': looks like one of arguments has wrong size");
n = ap.rows(lua);
bool result = directdensesolvers.rmatrixlusolvefast(lua, p, n, b, _params);
return result;
}
/*************************************************************************
Dense solver.
Similar to RMatrixLUSolve() but solves task with multiple right parts
(where b and x are NxM matrices). This is "robust-but-slow" version of
LU-based solver which performs additional checks for non-degeneracy of
inputs (condition number estimation). If you need best performance, use
"fast-without-any-checks" version, RMatrixLUSolveMFast().
Algorithm features:
* automatic detection of degenerate cases
* O(M*N^2) complexity
* condition number estimation
No iterative refinement is provided because exact form of original matrix
is not known to subroutine. Use RMatrixSolve or RMatrixMixedSolve if you
need iterative refinement.
IMPORTANT: ! this function is NOT the most efficient linear solver provided
! by ALGLIB. It estimates condition number of linear system,
! which results in significant performance penalty when
! compared with "fast" version which just calls triangular
! solver.
!
! This performance penalty is especially apparent when you use
! ALGLIB parallel capabilities (condition number estimation is
! inherently sequential). It also becomes significant for
! small-scale problems.
!
! In such cases we strongly recommend you to use faster solver,
! RMatrixLUSolveMFast() function.
INPUT PARAMETERS
LUA - array[N,N], LU decomposition, RMatrixLU result
P - array[N], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS
Rep - additional report, following fields are set:
* rep.terminationtype >0 for success
-3 for badly conditioned matrix
* rep.r1 condition number in 1-norm
* rep.rinf condition number in inf-norm
X - array[N,M], it contains:
* rep.terminationtype>0 => solution
* rep.terminationtype=-3 => filled by zeros
! FREE EDITION OF ALGLIB:
!
! Free Edition of ALGLIB supports following important features for this
! function:
! * C++ version: x64 SIMD support using C++ intrinsics
! * C# version: x64 SIMD support using NET5/NetCore hardware intrinsics
!
! We recommend you to read 'Compiling ALGLIB' section of the ALGLIB
! Reference Manual in order to find out how to activate SIMD support
! in ALGLIB.
! COMMERCIAL EDITION OF ALGLIB:
!
! Commercial Edition of ALGLIB includes following important improvements
! of this function:
! * high-performance native backend with same C# interface (C# version)
! * multithreading support (C++ and C# versions)
! * hardware vendor (Intel) implementations of linear algebra primitives
! (C++ and C# versions, x86/x64 platform)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB --
Copyright 27.01.2010 by Bochkanov Sergey
*************************************************************************/
public static void rmatrixlusolvem(double[,] lua, int[] p, int n, double[,] b, int m, out double[,] x, out densesolverreport rep)
{
x = new double[0,0];
rep = new densesolverreport();
directdensesolvers.rmatrixlusolvem(lua, p, n, b, m, ref x, rep.innerobj, null);
}
public static void rmatrixlusolvem(double[,] lua, int[] p, int n, double[,] b, int m, out double[,] x, out densesolverreport rep, alglib.xparams _params)
{
x = new double[0,0];
rep = new densesolverreport();
directdensesolvers.rmatrixlusolvem(lua, p, n, b, m, ref x, rep.innerobj, _params);
}
public static void rmatrixlusolvem(double[,] lua, int[] p, double[,] b, out double[,] x, out densesolverreport rep)
{
int n;
int m;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)) || (ap.rows(lua)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixlusolvem': looks like one of arguments has wrong size");
x = new double[0,0];
rep = new densesolverreport();
n = ap.rows(lua);
m = ap.cols(b);
directdensesolvers.rmatrixlusolvem(lua, p, n, b, m, ref x, rep.innerobj, null);
return;
}
public static void rmatrixlusolvem(double[,] lua, int[] p, double[,] b, out double[,] x, out densesolverreport rep, alglib.xparams _params)
{
int n;
int m;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)) || (ap.rows(lua)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixlusolvem': looks like one of arguments has wrong size");
x = new double[0,0];
rep = new densesolverreport();
n = ap.rows(lua);
m = ap.cols(b);
directdensesolvers.rmatrixlusolvem(lua, p, n, b, m, ref x, rep.innerobj, _params);
return;
}
/*************************************************************************
Dense solver.
Similar to RMatrixLUSolve() but solves task with multiple right parts,
where b and x are NxM matrices. This is "fast-without-any-checks" version
of LU-based solver. It does not estimate condition number of a system,
so it is extremely fast. If you need better detection of near-degenerate
cases, use RMatrixLUSolveM() function.
Algorithm features:
* O(M*N^2) complexity
* fast algorithm without ANY additional checks, just triangular solver
INPUT PARAMETERS:
LUA - array[0..N-1,0..N-1], LU decomposition, RMatrixLU result
P - array[0..N-1], pivots array, RMatrixLU result
N - size of A
B - array[0..N-1,0..M-1], right part
M - right part size
OUTPUT PARAMETERS:
B - array[N,M]:
* result=true => overwritten by solution
* result=false => filled by zeros
RETURNS:
True, if the system was solved
False, for an extremely badly conditioned or exactly singular system
! FREE EDITION OF ALGLIB:
!
! Free Edition of ALGLIB supports following important features for this
! function:
! * C++ version: x64 SIMD support using C++ intrinsics
! * C# version: x64 SIMD support using NET5/NetCore hardware intrinsics
!
! We recommend you to read 'Compiling ALGLIB' section of the ALGLIB
! Reference Manual in order to find out how to activate SIMD support
! in ALGLIB.
! COMMERCIAL EDITION OF ALGLIB:
!
! Commercial Edition of ALGLIB includes following important improvements
! of this function:
! * high-performance native backend with same C# interface (C# version)
! * multithreading support (C++ and C# versions)
! * hardware vendor (Intel) implementations of linear algebra primitives
! (C++ and C# versions, x86/x64 platform)
!
! We recommend you to read 'Working with commercial version' section of
! ALGLIB Reference Manual in order to find out how to use performance-
! related features provided by commercial edition of ALGLIB.
-- ALGLIB --
Copyright 18.03.2015 by Bochkanov Sergey
*************************************************************************/
public static bool rmatrixlusolvemfast(double[,] lua, int[] p, int n, double[,] b, int m)
{
return directdensesolvers.rmatrixlusolvemfast(lua, p, n, b, m, null);
}
public static bool rmatrixlusolvemfast(double[,] lua, int[] p, int n, double[,] b, int m, alglib.xparams _params)
{
return directdensesolvers.rmatrixlusolvemfast(lua, p, n, b, m, _params);
}
public static bool rmatrixlusolvemfast(double[,] lua, int[] p, double[,] b)
{
int n;
int m;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)) || (ap.rows(lua)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixlusolvemfast': looks like one of arguments has wrong size");
n = ap.rows(lua);
m = ap.cols(b);
bool result = directdensesolvers.rmatrixlusolvemfast(lua, p, n, b, m, null);
return result;
}
public static bool rmatrixlusolvemfast(double[,] lua, int[] p, double[,] b, alglib.xparams _params)
{
int n;
int m;
if( (ap.rows(lua)!=ap.cols(lua)) || (ap.rows(lua)!=ap.len(p)) || (ap.rows(lua)!=ap.rows(b)))
throw new alglibexception("Error while calling 'rmatrixlusolvemfast': looks like one of arguments has wrong size");
n = ap.rows(lua);
m = ap.cols(b);
bool result = directdensesolvers.rmatrixlusolvemfast(lua, p, n, b, m, _params);
return result;
}
/*************************************************************************
Dense solver.
This subroutine solves a system A*x=b, where BOTH ORIGINAL A AND ITS
LU DECOMPOSITION ARE KNOWN. You can use it if for some reasons you have
both A and its LU decomposition.
Algorithm features:
* automatic detection of degenerate cases