Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/matrix.cc
[mareframe] / trunk / gadget / matrix.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/matrix.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 12 - (view) (download)

1 : ulcessvp 2 #include "matrix.h"
2 :     #include "mathfunc.h"
3 :     #include "gadget.h"
4 :    
5 :     Matrix::Matrix(int nr, int nc, double value) {
6 :    
7 :     m = new double[nr * nc];
8 :     nrow = nr;
9 :     ncol = nc;
10 :     int i, j;
11 :     for (i = 0; i < nr; i++) {
12 :     for (j = 0; j < nc; j++)
13 :     m[i*ncol+j] = value;
14 :     }
15 :     }
16 :    
17 :     Matrix::~Matrix() {
18 :     int i;
19 :     if (m != 0) {
20 :     delete[] m;
21 :     m = 0;
22 :     ncol = nrow = 0;
23 :     }
24 :     }
25 :    
26 :     void Matrix::AddRows(int add, int length, double value) {
27 :     if (add <= 0)
28 :     return;
29 :    
30 :     int i, j;
31 :     if (m == 0) {
32 :     nrow = add;
33 :     ncol = length;
34 :     m = new double[nrow*ncol];
35 :     for (i = 0; i < nrow; i++) {
36 :     for (j = 0; j < length; j++)
37 :     m[i*ncol+j] = value;
38 :     }
39 :    
40 :     } else {
41 :     int aux = nrow + add;
42 :     double* vnew = new double[aux*length];
43 :     for (i = 0; i < nrow; i++)
44 :     for (j = 0; j < length; j++)
45 :     vnew[i*ncol+j] = m[i*ncol+j];
46 :    
47 :     for (i = nrow; i < nrow + add; i++) {
48 :     for (j = 0; j < length; j++)
49 :     vnew[i*ncol+j] = value;
50 :     }
51 :     delete[] m;
52 :     m = vnew;
53 :     nrow = aux;
54 :     }
55 :     }
56 :    
57 :     void Matrix::Reset() {
58 :     if (nrow > 0) {
59 :     int i;
60 :     delete[] m;
61 :     m = 0;
62 :     nrow = 0;
63 :     ncol = 0;
64 :     }
65 :     }
66 :    
67 : ulcessvp 5 void Matrix::Initialize(int nr, int nc, double initial) {
68 :     if (m != 0)
69 :     delete[] m;
70 :    
71 :     m = new double[nr * nc];
72 :     nrow = nr;
73 :     ncol = nc;
74 :     int i, j;
75 :     for (i = 0; i < nr; i++) {
76 :     for (j = 0; j < nc; j++)
77 :     m[i*ncol+j] = initial;
78 :     }
79 :     }
80 :    
81 : ulcessvp 2 void Matrix::Print(ofstream& outfile) const {
82 :     int i, j;
83 :     for (i = 0; i < nrow; i++) {
84 :     outfile << TAB;
85 :     for (j = 0; j < ncol; j++)
86 :     outfile << setw(smallwidth) << setprecision(smallprecision)
87 :     << m[i*ncol+j] << sep;
88 :     outfile << endl;
89 :     }
90 :     }
91 :    
92 :     void Matrix::setToZero() {
93 :     int i, j;
94 :     for (i = 0; i < nrow; i++)
95 :     for (j = 0; j < ncol; j++)
96 : ulcessvp 5 m[i*ncol+j] = 0.0;
97 : ulcessvp 2 }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge