]> git.donarmstrong.com Git - lilypond.git/blob - smat.cc
3830fd6825b4aab553cadf5b91f25ff5be457b6f
[lilypond.git] / smat.cc
1 #include "smat.hh"
2
3 void
4 Full_storage::operator=(Full_storage const &fs)
5 {
6     resize(fs.h, fs.w);
7     OK();
8     fs.OK();
9     for (int i=0; i<h; i++)
10         for (int j=0; j<w; j++)
11             els[i][j]= fs.els[i][j];
12 }
13
14 void
15 Full_storage::OK() const
16 {
17     //    static Real dummy;            
18     assert(maxh >= h && maxw >= w);
19     assert(h >= 0 && w >= 0);
20     assert(els||!maxh);
21     if (maxh>0) {               // access outer elts.
22         Real *r = els[maxh -1];
23         if (maxw>0) {
24             assert(r);
25             Real s = r[maxw -1];
26             s = sin(s);
27         }
28     }
29 }
30 void
31 Full_storage::resize_cols(int newh)
32 {
33     if (newh <= maxh) {
34         h=newh;
35         return;
36     }
37    
38     Real ** newa=new Real*[newh];
39     int j=0;
40     for (; j < h; j++)
41         newa[j] = els[j];
42     for (; j < newh; j++)
43         newa[j] = new Real[maxw];
44     delete[] els;
45     els=newa;
46
47     h = maxh = newh;
48 }
49
50 void
51 Full_storage::resize_rows(int neww)
52 {
53     if (neww <= maxw) {
54         w=neww;
55         return;
56     }
57     for (int i=0; i < maxh ; i++) {
58         Real* newa=new Real[neww];
59         for (int k=0; k < w; k++)
60             newa[k] = els[i][k];
61
62         delete[] els[i];
63         els[i] = newa;
64     }
65     w = maxw = neww;    
66 }
67
68 Full_storage::~Full_storage() {
69     for (int i=0; i < maxh; i++)
70         delete [] els[i];
71     delete[] els;
72 }
73
74 void
75 Full_storage::resize(int rows, int cols)
76 {
77     OK();
78     resize_cols(rows);
79     resize_rows(cols);
80
81 }
82
83
84 bool
85 Full_storage::mult_ok(int i, int j) const
86 {
87     return valid(i,j);
88 }
89
90 bool
91 Full_storage::trans_ok(int i, int j) const
92 {
93        return valid(i,j);
94
95
96
97 void
98 Full_storage::trans_next(int &i, int &j) const
99 {
100     assert(trans_ok(i,j));
101     i++;
102     if (i >= h) {
103         i=0;
104         j ++;
105     }
106 }
107
108 void
109 Full_storage::mult_next(int &i, int &j) const
110 {
111     assert(mult_ok(i,j));
112     j++;
113     if (j >= w) {
114         j=0;
115         i++;
116     }
117 }
118
119 void
120 Full_storage::delete_column(int k)
121 {
122     assert(0 <= k &&k<w);    
123     for (int i=0; i< h ; i++)
124         for (int j=k+1; j <w; j++)
125             els[i][j-1]=els[i][j];
126     w--;
127 }
128 void
129 Full_storage::delete_row(int k)
130 {
131     assert(0 <= k &&k<h);
132     for (int i=k+1; i < h ; i++)
133         for (int j=0; j < w; j++)
134             els[i-1][j]=els[i][j];
135     h--;
136 }
137
138
139 void
140 Full_storage::insert_row(int k)
141 {
142     assert(0 <= k&& k <=h);
143     resize_cols(h+1);
144     for (int i=h-1; i > k ; i--)
145         for (int j=0; j <w; j++)
146             els[i][j]=els[i-1][j];
147
148 }
149
150
151 svec<Real>
152 Full_storage::row(int n) const
153 {
154     svec<Real> r;
155     for (int j = 0; j < w; j++)
156         r.add(els[n][j]);
157     return r;
158 }
159
160 svec<Real>
161 Full_storage::column(int n) const
162 {
163     
164     svec<Real> r;
165     for (int i = 0; i<h; i++)
166         r.add(els[i][n]);
167     return r;
168 }
169
170
171 Full_storage::Full_storage(Full_storage&s)
172 {
173     init();
174     (*this) = s;
175 }
176 virtual_smat*
177 Full_storage::clone()
178 {
179     return new Full_storage(*this);
180 }
181 /****************************************************************/
182
183 virtual_smat *
184 virtual_smat::get_full(int n, int m)
185 {
186     return new Full_storage(n,m);
187 }