lilypond-1.1.44
[lilypond.git] / flower / smat.cc
blobdcc61ce44ef26eadb600db6c8b9fcd3155ec1e82
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 #ifndef NDEBUG
18 // static Real dummy;
19 assert(maxh >= h && maxw >= w);
20 assert(h >= 0 && w >= 0);
21 assert(els||!maxh);
22 #endif
24 void
25 Full_storage::resize_cols(int newh)
27 if (newh <= maxh) {
28 h=newh;
29 return;
32 Real ** newa=new Real*[newh];
33 int j=0;
34 for (; j < h; j++)
35 newa[j] = els[j];
36 for (; j < newh; j++)
37 newa[j] = new Real[maxw];
38 delete[] els;
39 els=newa;
41 h = maxh = newh;
44 void
45 Full_storage::resize_rows(int neww)
47 if (neww <= maxw) {
48 w=neww;
49 return;
51 for (int i=0; i < maxh ; i++) {
52 Real* newa = new Real[neww];
53 for (int k=0; k < w; k++)
54 newa[k] = els[i][k];
56 delete[] els[i];
57 els[i] = newa;
59 w = maxw = neww;
62 Full_storage::~Full_storage() {
63 for (int i=0; i < maxh; i++)
64 delete [] els[i];
65 delete[] els;
68 void
69 Full_storage::resize(int rows, int cols)
71 OK();
72 resize_cols(rows);
73 resize_rows(cols);
78 bool
79 Full_storage::mult_ok(int i, int j) const
81 return valid(i,j);
84 bool
85 Full_storage::trans_ok(int i, int j) const
87 return valid(i,j);
91 void
92 Full_storage::trans_next(int &i, int &j) const
94 assert(trans_ok(i,j));
95 i++;
96 if (i >= h) {
97 i=0;
98 j ++;
102 void
103 Full_storage::mult_next(int &i, int &j) const
105 assert(mult_ok(i,j));
106 j++;
107 if (j >= w) {
108 j=0;
109 i++;
113 void
114 Full_storage::delete_column(int k)
116 assert(0 <= k &&k<w);
117 for (int i=0; i< h ; i++)
118 for (int j=k+1; j <w; j++)
119 els[i][j-1]=els[i][j];
120 w--;
122 void
123 Full_storage::delete_row(int k)
125 assert(0 <= k &&k<h);
126 for (int i=k+1; i < h ; i++)
127 for (int j=0; j < w; j++)
128 els[i-1][j]=els[i][j];
129 h--;
133 void
134 Full_storage::insert_row(int k)
136 assert(0 <= k&& k <=h);
137 resize_cols(h+1);
138 for (int i=h-1; i > k ; i--)
139 for (int j=0; j <w; j++)
140 els[i][j]=els[i-1][j];
145 Array<Real>
146 Full_storage::row(int n) const
148 Array<Real> r;
149 for (int j = 0; j < w; j++)
150 r.push(els[n][j]);
151 return r;
154 Array<Real>
155 Full_storage::column(int n) const
158 Array<Real> r;
159 for (int i = 0; i<h; i++)
160 r.push(els[i][n]);
161 return r;
165 Full_storage::Full_storage(Full_storage&s)
167 init();
168 (*this) = s;
170 virtual_smat*
171 Full_storage::clone()
173 return new Full_storage(*this);
177 virtual_smat *
178 virtual_smat::get_full(int n, int m)
180 return new Full_storage(n,m);