-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathAlgLibIterativeSolversTests.cs
More file actions
71 lines (60 loc) · 2.17 KB
/
Copy pathAlgLibIterativeSolversTests.cs
File metadata and controls
71 lines (60 loc) · 2.17 KB
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
using NUnit.Framework;
namespace AlgLibSamples
{
/*
* References:
* - http://www.alglib.net/translator/man/manual.csharp.html#example_linlsqr_d_1
*
* */
[TestFixture]
public class AlgLibIterativeSolversTests
{
[Test]
public void SimpleSample_Identity()
{
int m = 3;
int n = 3;
alglib.sparsematrix a;
alglib.sparsecreate(m, n, out a);
alglib.sparseset(a, 0, 0, 1.0);
alglib.sparseset(a, 1, 1, 1.0);
alglib.sparseset(a, 2, 2, 1.0);
alglib.sparseconverttocrs(a);
double[] b = { 4, 2, 3 };
alglib.linlsqrstate s;
alglib.linlsqrreport rep;
double[] x;
alglib.linlsqrcreate(a.innerobj.m, a.innerobj.n, out s);
alglib.linlsqrsolvesparse(s, a, b);
alglib.linlsqrresults(s, out x, out rep);
System.Console.WriteLine("{0}", rep.terminationtype); // EXPECTED: 4
System.Console.WriteLine("{0}", alglib.ap.format(x, 2)); // EXPECTED: [4.000, 2.000, 3.000]
}
[Test]
public void SimpleSample()
{
int m = 5;
int n = 2;
alglib.sparsematrix a;
alglib.sparsecreate(m, n, out a);
alglib.sparseset(a, 0, 0, 1.0);
alglib.sparseset(a, 0, 1, 1.0);
alglib.sparseset(a, 1, 0, 1.0);
alglib.sparseset(a, 1, 1, 1.0);
alglib.sparseset(a, 2, 0, 2.0);
alglib.sparseset(a, 2, 1, 1.0);
alglib.sparseset(a, 3, 0, 1.0);
alglib.sparseset(a, 4, 1, 1.0);
alglib.sparseconverttocrs(a);
double[] b = { 4, 2, 4, 1, 2 };
alglib.linlsqrstate s;
alglib.linlsqrreport rep;
double[] x;
alglib.linlsqrcreate(a.innerobj.m, a.innerobj.n, out s);
alglib.linlsqrsolvesparse(s, a, b);
alglib.linlsqrresults(s, out x, out rep);
System.Console.WriteLine("{0}", rep.terminationtype); // EXPECTED: 4
System.Console.WriteLine("{0}", alglib.ap.format(x, 2)); // EXPECTED: [1.000,2.000]
}
}
}