Browse Source

io: added matlab reader

matrix: added general version of matrix norms - need to add dense and sparse specific
la-knuth
Marcus Cuda 16 years ago
parent
commit
b06cfe4175
  1. BIN
      data/Matlab/A.mat
  2. BIN
      data/Matlab/collection-nocompress.mat
  3. BIN
      data/Matlab/collection.mat
  4. 15
      data/Matlab/matrices.txt
  5. BIN
      data/Matlab/sparse-large.mat
  6. BIN
      data/Matlab/sparse-small.mat
  7. BIN
      data/Matlab/v.mat
  8. 3804
      data/Matrices/bp___200.mtx
  9. 94
      data/Matrices/can24_pattern_symmetric_coordinate_24.mtx
  10. 208
      data/Matrices/gear_integer_general_coordinate_100.mtx
  11. 61
      data/Matrices/hilbert_real_symmetric_array_10.mtx
  12. 10010
      data/Matrices/random_real_general_array_100.mtx
  13. 207
      data/Matrices/random_real_general_array_10_20.mtx
  14. 207
      data/Matrices/random_real_general_array_20_10.mtx
  15. 58
      data/Matrices/random_real_general_coordinate_10_20.mtx
  16. 12
      data/Matrices/random_real_general_dense_10_20.comma
  17. 12
      data/Matrices/random_real_general_dense_10_20.space
  18. 12
      data/Matrices/random_real_general_dense_10_20.tab
  19. 121
      src/Numerics/LinearAlgebra/Common/IO/Matlab/ArrayClass.cs
  20. 54
      src/Numerics/LinearAlgebra/Common/IO/Matlab/ArrayFlags.cs
  21. 116
      src/Numerics/LinearAlgebra/Common/IO/Matlab/DataType.cs
  22. 218
      src/Numerics/LinearAlgebra/Double/IO/Matlab/MatlabFile.cs
  23. 535
      src/Numerics/LinearAlgebra/Double/IO/Matlab/MatlabParser.cs
  24. 189
      src/Numerics/LinearAlgebra/Double/IO/MatlabReader.cs
  25. 69
      src/Numerics/LinearAlgebra/Double/Matrix.cs
  26. 9
      src/Numerics/Numerics.csproj
  27. 54
      src/Numerics/Properties/Resources.Designer.cs
  28. 18
      src/Numerics/Properties/Resources.resx
  29. 70
      src/UnitTests/LinearAlgebraTests/Double/IO/MatlabReaderTests.cs
  30. 52
      src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs
  31. 26
      src/UnitTests/UnitTests.csproj

BIN
data/Matlab/A.mat

Binary file not shown.

BIN
data/Matlab/collection-nocompress.mat

Binary file not shown.

BIN
data/Matlab/collection.mat

Binary file not shown.

15
data/Matlab/matrices.txt

@ -0,0 +1,15 @@
sparse.mat contains:
* a sparse matrix S
* a sparse vector v
v.mat contains:
* a vector v
collection.mat contains:
* a matrix A
* a scalar t
* a vector v
* a vector w
A.mat contains:
* a matrix A

BIN
data/Matlab/sparse-large.mat

Binary file not shown.

BIN
data/Matlab/sparse-small.mat

Binary file not shown.

BIN
data/Matlab/v.mat

Binary file not shown.

3804
data/Matrices/bp___200.mtx

File diff suppressed because it is too large

94
data/Matrices/can24_pattern_symmetric_coordinate_24.mtx

@ -0,0 +1,94 @@
%%MatrixMarket matrix coordinate pattern symmetric
24 24 92
1 1
6 1
7 1
13 1
14 1
18 1
19 1
20 1
22 1
2 2
9 2
10 2
14 2
15 2
18 2
3 3
7 3
12 3
21 3
22 3
23 3
4 4
8 4
11 4
16 4
19 4
20 4
5 5
8 5
10 5
15 5
16 5
17 5
6 6
7 6
13 6
14 6
18 6
7 7
12 7
13 7
20 7
22 7
24 7
8 8
10 8
15 8
16 8
17 8
18 8
19 8
9 9
10 9
15 9
10 10
14 10
15 10
18 10
19 10
11 11
19 11
20 11
21 11
22 11
12 12
13 12
22 12
24 12
13 13
24 13
14 14
18 14
15 15
16 16
17 16
19 16
17 17
18 18
19 18
20 18
19 19
20 19
20 20
21 20
22 20
21 21
22 21
23 21
22 22
23 22
23 23
24 24

208
data/Matrices/gear_integer_general_coordinate_100.mtx

@ -0,0 +1,208 @@
%%MatrixMarket matrix coordinate integer general
%==============================================================
% A Gear matrix of order 100 with A[1,1]=1 and A[100,100]=1
% Generated by MatrixMarketDeli @ Thu Nov 17 16:19:13 EET 2005
%==============================================================
100 100 200
15 16 1
15 14 1
30 31 1
30 29 1
45 46 1
45 44 1
60 61 1
75 76 1
60 59 1
90 91 1
75 74 1
90 89 1
11 12 1
11 10 1
26 27 1
26 25 1
41 42 1
41 40 1
56 57 1
56 55 1
71 72 1
86 87 1
71 70 1
86 85 1
7 8 1
7 6 1
22 23 1
22 21 1
37 38 1
37 36 1
52 53 1
52 51 1
67 68 1
82 83 1
67 66 1
97 98 1
82 81 1
97 96 1
3 4 1
3 2 1
18 19 1
18 17 1
33 34 1
33 32 1
48 49 1
48 47 1
63 64 1
78 79 1
63 62 1
93 94 1
78 77 1
93 92 1
14 15 1
14 13 1
29 30 1
29 28 1
44 45 1
44 43 1
59 60 1
74 75 1
59 58 1
89 90 1
74 73 1
89 88 1
10 11 1
10 9 1
25 26 1
25 24 1
40 41 1
40 39 1
55 56 1
55 54 1
70 71 1
85 86 1
70 69 1
85 84 1
100 100 1
100 99 1
6 7 1
6 5 1
21 22 1
21 20 1
36 37 1
36 35 1
51 52 1
51 50 1
66 67 1
81 82 1
66 65 1
96 97 1
81 80 1
96 95 1
2 3 1
2 1 1
17 18 1
17 16 1
32 33 1
32 31 1
47 48 1
47 46 1
62 63 1
77 78 1
62 61 1
92 93 1
77 76 1
92 91 1
13 14 1
13 12 1
28 29 1
28 27 1
43 44 1
43 42 1
58 59 1
73 74 1
58 57 1
88 89 1
73 72 1
88 87 1
9 10 1
9 8 1
24 25 1
24 23 1
39 40 1
39 38 1
54 55 1
54 53 1
69 70 1
84 85 1
69 68 1
99 100 1
84 83 1
99 98 1
5 6 1
5 4 1
20 21 1
20 19 1
35 36 1
35 34 1
50 51 1
50 49 1
65 66 1
80 81 1
65 64 1
95 96 1
80 79 1
95 94 1
1 2 1
1 1 1
16 17 1
16 15 1
31 32 1
31 30 1
46 47 1
46 45 1
61 62 1
76 77 1
61 60 1
91 92 1
76 75 1
91 90 1
12 13 1
12 11 1
27 28 1
27 26 1
42 43 1
42 41 1
57 58 1
72 73 1
57 56 1
87 88 1
72 71 1
87 86 1
8 9 1
8 7 1
23 24 1
23 22 1
38 39 1
38 37 1
53 54 1
53 52 1
68 69 1
83 84 1
68 67 1
98 99 1
83 82 1
98 97 1
4 5 1
4 3 1
19 20 1
19 18 1
34 35 1
34 33 1
49 50 1
49 48 1
64 65 1
79 80 1
64 63 1
94 95 1
79 78 1
94 93 1

61
data/Matrices/hilbert_real_symmetric_array_10.mtx

@ -0,0 +1,61 @@
%%MatrixMarket matrix array real symmetric
%==============================================================
% The Hilbert matrix of order 10
% Generated by MatrixMarketDeli @ Fri Nov 11 17:33:11 EET 2005
%==============================================================
10 10
1.0000000000000E+0
5.0000000000000E-1
3.3333333333333E-1
2.5000000000000E-1
2.0000000000000E-1
1.6666666666667E-1
1.4285714285714E-1
1.2500000000000E-1
1.1111111111111E-1
1.0000000000000E-1
3.3333333333333E-1
2.5000000000000E-1
2.0000000000000E-1
1.6666666666667E-1
1.4285714285714E-1
1.2500000000000E-1
1.1111111111111E-1
1.0000000000000E-1
9.0909090909091E-2
2.0000000000000E-1
1.6666666666667E-1
1.4285714285714E-1
1.2500000000000E-1
1.1111111111111E-1
1.0000000000000E-1
9.0909090909091E-2
8.3333333333333E-2
1.4285714285714E-1
1.2500000000000E-1
1.1111111111111E-1
1.0000000000000E-1
9.0909090909091E-2
8.3333333333333E-2
7.6923076923077E-2
1.1111111111111E-1
1.0000000000000E-1
9.0909090909091E-2
8.3333333333333E-2
7.6923076923077E-2
7.1428571428571E-2
9.0909090909091E-2
8.3333333333333E-2
7.6923076923077E-2
7.1428571428571E-2
6.6666666666667E-2
7.6923076923077E-2
7.1428571428571E-2
6.6666666666667E-2
6.2500000000000E-2
6.6666666666667E-2
6.2500000000000E-2
5.8823529411765E-2
5.8823529411765E-2
5.5555555555556E-2
5.2631578947368E-2

10010
data/Matrices/random_real_general_array_100.mtx

File diff suppressed because it is too large

207
data/Matrices/random_real_general_array_10_20.mtx

@ -0,0 +1,207 @@
%%MatrixMarket matrix array real general
%==============================================================
% A Random 10x20 matrix with density = 1.0,
% elements from -100.0 to 100.0
% Generated by MatrixMarketDeli @ Fri Nov 11 17:06:08 EET 2005
%==============================================================
10 20
3.8657857973798E+1
-4.9614141943821E+0
9.8367529614337E+1
-8.2830239960130E+1
-4.8001834141995E+1
1.8538795105779E+0
8.8913280903105E+0
7.6433590250342E+1
3.9112716073559E+1
3.9887721176386E+0
7.1502475973519E+1
-6.2241679398193E+1
-1.9561929064987E+0
3.3027174343978E+1
2.4007135439120E+1
8.2689715275099E-1
-8.1632642030832E+1
4.9360457021864E+0
-7.6279897452783E+1
-7.4269842491989E+0
-8.6709742218175E+1
-2.3383344954355E+1
-9.6814601918678E+1
-8.9091848158775E+1
7.8756002367903E+1
7.5160409139558E+1
4.9821485912964E+1
-7.2203103442099E+1
-8.0841292407509E+1
8.8169658884781E+1
7.3532129439538E+1
-9.4881302335684E+1
5.8975431339973E+1
-9.6492050220299E+1
-7.9279553728695E+1
3.2251799109820E+1
5.9347462853748E+0
-5.9801269728711E+1
3.7113551592361E+1
-5.4025279935249E+0
8.5124240448279E+1
-5.0657034629351E+1
-6.7019266503368E+1
-1.7572213479782E+1
-4.1060590659680E+1
-3.7716876288734E+1
4.8472477178567E+1
8.7097993571157E-1
-7.1011388392340E+1
-5.9417485352436E+1
6.0302454220710E+1
7.2841896419677E+1
-8.0277608153256E+1
-5.3412553849684E+1
-5.1571106786546E+1
2.6798324194892E+1
8.7932790521780E+1
-2.7818093307886E+1
-1.5775292212287E+1
-2.1083512397918E+1
2.5065328021297E+1
7.6851803745298E+1
2.3727288271726E+1
-5.6135909760460E+1
9.7097165855923E+1
3.0818525947043E+1
-7.7399463045670E+1
-5.9195847420585E+1
-8.9907684389171E+1
-6.9317317811519E+1
5.4976526142004E+1
-5.7711254412963E+1
-4.2430488846026E+0
-9.8520336997919E+1
5.4207931936249E+1
-9.6502727928745E+1
-1.7731298536016E+1
6.5294704112545E+1
9.9852653099467E+1
5.1764551074441E+1
2.2030411483824E+1
6.3961999694411E-1
9.0490382297665E+1
9.4968452852052E+0
9.6691006175572E+1
4.4616403469871E+1
5.1962038778481E+1
2.6227755837799E+1
1.2501410937845E+1
-7.3032758436502E+1
-4.3799479222919E+1
-4.8823266783208E+1
4.8892028772484E+1
9.8005489461655E+1
-5.2275562868370E+1
1.4514592414139E+1
-1.1026075554457E+1
7.6577296847270E+1
2.6350906953621E+1
6.8136841733325E+1
5.7795535934622E+1
-6.4470860476650E+1
5.6283044025406E+1
-2.6583238106615E+1
5.7172990280152E+1
1.4839208716056E+1
-5.3063788768535E+1
-3.0677473549551E+1
6.8017669017893E+1
-5.3288687513339E+1
-3.3607082144278E+1
-1.7939974765680E+1
2.2957582823418E+1
-9.0407494201500E+1
2.1409839072464E+1
6.4922138455957E+1
-4.6327046291443E+1
5.3995656456756E+1
2.6505336221819E+1
-2.4511915982629E+1
9.1168047319635E+1
9.9716688040813E+1
9.8054707298386E+1
5.9887316030350E+1
7.8681744287464E+1
6.9897597029792E+1
-8.8787531253430E+1
2.7292048953501E+1
3.1927009684747E+0
-5.5726168695277E+1
-8.6693878979362E+1
-2.1397824828833E+1
8.1370822022098E+1
-1.7270794811094E+1
-8.1388223901884E+1
-1.8936484118800E+1
-4.2889927761586E+1
7.8482437781550E+1
7.7075325106993E+1
8.8869899961860E+1
-9.3232845693345E+1
6.1846976789257E+0
-6.6663261172111E+1
1.8474958322888E+1
2.3348744734824E+1
-7.4897068718330E+1
-5.7272836386936E+1
-9.1714308724696E+0
-8.6336407708615E+1
7.6778818041074E+1
-3.3445963164259E+0
4.3894137549737E+1
-6.1054965593620E+1
-8.1991824752178E+1
-8.8591774350639E+1
-3.1429357495994E+1
8.3046062122694E+1
3.4239494222753E+1
1.9727267992300E+1
-8.4478528341323E+1
6.2027033474417E+1
9.8545842876554E+1
-5.3286194233121E+1
-2.5677202022038E+0
-7.9209868876695E+1
6.5041073720403E+1
-1.5816965556759E+1
8.3696434105093E+1
-1.7212688574462E+1
-4.3479677766491E+1
-5.8324979805811E+1
9.2815617577040E+1
-2.6635511496726E+1
3.8968282841527E+1
7.6492961602756E+1
1.6117066567479E+1
6.7829313570147E+1
-4.8571588439503E+1
1.1974628549357E+1
4.1744016266844E+1
8.8861608890694E+1
-9.3820211873294E+1
-8.0039282550807E+1
-4.7286040976801E+0
2.7500658275720E+1
8.4074146022574E+0
2.9721652493472E+1
7.0202857515499E+1
-8.8525601516714E+1
8.3616547659693E+1
-3.0287777191142E+1
-3.6989943737820E+1
4.8802326734341E+1
-1.8370471958878E+1
6.4014835211960E+1
-9.7585733146856E+1
-5.8531696320096E+1
-8.7843304424702E+1
6.7934939698221E+1
-7.2342764125323E+1

207
data/Matrices/random_real_general_array_20_10.mtx

@ -0,0 +1,207 @@
%%MatrixMarket matrix array real general
%==============================================================
% A Random 20x10 matrix with density = 1.0,
% elements from -100.0 to 100.0
% Generated by MatrixMarketDeli @ Fri Nov 11 17:06:08 EET 2005
%==============================================================
20 10
3.8657857973798E+1
-4.9614141943821E+0
9.8367529614337E+1
-8.2830239960130E+1
-4.8001834141995E+1
1.8538795105779E+0
8.8913280903105E+0
7.6433590250342E+1
3.9112716073559E+1
3.9887721176386E+0
7.1502475973519E+1
-6.2241679398193E+1
-1.9561929064987E+0
3.3027174343978E+1
2.4007135439120E+1
8.2689715275099E-1
-8.1632642030832E+1
4.9360457021864E+0
-7.6279897452783E+1
-7.4269842491989E+0
-8.6709742218175E+1
-2.3383344954355E+1
-9.6814601918678E+1
-8.9091848158775E+1
7.8756002367903E+1
7.5160409139558E+1
4.9821485912964E+1
-7.2203103442099E+1
-8.0841292407509E+1
8.8169658884781E+1
7.3532129439538E+1
-9.4881302335684E+1
5.8975431339973E+1
-9.6492050220299E+1
-7.9279553728695E+1
3.2251799109820E+1
5.9347462853748E+0
-5.9801269728711E+1
3.7113551592361E+1
-5.4025279935249E+0
8.5124240448279E+1
-5.0657034629351E+1
-6.7019266503368E+1
-1.7572213479782E+1
-4.1060590659680E+1
-3.7716876288734E+1
4.8472477178567E+1
8.7097993571157E-1
-7.1011388392340E+1
-5.9417485352436E+1
6.0302454220710E+1
7.2841896419677E+1
-8.0277608153256E+1
-5.3412553849684E+1
-5.1571106786546E+1
2.6798324194892E+1
8.7932790521780E+1
-2.7818093307886E+1
-1.5775292212287E+1
-2.1083512397918E+1
2.5065328021297E+1
7.6851803745298E+1
2.3727288271726E+1
-5.6135909760460E+1
9.7097165855923E+1
3.0818525947043E+1
-7.7399463045670E+1
-5.9195847420585E+1
-8.9907684389171E+1
-6.9317317811519E+1
5.4976526142004E+1
-5.7711254412963E+1
-4.2430488846026E+0
-9.8520336997919E+1
5.4207931936249E+1
-9.6502727928745E+1
-1.7731298536016E+1
6.5294704112545E+1
9.9852653099467E+1
5.1764551074441E+1
2.2030411483824E+1
6.3961999694411E-1
9.0490382297665E+1
9.4968452852052E+0
9.6691006175572E+1
4.4616403469871E+1
5.1962038778481E+1
2.6227755837799E+1
1.2501410937845E+1
-7.3032758436502E+1
-4.3799479222919E+1
-4.8823266783208E+1
4.8892028772484E+1
9.8005489461655E+1
-5.2275562868370E+1
1.4514592414139E+1
-1.1026075554457E+1
7.6577296847270E+1
2.6350906953621E+1
6.8136841733325E+1
5.7795535934622E+1
-6.4470860476650E+1
5.6283044025406E+1
-2.6583238106615E+1
5.7172990280152E+1
1.4839208716056E+1
-5.3063788768535E+1
-3.0677473549551E+1
6.8017669017893E+1
-5.3288687513339E+1
-3.3607082144278E+1
-1.7939974765680E+1
2.2957582823418E+1
-9.0407494201500E+1
2.1409839072464E+1
6.4922138455957E+1
-4.6327046291443E+1
5.3995656456756E+1
2.6505336221819E+1
-2.4511915982629E+1
9.1168047319635E+1
9.9716688040813E+1
9.8054707298386E+1
5.9887316030350E+1
7.8681744287464E+1
6.9897597029792E+1
-8.8787531253430E+1
2.7292048953501E+1
3.1927009684747E+0
-5.5726168695277E+1
-8.6693878979362E+1
-2.1397824828833E+1
8.1370822022098E+1
-1.7270794811094E+1
-8.1388223901884E+1
-1.8936484118800E+1
-4.2889927761586E+1
7.8482437781550E+1
7.7075325106993E+1
8.8869899961860E+1
-9.3232845693345E+1
6.1846976789257E+0
-6.6663261172111E+1
1.8474958322888E+1
2.3348744734824E+1
-7.4897068718330E+1
-5.7272836386936E+1
-9.1714308724696E+0
-8.6336407708615E+1
7.6778818041074E+1
-3.3445963164259E+0
4.3894137549737E+1
-6.1054965593620E+1
-8.1991824752178E+1
-8.8591774350639E+1
-3.1429357495994E+1
8.3046062122694E+1
3.4239494222753E+1
1.9727267992300E+1
-8.4478528341323E+1
6.2027033474417E+1
9.8545842876554E+1
-5.3286194233121E+1
-2.5677202022038E+0
-7.9209868876695E+1
6.5041073720403E+1
-1.5816965556759E+1
8.3696434105093E+1
-1.7212688574462E+1
-4.3479677766491E+1
-5.8324979805811E+1
9.2815617577040E+1
-2.6635511496726E+1
3.8968282841527E+1
7.6492961602756E+1
1.6117066567479E+1
6.7829313570147E+1
-4.8571588439503E+1
1.1974628549357E+1
4.1744016266844E+1
8.8861608890694E+1
-9.3820211873294E+1
-8.0039282550807E+1
-4.7286040976801E+0
2.7500658275720E+1
8.4074146022574E+0
2.9721652493472E+1
7.0202857515499E+1
-8.8525601516714E+1
8.3616547659693E+1
-3.0287777191142E+1
-3.6989943737820E+1
4.8802326734341E+1
-1.8370471958878E+1
6.4014835211960E+1
-9.7585733146856E+1
-5.8531696320096E+1
-8.7843304424702E+1
6.7934939698221E+1
-7.2342764125323E+1

58
data/Matrices/random_real_general_coordinate_10_20.mtx

@ -0,0 +1,58 @@
%%MatrixMarket matrix coordinate real general
%==============================================================
% A Random 10x20 matrix with density = 0.25,
% elements from -100.0 to 100.0
% The diagonal is dense
% Generated by MatrixMarketDeli @ Fri Nov 11 17:22:08 EET 2005
%==============================================================
10 20 50
8 15 -4.6451483491123E+1
4 4 -2.8632063827819E+1
8 14 -1.5213706867772E+1
8 13 7.4423246543243E+1
8 12 2.7887491569201E+1
8 10 1.9460224390033E+1
8 9 9.7954330827189E+1
8 8 -4.9325070065588E+0
3 17 6.1642960953491E+1
8 3 2.0660149282608E+1
7 20 1.1013106124705E+1
3 8 3.6716745726295E+1
7 18 1.4931179559131E+1
3 4 7.9316548265485E+1
3 3 -2.5725327792433E+1
2 20 9.7109701061597E+1
7 7 -4.6585107832475E+1
2 13 -9.1085433962913E+1
7 1 -9.0521046010583E+1
2 10 -7.9900350891929E+1
2 6 -8.1978958323441E+1
6 16 4.6993511999238E+1
6 13 7.1058095783918E+1
2 2 -9.6846771057381E+1
1 19 -7.3290149915957E+1
10 19 3.2691966451159E+1
6 7 -3.8227481374005E+1
6 6 6.5087993662941E+1
1 15 7.0730096280286E+1
1 14 -4.8808933591076E+1
10 14 -2.6181143470241E+1
1 10 3.0692981751248E+0
10 11 -8.2875180734905E+0
10 10 1.3860350607799E+1
5 18 6.8804480264382E+0
1 6 -1.2859773597471E+1
1 5 -7.8567448719877E+1
5 14 1.4218193449585E+1
10 4 3.1661576533386E+1
1 2 8.0480008211576E+1
1 1 -9.4637595118467E+0
5 9 -8.1226636123555E+1
5 5 -5.7484307268815E+1
5 4 -1.8133543866265E+1
5 3 7.6645343914939E+1
9 13 8.5951254130729E+1
9 9 4.7959204407134E+1
9 6 -1.7574151541303E+1
4 13 -6.4767076502567E+1
9 1 -8.0637951259290E+1

12
data/Matrices/random_real_general_dense_10_20.comma

@ -0,0 +1,12 @@
82.38917250140915,66.46799821137029,-73.97365545078824,-95.31921313337975,-21.846680846362403,24.88547007112365,-25.865299859546667,10.336949242478795,-1.8972305626745083,-58.69281090645184,40.59540633021413,29.366537108425774,-65.555416486013,58.33261150589951,-21.512984674665134,-60.05349816749461,-71.69576759012608,-28.329728816399566,58.99962297286575,-58.13813415200328
-92.50717807374093,-82.70625429017943,-20.410516251452208,25.9852497102478,-13.074424970502463,-75.81380264681468,65.67168308152634,-77.22426410465941,-44.37656310765219,-88.85362200162008,-3.869540413370487,24.773907077654613,63.487545256790355,78.19931976538115,50.30949949551953,53.26517926577674,16.544000743427063,71.47522896677881,47.77740999067842,-29.271187577378967
-8.885651979830001,-15.009550413900527,32.046301346908564,-71.61457727836635,-14.6251745645027,-96.41542712163911,-64.4456874994869,82.10096455940729,-58.97460739147273,-11.661722888831434,-44.394362691753344,-89.89937133484982,-11.702766674811272,59.11653188176288,-30.405475164252323,22.39129523094232,94.28537645748202,38.452366418243145,22.722434197133154,-35.51347099206336
-72.39925296033682,86.80656289020808,-67.44960471721876,-13.026515416896345,91.59389848364387,-18.691036760387277,-27.88853255404662,-22.34376663235838,23.91043816114275,68.40744026653786,16.940882641757,-65.54443899898625,11.895885273301388,-44.57909383901271,71.2644337972327,94.94039533986543,-68.62426222347332,-3.187092927585482,-75.28163396436153,-67.68852908196209
80.59404861191172,-21.927115687319628,33.35685607311282,77.85305544886839,51.601887517862934,3.4122905747095302,-32.66398661676185,36.313965885768795,-41.855322967675626,53.05321393909486,-77.45385402005236,-76.62565696500063,-77.89465840528247,-8.292657315637712,54.596812842423816,-26.700011954666138,-90.18206036502391,-18.086466524875647,-39.05799437730564,40.081375053902434
5.074311855252006,84.22251608410437,-89.43434460315265,-53.20018066807546,7.404021249266805,-89.21248946077878,0.5304325953368902,-74.34152108887051,52.215785748562354,-60.26002900699521,-95.17438985467528,-64.93872162910426,-36.35370747867126,94.79990831767964,73.33262704119048,-59.681867558485415,71.47018389311609,47.89051587365097,-62.640271686852664,-98.99985453928473
50.182784823566294,12.097252271380526,83.07996571154416,20.66374964705308,-28.62505608952776,-41.86824532182081,65.33953691596301,-16.391857185520237,-0.22278619568626823,9.531285197122358,-48.313630271303175,28.525617385790497,8.858317928527441,50.144728875588044,10.101574486784415,-9.650330173214215,43.62081402240824,-87.97346348859674,-16.200725704789278,79.30124722603097
16.244528852441675,-97.31979682308949,-67.40689255497901,-39.92144949778462,84.48620911351529,77.66323402191361,62.7104659606772,44.331368682216066,33.25168158596264,-32.114028882470876,-84.43158620923647,16.006065827914597,56.514584403352785,30.506745473805154,-59.091970039510564,71.84277589271971,19.76353108793583,-91.8536661164411,40.816699687526665,-21.748497105449943
-27.5825703719821,53.214916716795955,-61.44933421266386,20.989386576244158,-24.843533806184,2.4650376444985937,-0.29689732809508484,55.50645331498691,8.8740605620345,-28.54555837388824,13.145594138401819,-46.47735662932331,39.9629198654433,79.42291665639041,25.303875365553168,-14.655837219569023,30.906194664906167,12.157593370420656,13.711383434444585,77.62256423702749
5.65242025763699,83.7415139866441,-15.5829142912266,42.70513599117206,6.0108536217851025,67.65052517545206,-17.293198665435725,-11.579274485730991,-91.6883919961893,33.483892852094584,-82.26997555133242,-13.90977123378643,8.832753150101368,-52.315593898537394,19.00713120154056,99.74634572689772,32.00440579695595,-25.07610596982819,-33.57536049014007,60.99259101135044

12
data/Matrices/random_real_general_dense_10_20.space

@ -0,0 +1,12 @@
82.38917250140915 66.46799821137029 -73.97365545078824 -95.31921313337975 -21.846680846362403 24.88547007112365 -25.865299859546667 10.336949242478795 -1.8972305626745083 -58.69281090645184 40.59540633021413 29.366537108425774 -65.555416486013 58.33261150589951 -21.512984674665134 -60.05349816749461 -71.69576759012608 -28.329728816399566 58.99962297286575 -58.13813415200328
-92.50717807374093 -82.70625429017943 -20.410516251452208 25.9852497102478 -13.074424970502463 -75.81380264681468 65.67168308152634 -77.22426410465941 -44.37656310765219 -88.85362200162008 -3.869540413370487 24.773907077654613 63.487545256790355 78.19931976538115 50.30949949551953 53.26517926577674 16.544000743427063 71.47522896677881 47.77740999067842 -29.271187577378967
-8.885651979830001 -15.009550413900527 32.046301346908564 -71.61457727836635 -14.6251745645027 -96.41542712163911 -64.4456874994869 82.10096455940729 -58.97460739147273 -11.661722888831434 -44.394362691753344 -89.89937133484982 -11.702766674811272 59.11653188176288 -30.405475164252323 22.39129523094232 94.28537645748202 38.452366418243145 22.722434197133154 -35.51347099206336
-72.39925296033682 86.80656289020808 -67.44960471721876 -13.026515416896345 91.59389848364387 -18.691036760387277 -27.88853255404662 -22.34376663235838 23.91043816114275 68.40744026653786 16.940882641757 -65.54443899898625 11.895885273301388 -44.57909383901271 71.2644337972327 94.94039533986543 -68.62426222347332 -3.187092927585482 -75.28163396436153 -67.68852908196209
80.59404861191172 -21.927115687319628 33.35685607311282 77.85305544886839 51.601887517862934 3.4122905747095302 -32.66398661676185 36.313965885768795 -41.855322967675626 53.05321393909486 -77.45385402005236 -76.62565696500063 -77.89465840528247 -8.292657315637712 54.596812842423816 -26.700011954666138 -90.18206036502391 -18.086466524875647 -39.05799437730564 40.081375053902434
5.074311855252006 84.22251608410437 -89.43434460315265 -53.20018066807546 7.404021249266805 -89.21248946077878 0.5304325953368902 -74.34152108887051 52.215785748562354 -60.26002900699521 -95.17438985467528 -64.93872162910426 -36.35370747867126 94.79990831767964 73.33262704119048 -59.681867558485415 71.47018389311609 47.89051587365097 -62.640271686852664 -98.99985453928473
50.182784823566294 12.097252271380526 83.07996571154416 20.66374964705308 -28.62505608952776 -41.86824532182081 65.33953691596301 -16.391857185520237 -0.22278619568626823 9.531285197122358 -48.313630271303175 28.525617385790497 8.858317928527441 50.144728875588044 10.101574486784415 -9.650330173214215 43.62081402240824 -87.97346348859674 -16.200725704789278 79.30124722603097
16.244528852441675 -97.31979682308949 -67.40689255497901 -39.92144949778462 84.48620911351529 77.66323402191361 62.7104659606772 44.331368682216066 33.25168158596264 -32.114028882470876 -84.43158620923647 16.006065827914597 56.514584403352785 30.506745473805154 -59.091970039510564 71.84277589271971 19.76353108793583 -91.8536661164411 40.816699687526665 -21.748497105449943
-27.5825703719821 53.214916716795955 -61.44933421266386 20.989386576244158 -24.843533806184 2.4650376444985937 -0.29689732809508484 55.50645331498691 8.8740605620345 -28.54555837388824 13.145594138401819 -46.47735662932331 39.9629198654433 79.42291665639041 25.303875365553168 -14.655837219569023 30.906194664906167 12.157593370420656 13.711383434444585 77.62256423702749
5.65242025763699 83.7415139866441 -15.5829142912266 42.70513599117206 6.0108536217851025 67.65052517545206 -17.293198665435725 -11.579274485730991 -91.6883919961893 33.483892852094584 -82.26997555133242 -13.90977123378643 8.832753150101368 -52.315593898537394 19.00713120154056 99.74634572689772 32.00440579695595 -25.07610596982819 -33.57536049014007 60.99259101135044

12
data/Matrices/random_real_general_dense_10_20.tab

@ -0,0 +1,12 @@
82.38917250140915 66.46799821137029 -73.97365545078824 -95.31921313337975 -21.846680846362403 24.88547007112365 -25.865299859546667 10.336949242478795 -1.8972305626745083 -58.69281090645184 40.59540633021413 29.366537108425774 -65.555416486013 58.33261150589951 -21.512984674665134 -60.05349816749461 -71.69576759012608 -28.329728816399566 58.99962297286575 -58.13813415200328
-92.50717807374093 -82.70625429017943 -20.410516251452208 25.9852497102478 -13.074424970502463 -75.81380264681468 65.67168308152634 -77.22426410465941 -44.37656310765219 -88.85362200162008 -3.869540413370487 24.773907077654613 63.487545256790355 78.19931976538115 50.30949949551953 53.26517926577674 16.544000743427063 71.47522896677881 47.77740999067842 -29.271187577378967
-8.885651979830001 -15.009550413900527 32.046301346908564 -71.61457727836635 -14.6251745645027 -96.41542712163911 -64.4456874994869 82.10096455940729 -58.97460739147273 -11.661722888831434 -44.394362691753344 -89.89937133484982 -11.702766674811272 59.11653188176288 -30.405475164252323 22.39129523094232 94.28537645748202 38.452366418243145 22.722434197133154 -35.51347099206336
-72.39925296033682 86.80656289020808 -67.44960471721876 -13.026515416896345 91.59389848364387 -18.691036760387277 -27.88853255404662 -22.34376663235838 23.91043816114275 68.40744026653786 16.940882641757 -65.54443899898625 11.895885273301388 -44.57909383901271 71.2644337972327 94.94039533986543 -68.62426222347332 -3.187092927585482 -75.28163396436153 -67.68852908196209
80.59404861191172 -21.927115687319628 33.35685607311282 77.85305544886839 51.601887517862934 3.4122905747095302 -32.66398661676185 36.313965885768795 -41.855322967675626 53.05321393909486 -77.45385402005236 -76.62565696500063 -77.89465840528247 -8.292657315637712 54.596812842423816 -26.700011954666138 -90.18206036502391 -18.086466524875647 -39.05799437730564 40.081375053902434
5.074311855252006 84.22251608410437 -89.43434460315265 -53.20018066807546 7.404021249266805 -89.21248946077878 0.5304325953368902 -74.34152108887051 52.215785748562354 -60.26002900699521 -95.17438985467528 -64.93872162910426 -36.35370747867126 94.79990831767964 73.33262704119048 -59.681867558485415 71.47018389311609 47.89051587365097 -62.640271686852664 -98.99985453928473
50.182784823566294 12.097252271380526 83.07996571154416 20.66374964705308 -28.62505608952776 -41.86824532182081 65.33953691596301 -16.391857185520237 -0.22278619568626823 9.531285197122358 -48.313630271303175 28.525617385790497 8.858317928527441 50.144728875588044 10.101574486784415 -9.650330173214215 43.62081402240824 -87.97346348859674 -16.200725704789278 79.30124722603097
16.244528852441675 -97.31979682308949 -67.40689255497901 -39.92144949778462 84.48620911351529 77.66323402191361 62.7104659606772 44.331368682216066 33.25168158596264 -32.114028882470876 -84.43158620923647 16.006065827914597 56.514584403352785 30.506745473805154 -59.091970039510564 71.84277589271971 19.76353108793583 -91.8536661164411 40.816699687526665 -21.748497105449943
-27.5825703719821 53.214916716795955 -61.44933421266386 20.989386576244158 -24.843533806184 2.4650376444985937 -0.29689732809508484 55.50645331498691 8.8740605620345 -28.54555837388824 13.145594138401819 -46.47735662932331 39.9629198654433 79.42291665639041 25.303875365553168 -14.655837219569023 30.906194664906167 12.157593370420656 13.711383434444585 77.62256423702749
5.65242025763699 83.7415139866441 -15.5829142912266 42.70513599117206 6.0108536217851025 67.65052517545206 -17.293198665435725 -11.579274485730991 -91.6883919961893 33.483892852094584 -82.26997555133242 -13.90977123378643 8.832753150101368 -52.315593898537394 19.00713120154056 99.74634572689772 32.00440579695595 -25.07610596982819 -33.57536049014007 60.99259101135044

