lilypond-0.0.2
[lilypond.git] / smat.cc
blob3830fd6825b4aab553cadf5b91f25ff5be457b6f
1 #include "smat.hh"
3 void
4 Full_storage::operator=(Full_storage const &fs)
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];
14 void
15 Full_storage::OK() const
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);
30 void
31 Full_storage::resize_cols(int newh)
33 if (newh <= maxh) {
34 h=newh;
35 return;
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;
47 h = maxh = newh;
50 void
51 Full_storage::resize_rows(int neww)
53 if (neww <= maxw) {
54 w=neww;
55 return;
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];
62 delete[] els[i];
63 els[i] = newa;
65 w = maxw = neww;
68 Full_storage::~Full_storage() {
69 for (int i=0; i < maxh; i++)
70 delete [] els[i];
71 delete[] els;
74 void
75 Full_storage::resize(int rows, int cols)
77 OK();
78 resize_cols(rows);
79 resize_rows(cols);
84 bool
85 Full_storage::mult_ok(int i, int j) const
87 return valid(i,j);
90 bool
91 Full_storage::trans_ok(int i, int j) const
93 return valid(i,j);
97 void
98 Full_storage::trans_next(int &i, int &j) const
100 assert(trans_ok(i,j));
101 i++;
102 if (i >= h) {
103 i=0;
104 j ++;
108 void
109 Full_storage::mult_next(int &i, int &j) const
111 assert(mult_ok(i,j));
112 j++;
113 if (j >= w) {
114 j=0;
115 i++;
119 void
120 Full_storage::delete_column(int k)
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--;
128 void
129 Full_storage::delete_row(int k)
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--;
139 void
140 Full_storage::insert_row(int k)
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];
151 svec<Real>
152 Full_storage::row(int n) const
154 svec<Real> r;
155 for (int j = 0; j < w; j++)
156 r.add(els[n][j]);
157 return r;
160 svec<Real>
161 Full_storage::column(int n) const
164 svec<Real> r;
165 for (int i = 0; i<h; i++)
166 r.add(els[i][n]);
167 return r;
171 Full_storage::Full_storage(Full_storage&s)
173 init();
174 (*this) = s;
176 virtual_smat*
177 Full_storage::clone()
179 return new Full_storage(*this);
181 /****************************************************************/
183 virtual_smat *
184 virtual_smat::get_full(int n, int m)
186 return new Full_storage(n,m);