121
src/Numerics/LinearAlgebra/Common/IO/Matlab/ArrayClass.cs

@ -0,0 +1,121 @@
// <copyright file="ArrayClass.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Common.IO.Matlab
{
/// <summary>
/// Enumeration for the Matlab array types
/// </summary>
internal enum ArrayClass : byte
{
/// <summary>
/// mxUNKNOWN CLASS
/// </summary>
Unknown = 0,
/// <summary>
/// mxCELL CLASS
/// </summary>
Cell = 1,
/// <summary>
/// mxSTRUCT CLASS
/// </summary>
Structure = 2,
/// <summary>
/// mxOBJECT CLASS
/// </summary>
Object = 3,
/// <summary>
/// mxCHAR CLASS
/// </summary>
Character = 4,
/// <summary>
/// mxSPARSE CLASS
/// </summary>
Sparse = 5,
/// <summary>
/// mxDOUBLE CLASS
/// </summary>
Double = 6,
/// <summary>
/// mxSINGLE CLASS
/// </summary>
Single = 7,
/// <summary>
/// mxINT8 CLASS
/// </summary>
Int8 = 8,
/// <summary>
/// mxUINT8 CLASS
/// </summary>
UInt8 = 9,
/// <summary>
/// mxINT16 CLASS
/// </summary>
Int16 = 10,
/// <summary>
/// mxUINT16 CLASS
/// </summary>
UInt16 = 11,
/// <summary>
/// mxINT32 CLASS
/// </summary>
Int32 = 12,
/// <summary>
/// mxUINT32 CLASS
/// </summary>
UInt32 = 13,
/// <summary>
/// mxINT64 CLASS
/// </summary>
Int64 = 14,
/// <summary>
/// mxUINT64 CLASS
/// </summary>
UInt64 = 15,
/// <summary>
/// mxFUNCTION CLASS
/// </summary>
Function = 16
}
}

54
src/Numerics/LinearAlgebra/Common/IO/Matlab/ArrayFlags.cs

@ -0,0 +1,54 @@
// <copyright file="ArrayFlags.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Common.IO.Matlab
{
using System;
/// <summary>
/// Matlab Array Flags
/// </summary>
[Flags]
internal enum ArrayFlags
{
/// <summary>
/// Complex flag
/// </summary>
Complex = 8,
/// <summary>
/// Global flag
/// </summary>
Global = 4,
/// <summary>
/// Logical flag
/// </summary>
Logical = 2
}
}

116
src/Numerics/LinearAlgebra/Common/IO/Matlab/DataType.cs

@ -0,0 +1,116 @@
// <copyright file="DataType.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Common.IO.Matlab
{
/// <summary>
/// Matlab data types
/// </summary>
internal enum DataType
{
/// <summary>
/// Unkown type
/// </summary>
Unknown = 0,
/// <summary>
/// miINT8 type
/// </summary>
Int8 = 1,
/// <summary>
/// miUINT8 type
/// </summary>
UInt8 = 2,
/// <summary>
/// miINT16 type
/// </summary>
Int16 = 3,
/// <summary>
/// miUINT16 type
/// </summary>
UInt16 = 4,
/// <summary>
/// miINT32 type
/// </summary>
Int32 = 5,
/// <summary>
/// miUINT32 type
/// </summary>
UInt32 = 6,
/// <summary>
/// miSINGLE type
/// </summary>
Single = 7,
/// <summary>
/// miDOUBLE type
/// </summary>
Double = 9,
/// <summary>
/// miINT64 type
/// </summary>
Int64 = 12,
/// <summary>
/// miUINT6 4type
/// </summary>
UInt64 = 13,
/// <summary>
/// miMATRIX type
/// </summary>
Matrix = 14,
/// <summary>
/// miCOMPRESSED type
/// </summary>
Compressed = 15,
/// <summary>
/// miUTF8 type
/// </summary>
Utf8 = 16,
/// <summary>
/// miUTF16 type
/// </summary>
Utf16 = 17,
/// <summary>
/// miUTF32 type
/// </summary>
Utf32 = 18
}
}

218
src/Numerics/LinearAlgebra/Double/IO/Matlab/MatlabFile.cs

@ -0,0 +1,218 @@
// <copyright file="MatlabFile.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double.IO.Matlab
{
using System.Collections.Generic;
/// <summary>
/// Represents a Matlab file
/// </summary>
internal class MatlabFile
{
/// <summary>
/// Matrices in a matlab file stored as 1-D arrays
/// </summary>
private readonly IDictionary<string, Matrix> _matrices = new SortedList<string, Matrix>();
/// <summary>
/// Gets or sets the header text.
/// </summary>
/// <value>The header text.</value>
public string HeaderText { get; set; }
/// <summary>
/// Gets or sets the first name of the matrix.
/// </summary>
/// <value>The first name of the matrix.</value>
public string FirstMatrixName { get; set; }
/// <summary>
/// Gets the first matrix.
/// </summary>
/// <value>The first matrix.</value>
public Matrix FirstMatrix
{
get
{
if (string.IsNullOrEmpty(FirstMatrixName) || !_matrices.ContainsKey(FirstMatrixName))
{
return null;
}
return _matrices[FirstMatrixName];
}
}
/// <summary>
/// Gets the matrices.
/// </summary>
/// <value>The matrices.</value>
public IDictionary<string, Matrix> Matrices
{
get { return _matrices; }
}
}
/*
/// <summary>
/// An
/// </summary>
/// <typeparam name="T"></typeparam>
/// <typeparam name="K"></typeparam>
internal class ListDictionary<T, K> : IDictionary<T, K>
{
private readonly IList<T> _keys = new List<T>();
private readonly IList<K> _values = new List<K>();
public void Add(T key, K value)
{
_keys.Add(key);
_values.Add(value);
}
public bool ContainsKey(T key)
{
return _keys.Contains(key);
}
public ICollection<T> Keys
{
get { return _keys; }
}
public bool Remove(T key)
{
if (_keys.Contains(key))
{
int pos = _keys.IndexOf(key);
_values.RemoveAt(pos);
_values.RemoveAt(pos);
return true;
}
return false;
}
public bool TryGetValue(T key, out K value)
{
if (_keys.Contains(key))
{
value = _values[_keys.IndexOf(key)];
return true;
}
value = default(K);
return false;
}
public ICollection<K> Values
{
get { return _values; }
}
public K this[T key]
{
get
{
if (_keys.Contains(key))
{
return _values[_keys.IndexOf(key)];
}
throw new KeyNotFoundException();
}
set
{
if (_keys.Contains(key))
{
_values[_keys.IndexOf(key)] = value;
}
else
{
Add(key, value);
}
}
}
public void Add(KeyValuePair<T, K> item)
{
Add(item.Key, item.Value);
}
public void Clear()
{
_keys.Clear();
_values.Clear();
}
public bool Contains(KeyValuePair<T, K> item)
{
return _keys.Contains(item.Key) && _values[_keys.IndexOf(item.Key)].Equals(item.Value);
}
public void CopyTo(KeyValuePair<T, K>[] array, int arrayIndex)
{
for (int i = 0; i < _keys.Count; i++)
{
array[arrayIndex + i] = new KeyValuePair<T, K>(_keys[i], _values[i]);
}
}
public int Count
{
get { return _keys.Count; }
}
public bool IsReadOnly
{
get { return false; }
}
public bool Remove(KeyValuePair<T, K> item)
{
if (Contains(item))
{
Remove(item.Key);
return true;
}
return false;
}
public IEnumerator<KeyValuePair<T, K>> GetEnumerator()
{
for (int i = 0; i < _keys.Count; i++)
{
yield return new KeyValuePair<T, K>(_keys[i], _values[i]);
}
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}*/
}

535
src/Numerics/LinearAlgebra/Double/IO/Matlab/MatlabParser.cs

@ -0,0 +1,535 @@
// <copyright file="MatlabParser.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
// Copyright (c) 2009-2010 Math.NET
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double.IO.Matlab
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using Common.IO.Matlab;
using Properties;
using zlib;
/// <summary>
/// Parse a Matlab file
/// </summary>
internal class MatlabParser
{
/// <summary>
/// Large Block Size
/// </summary>
private const int LargeBlockSize = 8;
/// <summary>
/// Little Endian Indicator
/// </summary>
private const byte LittleEndianIndicator = 0x49;
/// <summary>
/// Small Block Size
/// </summary>
private const int SmallBlockSize = 4;
/// <summary>
/// Holds the names of the matrices in the file.
/// </summary>
private readonly IList<string> _names = new List<string>();
/// <summary>
/// The stream to read the matlab file from.
/// </summary>
private readonly Stream _stream;
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser"/> class.
/// </summary>
/// <param name="fileName">Name of the file.</param>
public MatlabParser(string fileName)
: this(fileName, new string[0])
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser"/> class.
/// </summary>
/// <param name="stream">The stream to read from.</param>
public MatlabParser(Stream stream)
: this(stream, new string[0])
{
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser"/> class.
/// </summary>
/// <param name="stream">The stream to read from.</param>
/// <param name="objectNames">The name of the objects to retrieve.</param>
public MatlabParser(Stream stream, IEnumerable<string> objectNames)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
_stream = stream;
SetNames(objectNames);
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabParser"/> class.
/// </summary>
/// <param name="fileName">Name of the file.</param>
/// <param name="objectNames">The name of the objects to retrieve.</param>
public MatlabParser(string fileName, IEnumerable<string> objectNames)
{
if (string.IsNullOrEmpty(fileName))
{
throw new ArgumentException(Resources.StringNullOrEmpty, "filename");
}
_stream = File.OpenRead(fileName);
SetNames(objectNames);
}
/// <summary>
/// Copies the names of the objects to retrieve to a local field.
/// </summary>
/// <param name="objectNames">The name of the objects to retrieve.</param>
private void SetNames(IEnumerable<string> objectNames)
{
foreach (var name in objectNames)
{
_names.Add(name);
}
}
/// <summary>
/// Parses the file.
/// </summary>
/// <returns>The parsed Matlab file as a <see cref="MatlabFile"/> object.</returns>
public MatlabFile Parse()
{
var file = new MatlabFile();
using (var reader = new BinaryReader(_stream))
{
file.HeaderText = Encoding.ASCII.GetString(reader.ReadBytes(116));
// skipping subsystem offsets
reader.BaseStream.Position = 126;
if (reader.ReadByte() != LittleEndianIndicator)
{
throw new NotSupportedException(Resources.BigEndianNotSupported);
}
// skip version since it is always 0x0100.
reader.BaseStream.Position = 128;
var length = _stream.Length;
// for each data block add a matlab object to the file.
while (reader.BaseStream.Position < length)
{
var type = (DataType)reader.ReadInt16();
int size = reader.ReadInt16();
var smallBlock = true;
if (size == 0)
{
size = reader.ReadInt32();
smallBlock = false;
}
byte[] data;
if (type == DataType.Compressed)
{
data = DecompressBlock(reader.ReadBytes(size), ref type);
}
else
{
data = new byte[size];
reader.Read(data, 0, size);
AlignData(reader.BaseStream, size, smallBlock);
}
if (type == DataType.Matrix)
{
AddMatrix(data, file);
}
else
{
throw new NotSupportedException(string.Format(Resources.NotSupportedType, type));
}
}
}
return file;
}
/// <summary>
/// Aligns the data.
/// </summary>
/// <param name="stream">The stream.</param>
/// <param name="size">The size of the array.</param>
/// <param name="smallBlock">if set to <c>true</c> if reading from a small block.</param>
private static void AlignData(Stream stream, int size, bool smallBlock)
{
var blockSize = smallBlock ? SmallBlockSize : LargeBlockSize;
var offset = 0;
var mod = size % blockSize;
if (mod != 0)
{
offset = blockSize - mod;
}
stream.Seek(offset, SeekOrigin.Current);
}
/// <summary>
/// Decompresses the block.
/// </summary>
/// <param name="compressed">The compressed data.</param>
/// <param name="type">The type data type contained in the block.</param>
/// <returns>The decompressed block.</returns>
private static byte[] DecompressBlock(byte[] compressed, ref DataType type)
{
byte[] data;
using (var decompressed = new MemoryStream())
{
using (var decompressor = new ZOutputStream(decompressed))
{
decompressor.Write(compressed, 0, compressed.Length);
decompressed.Position = 0;
var buf = new byte[4];
decompressed.Read(buf, 0, 4);
type = (DataType)BitConverter.ToInt32(buf, 0);
decompressed.Read(buf, 0, 4);
var size = BitConverter.ToInt32(buf, 0);
data = new byte[size];
decompressed.Read(data, 0, size);
}
}
return data;
}
/// <summary>
/// Adds a matrix from the actual file into our presentation of a matlab file.
/// </summary>
/// <param name="data">The data of the matrix.</param>
/// <param name="file">The <see cref="MatlabFile"/> instance.</param>
private void AddMatrix(byte[] data, MatlabFile file)
{
using (var ms = new MemoryStream(data))
{
using (var reader = new BinaryReader(ms))
{
// skip tag - doesn't tell us anything we don't already know
reader.BaseStream.Seek(8, SeekOrigin.Current);
var arrayClass = (ArrayClass)reader.ReadByte();
var flags = reader.ReadByte();
var isComplex = (flags & (byte)ArrayFlags.Complex) == (byte)ArrayFlags.Complex;
if (isComplex)
{
throw new NotSupportedException(Resources.ComplexMatricesNotSupported);
}
// skip unneeded bytes
reader.BaseStream.Seek(10, SeekOrigin.Current);
var numDimensions = reader.ReadInt32() / 8;
if (numDimensions > 2)
{
throw new NotSupportedException(Resources.MoreThan2D);
}
var rows = reader.ReadInt32();
var columns = reader.ReadInt32();
// skip unneeded bytes
reader.BaseStream.Seek(2, SeekOrigin.Current);
int size = reader.ReadInt16();
var smallBlock = true;
if (size == 0)
{
size = reader.ReadInt32();
smallBlock = false;
}
var name = Encoding.ASCII.GetString(reader.ReadBytes(size));
AlignData(reader.BaseStream, size, smallBlock);
// only grab wanted objects
if (_names.Count != 0 && !_names.Contains(name))
{
return;
}
var type = (DataType)reader.ReadInt16();
size = reader.ReadInt16();
if (size == 0)
{
size = reader.ReadInt32();
}
Matrix matrix;
switch (arrayClass)
{
case ArrayClass.Sparse:
matrix = PopulateSparseMatrix(reader, rows, columns, size);
break;
case ArrayClass.Function:
case ArrayClass.Character:
case ArrayClass.Object:
case ArrayClass.Structure:
case ArrayClass.Cell:
case ArrayClass.Unknown:
throw new NotImplementedException();
default:
matrix = PopulateDenseMatrix(type, reader, rows, columns);
break;
}
file.Matrices.Add(name, matrix);
if (file.FirstMatrixName == null)
{
file.FirstMatrixName = name;
}
}
}
}
/// <summary>
/// Populates a sparse matrix.
/// </summary>
/// <param name="reader">The reader.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <param name="size">The size of the block.</param>
/// <returns>A populated sparse matrix.</returns>
private static Matrix PopulateSparseMatrix(BinaryReader reader, int rows, int columns, int size)
{
// populate the row data array
var ir = new int[size / 4];
for (var i = 0; i < ir.Length; i++)
{
ir[i] = reader.ReadInt32();
}
AlignData(reader.BaseStream, size, false);
// skip data type since it will always be int32
reader.BaseStream.Seek(4, SeekOrigin.Current);
// populate the column data array
var jcsize = reader.ReadInt32();
var jc = new int[jcsize / 4];
for (var j = 0; j < jc.Length; j++)
{
jc[j] = reader.ReadInt32();
}
AlignData(reader.BaseStream, jcsize, false);
var type = (DataType)reader.ReadInt32();
// skip length since we already no it for the number of rows
reader.BaseStream.Seek(4, SeekOrigin.Current);
Matrix matrix = new SparseMatrix(rows, columns);
var col = 0;
for (var i = 0; i < ir.Length; i++)
{
var row = ir[i];
if (jc[col + 1] == i)
{
col++;
}
switch (type)
{
case DataType.Int8:
matrix[row, col] = reader.ReadSByte();
break;
case DataType.UInt8:
matrix[row, col] = reader.ReadByte();
break;
case DataType.Int16:
matrix[row, col] = reader.ReadInt16();
break;
case DataType.UInt16:
matrix[row, col] = reader.ReadUInt16();
break;
case DataType.Int32:
matrix[row, col] = reader.ReadInt32();
break;
case DataType.UInt32:
matrix[row, col] = reader.ReadUInt32();
break;
case DataType.Single:
matrix[row, col] = reader.ReadSingle();
break;
case DataType.Int64:
matrix[row, col] = reader.ReadInt64();
break;
case DataType.UInt64:
matrix[row, col] = reader.ReadUInt64();
break;
case DataType.Double:
matrix[row, col] = reader.ReadDouble();
break;
default:
throw new NotSupportedException();
}
}
return matrix;
}
/// <summary>
/// Populates a dense matrix.
/// </summary>
/// <param name="type">The type of data.</param>
/// <param name="reader">The reader.</param>
/// <param name="rows">The number of rows.</param>
/// <param name="columns">The number of columns.</param>
/// <returns>Returns a populated dense matrix.</returns>
private static Matrix PopulateDenseMatrix(DataType type, BinaryReader reader, int rows, int columns)
{
Matrix matrix = new DenseMatrix(rows, columns);
switch (type)
{
case DataType.Int8:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadSByte();
}
}
break;
case DataType.UInt8:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadByte();
}
}
break;
case DataType.Int16:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadInt16();
}
}
break;
case DataType.UInt16:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadUInt16();
}
}
break;
case DataType.Int32:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadInt32();
}
}
break;
case DataType.UInt32:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadUInt32();
}
}
break;
case DataType.Single:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadSingle();
}
}
break;
case DataType.Int64:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadInt64();
}
}
break;
case DataType.UInt64:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadUInt64();
}
}
break;
case DataType.Double:
for (var j = 0; j < columns; j++)
{
for (var i = 0; i < rows; i++)
{
matrix[i, j] = reader.ReadDouble();
}
}
break;
default:
throw new NotSupportedException();
}
return matrix;
}
}
}

189
src/Numerics/LinearAlgebra/Double/IO/MatlabReader.cs

@ -0,0 +1,189 @@
// <copyright file="MatlabReader.cs" company="Math.NET">
// Math.NET Numerics, part of the Math.NET Project
// http://numerics.mathdotnet.com
// http://github.com/mathnet/mathnet-numerics
// http://mathnetnumerics.codeplex.com
//
// Copyright (c) 2009-2010 Math.NET
//
// Permission is hereby granted, free of charge, to any person
// obtaining a copy of this software and associated documentation
// files (the "Software"), to deal in the Software without
// restriction, including without limitation the rights to use,
// copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following
// conditions:
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
// </copyright>
namespace MathNet.Numerics.LinearAlgebra.Double.IO
{
using System;
using System.Collections.Generic;
using System.IO;
using Matlab;
using Properties;
/// <summary>
/// Creates matrices from Matlab files.
/// </summary>
public class MatlabMatrixReader
{
/// <summary>
/// The name of the file to read from.
/// </summary>
private readonly string _filename;
/// <summary>
/// The stream to read from if we are not reading from a file directly.
/// </summary>
private readonly Stream _stream;
/// <summary>
/// Initializes a new instance of the <see cref="MatlabMatrixReader"/> class.
/// </summary>
/// <param name="filename">Name of the file to read matrices from.</param>
public MatlabMatrixReader(string filename)
{
if (string.IsNullOrEmpty(filename))
{
throw new ArgumentException(Resources.StringNullOrEmpty, "filename");
}
if (!File.Exists(filename))
{
throw new FileNotFoundException(Resources.FileDoesNotExist, "filename");
}
_filename = filename;
}
/// <summary>
/// Initializes a new instance of the <see cref="MatlabMatrixReader"/> class.
/// </summary>
/// <param name="stream">The stream to reader matrices from.</param>
public MatlabMatrixReader(Stream stream)
{
if (stream == null)
{
throw new ArgumentNullException("stream");
}
_stream = stream;
}
/// <summary>
/// Reads the first matrix from the file or stream.
/// </summary>
/// <returns>
/// If the matrix is stored as a sparse matrix, then a <see cref="SparseMatrix"/> is returned. Otherwise, a <see cref="DenseMatrix"/>
/// is returned.
/// </returns>
public Matrix ReadMatrix()
{
return ReadMatrix(null);
}
/// <summary>
/// Reads the named matrix from the file or stream.
/// </summary>
/// <param name="matrixName">The name of the matrix to read.</param>
/// <returns>
/// If the matrix is stored as a sparse matrix, then a <see cref="SparseMatrix"/> is returned. Otherwise, a <see cref="DenseMatrix"/>
/// is returned. <see langword="null"/> is returned if a matrix with the requests name doesn't exist.
/// </returns>
public Matrix ReadMatrix(string matrixName)
{
Stream stream;
if (_filename == null)
{
stream = _stream;
_stream.Seek(0, SeekOrigin.Begin);
}
else
{
stream = new FileStream(_filename, FileMode.Open, FileAccess.Read);
}
var names = string.IsNullOrEmpty(matrixName) ? new string[] { } : new[] { matrixName };
var parser = new MatlabParser(stream, names);
var file = parser.Parse();
Matrix matrix = null;
if (string.IsNullOrEmpty(matrixName))
{
matrix = file.FirstMatrix;
}
else if (file.Matrices.ContainsKey(matrixName))
{
matrix = file.Matrices[matrixName];
}
if (_filename != null)
{
stream.Close();
stream.Dispose();
}
return matrix;
}
/// <summary>
/// Reads all matrices from the file or stream.
/// </summary>
/// <returns>All matrices from the file or stream.</returns>
public Matrix[] ReadMatrices()
{
return ReadMatrices(new string[] { });
}
/// <summary>
/// Reads the named matrices from the file or stream.
/// </summary>
/// <param name="names">The names of the matrices to retrieve.</param>
/// <returns>
/// The named matrices from the file or stream.
/// </returns>
public Matrix[] ReadMatrices(IEnumerable<string> names)
{
Stream stream;
if (_filename == null)
{
stream = _stream;
_stream.Seek(0, SeekOrigin.Begin);
}
else
{
stream = new BufferedStream(new FileStream(_filename, FileMode.Open, FileAccess.Read));
}
var parser = new MatlabParser(stream, names);
var file = parser.Parse();
var matrices = new Matrix[file.Matrices.Count];
var i = 0;
foreach (var matrix in file.Matrices.Values)
{
matrices[i++] = matrix;
}
if (_filename != null)
{
stream.Close();
stream.Dispose();
}
return matrices;
}
}
}

69
src/Numerics/LinearAlgebra/Double/Matrix.cs

@ -29,6 +29,7 @@ namespace MathNet.Numerics.LinearAlgebra.Double
using System;
using System.Collections.Generic;
using System.Text;
using Factorization;
using Properties;
using Threading;
@ -1757,5 +1758,73 @@ namespace MathNet.Numerics.LinearAlgebra.Double
}
});
}
/// <summary>Calculates the L1 norm.</summary>
/// <returns>The L1 norm of the matrix.</returns>
public virtual double L1Norm()
{
double norm = 0.0;
for (var j = 0; j < ColumnCount; j++)
{
var s = 0.0;
for (var i = 0; i < RowCount; i++)
{
s += Math.Abs(At(i, j));
}
norm = Math.Max(norm, s);
}
return norm;
}
/// <summary>Calculates the L2 norm.</summary>
/// <returns>The L2 norm of the matrix.</returns>
/// <remarks>For sparse matrices, the L2 norm is computed using a dense implementation of singular value decomposition.
/// In a later release, it will be replaced with a sparse implementation.</remarks>
public virtual double L2Norm()
{
return Svd.Create(this, false).Norm2;
}
/// <summary>Calculates the Frobenius norm of this matrix.</summary>
/// <returns>The Frobenius norm of this matrix.</returns>
public virtual double FrobeniusNorm()
{
var transpose = Transpose();
var aat = this * transpose;
//TODO: Replace with multiple Transpose
// aat.Gemm(1.0, 0.0, false, true, this, this);
var norm = 0.0;
for (var i = 0; i < RowCount; i++)
{
norm += Math.Abs(aat.At(i, i));
}
norm = Math.Sqrt(norm);
return norm;
}
/// <summary>Calculates the infinity norm of this matrix.</summary>
/// <returns>The infinity norm of this matrix.</returns>
public virtual double InfinityNorm()
{
var norm = 0.0;
for (var i = 0; i < RowCount; i++)
{
var s = 0.0;
for (var j = 0; j < ColumnCount; j++)
{
s += Math.Abs(At(i, j));
}
norm = Math.Max(norm, s);
}
return norm;
}
}
}

9
src/Numerics/Numerics.csproj

@ -65,6 +65,9 @@
<Reference Include="System.Data" />
<Reference Include="System.Numerics" />
<Reference Include="System.Xml" />
<Reference Include="zlib.net">
<HintPath>..\..\lib\zlib\zlib.net.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Algorithms\LinearAlgebra\Atlas\AtlasLinearAlgebraProvider.cs">
@ -109,6 +112,12 @@
<Compile Include="LinearAlgebra\Double\Factorization\UserSvd.cs" />
<Compile Include="LinearAlgebra\Double\IO\DelimitedReader.cs" />
<Compile Include="LinearAlgebra\Double\IO\DelimitedWriter.cs" />
<Compile Include="LinearAlgebra\Common\IO\Matlab\ArrayClass.cs" />
<Compile Include="LinearAlgebra\Common\IO\Matlab\ArrayFlags.cs" />
<Compile Include="LinearAlgebra\Common\IO\Matlab\DataType.cs" />
<Compile Include="LinearAlgebra\Double\IO\MatlabReader.cs" />
<Compile Include="LinearAlgebra\Double\IO\Matlab\MatlabFile.cs" />
<Compile Include="LinearAlgebra\Double\IO\Matlab\MatlabParser.cs" />
<Compile Include="LinearAlgebra\Double\IO\MatrixReader.cs" />
<Compile Include="LinearAlgebra\Double\IO\MatrixWriter.cs" />
<Compile Include="LinearAlgebra\Double\ISolver.cs" />

54
src/Numerics/Properties/Resources.Designer.cs

@ -150,6 +150,15 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to The requested matrix does not exist..
/// </summary>
internal static string ArgumentMatrixDoesNotExist {
get {
return ResourceManager.GetString("ArgumentMatrixDoesNotExist", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The matrix indices must not be out of range of the given matrix..
/// </summary>
@ -456,6 +465,15 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Big endian files are not supported..
/// </summary>
internal static string BigEndianNotSupported {
get {
return ResourceManager.GetString("BigEndianNotSupported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The supplied collection is empty..
/// </summary>
@ -465,6 +483,15 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Complex matrices are not supported..
/// </summary>
internal static string ComplexMatricesNotSupported {
get {
return ResourceManager.GetString("ComplexMatricesNotSupported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An algorithm failed to converge..
/// </summary>
@ -483,6 +510,15 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to The given file doesn&apos;t exist..
/// </summary>
internal static string FileDoesNotExist {
get {
return ResourceManager.GetString("FileDoesNotExist", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Invalid parameterization for the distribution..
/// </summary>
@ -573,6 +609,24 @@ namespace MathNet.Numerics.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Only 1 and 2 dimensional arrays are supported..
/// </summary>
internal static string MoreThan2D {
get {
return ResourceManager.GetString("MoreThan2D", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} is not a supported type..
/// </summary>
internal static string NotSupportedType {
get {
return ResourceManager.GetString("NotSupportedType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The two arguments can&apos;t be compared (maybe they are part of a partial ordering?).
/// </summary>

18
src/Numerics/Properties/Resources.resx

@ -315,4 +315,22 @@
<data name="StringNullOrEmpty" xml:space="preserve">
<value>String parameter cannot be empty or null.</value>
</data>
<data name="ArgumentMatrixDoesNotExist" xml:space="preserve">
<value>The requested matrix does not exist.</value>
</data>
<data name="BigEndianNotSupported" xml:space="preserve">
<value>Big endian files are not supported.</value>
</data>
<data name="ComplexMatricesNotSupported" xml:space="preserve">
<value>Complex matrices are not supported.</value>
</data>
<data name="FileDoesNotExist" xml:space="preserve">
<value>The given file doesn't exist.</value>
</data>
<data name="MoreThan2D" xml:space="preserve">
<value>Only 1 and 2 dimensional arrays are supported.</value>
</data>
<data name="NotSupportedType" xml:space="preserve">
<value>{0} is not a supported type.</value>
</data>
</root>

70
src/UnitTests/LinearAlgebraTests/Double/IO/MatlabReaderTests.cs

@ -0,0 +1,70 @@

namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double.IO
{
using LinearAlgebra.Double;
using LinearAlgebra.Double.IO;
using MbUnit.Framework;
[TestFixture]
public class MatlabMatrixReaderTest
{
[Test]
public void CanReadAllMatrices()
{
var dmr = new MatlabMatrixReader("./data/Matlab/collection.mat");
var matrices = dmr.ReadMatrices();
Assert.AreEqual(30, matrices.Length);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(DenseMatrix), matrix.GetType());
}
}
[Test]
public void CanReadFirstMatrix()
{
var dmr = new MatlabMatrixReader("./data/Matlab/A.mat");
var matrix = dmr.ReadMatrix();
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(DenseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(100.108979553704, matrix.FrobeniusNorm(), 13);
}
[Test]
public void CanReadNamedMatrices()
{
var dmr = new MatlabMatrixReader("./data/Matlab/collection.mat");
var matrices = dmr.ReadMatrices(new[] { "Ad", "Au64" });
Assert.AreEqual(2, matrices.Length);
foreach (var matrix in matrices)
{
Assert.AreEqual(typeof(DenseMatrix), matrix.GetType());
}
}
[Test]
public void CanReadNamedMatrix()
{
var dmr = new MatlabMatrixReader("./data/Matlab/collection.mat");
var matrices = dmr.ReadMatrices(new[] { "Ad" });
Assert.AreEqual(1, matrices.Length);
Assert.AreEqual(100, matrices[0].RowCount);
Assert.AreEqual(100, matrices[0].ColumnCount);
AssertHelpers.AlmostEqual(100.431635988639, matrices[0].FrobeniusNorm(), 13);
Assert.AreEqual(typeof(DenseMatrix), matrices[0].GetType());
}
[Test]
public void CanReadNamedSparseMatrix()
{
var dmr = new MatlabMatrixReader("./data/Matlab/sparse-small.mat");
var matrix = dmr.ReadMatrix("S");
Assert.AreEqual(100, matrix.RowCount);
Assert.AreEqual(100, matrix.ColumnCount);
Assert.AreEqual(typeof(SparseMatrix), matrix.GetType());
AssertHelpers.AlmostEqual(17.6385090630805, matrix.FrobeniusNorm(), 12);
}
}
}

52
src/UnitTests/LinearAlgebraTests/Double/MatrixTests.cs

@ -1426,5 +1426,57 @@ namespace MathNet.Numerics.UnitTests.LinearAlgebraTests.Double
var result = this.CreateMatrix(top.RowCount + lower.RowCount + 2, top.ColumnCount + lower.ColumnCount);
top.DiagonalStack(lower, result);
}
[Test]
public void FrobeniusNorm()
{
var matrix = testMatrices["Square3x3"];
AssertHelpers.AlmostEqual(10.77775486824598, matrix.FrobeniusNorm(), 14);
matrix = testMatrices["Wide2x3"];
AssertHelpers.AlmostEqual(4.79478883789474, matrix.FrobeniusNorm(), 14);
matrix = testMatrices["Tall3x2"];
AssertHelpers.AlmostEqual(7.54122006044115, matrix.FrobeniusNorm(), 14);
}
[Test]
public void InfinityNorm()
{
Matrix matrix = testMatrices["Square3x3"];
Assert.AreEqual(16.5, matrix.InfinityNorm());
matrix = testMatrices["Wide2x3"];
Assert.AreEqual(6.6, matrix.InfinityNorm());
matrix = testMatrices["Tall3x2"];
Assert.AreEqual(9.9, matrix.InfinityNorm());
}
[Test]
public void L1Norm()
{
Matrix matrix = testMatrices["Square3x3"];
Assert.AreEqual(12.1, matrix.L1Norm());
matrix = testMatrices["Wide2x3"];
Assert.AreEqual(5.5, matrix.L1Norm());
matrix = testMatrices["Tall3x2"];
Assert.AreEqual(8.8, matrix.L1Norm());
}
[Test]
public void L2Norm()
{
var matrix = testMatrices["Square3x3"];
AssertHelpers.AlmostEqual(10.391347375312632, matrix.L2Norm(), 14);
matrix = testMatrices["Wide2x3"];
AssertHelpers.AlmostEqual(4.7540849434107635, matrix.L2Norm(), 14);
matrix = testMatrices["Tall3x2"];
AssertHelpers.AlmostEqual(7.182727033856683, matrix.L2Norm(), 14);
}
}
}

26
src/UnitTests/UnitTests.csproj

@ -98,6 +98,7 @@
<Compile Include="LinearAlgebraTests\Double\Factorization\QRTests.cs" />
<Compile Include="LinearAlgebraTests\Double\IO\DelimitedWriterTests.cs" />
<Compile Include="LinearAlgebraTests\Double\IO\DelimitedReaderTests.cs" />
<Compile Include="LinearAlgebraTests\Double\IO\MatlabReaderTests.cs" />
<Compile Include="LinearAlgebraTests\Double\SparseMatrixTests.cs" />
<Compile Include="PermutationTest.cs" />
<Compile Include="DistributionTests\CommonDistributionTests.cs" />
@ -174,6 +175,30 @@
<Compile Include="TrigonometryTest.cs" />
</ItemGroup>
<ItemGroup>
<None Include="..\..\data\Matlab\A.mat">
<Link>data\Matlab\A.mat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\data\Matlab\collection-nocompress.mat">
<Link>data\Matlab\collection-nocompress.mat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\data\Matlab\collection.mat">
<Link>data\Matlab\collection.mat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\data\Matlab\sparse-large.mat">
<Link>data\Matlab\sparse-large.mat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\data\Matlab\sparse-small.mat">
<Link>data\Matlab\sparse-small.mat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\data\Matlab\v.mat">
<Link>data\Matlab\v.mat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="..\..\data\NIST\AtmWtAgt.dat">
<Link>data\NIST\AtmWtAgt.dat</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
@ -429,6 +454,7 @@
<Install>true</Install>
</BootstrapperPackage>
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

Loading…
Cancel
Save