]> git.donarmstrong.com Git - lilypond.git/blob - flower/smat.cc
release: 0.0.40
[lilypond.git] / flower / 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 #ifndef NDEBUG
18     //    static Real dummy;            
19     assert(maxh >= h && maxw >= w);
20     assert(h >= 0 && w >= 0);
21     assert(els||!maxh);
22 #endif
23 }
24 void
25 Full_storage::resize_cols(int newh)
26 {
27     if (newh <= maxh) {
28         h=newh;
29         return;
30     }
31    
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;
40
41     h = maxh = newh;
42 }
43
44 void
45 Full_storage::resize_rows(int neww)
46 {
47     if (neww <= maxw) {
48         w=neww;
49         return;
50     }
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];
55
56         delete[] els[i];
57         els[i] = newa;
58     }
59     w = maxw = neww;    
60 }
61
62 Full_storage::~Full_storage() {
63     for (int i=0; i < maxh; i++)
64         delete [] els[i];
65     delete[] els;
66 }
67
68 void
69 Full_storage::resize(int rows, int cols)
70 {
71     OK();
72     resize_cols(rows);
73     resize_rows(cols);
74
75 }
76
77
78 bool
79 Full_storage::mult_ok(int i, int j) const
80 {
81     return valid(i,j);
82 }
83
84 bool
85 Full_storage::trans_ok(int i, int j) const
86 {
87        return valid(i,j);
88
89
90
91 void
92 Full_storage::trans_next(int &i, int &j) const
93 {
94     assert(trans_ok(i,j));
95     i++;
96     if (i >= h) {
97         i=0;
98         j ++;
99     }
100 }
101
102 void
103 Full_storage::mult_next(int &i, int &j) const
104 {
105     assert(mult_ok(i,j));
106     j++;
107     if (j >= w) {
108         j=0;
109         i++;
110     }
111 }
112
113 void
114 Full_storage::delete_column(int k)
115 {
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--;
121 }
122 void
123 Full_storage::delete_row(int k)
124 {
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--;
130 }
131
132
133 void
134 Full_storage::insert_row(int k)
135 {
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];
141
142 }
143
144
145 Array<Real>
146 Full_storage::row(int n) const
147 {
148     Array<Real> r;
149     for (int j = 0; j < w; j++)
150         r.push(els[n][j]);
151     return r;
152 }
153
154 Array<Real>
155 Full_storage::column(int n) const
156 {
157     
158     Array<Real> r;
159     for (int i = 0; i<h; i++)
160         r.push(els[i][n]);
161     return r;
162 }
163
164
165 Full_storage::Full_storage(Full_storage&s)
166 {
167     init();
168     (*this) = s;
169 }
170 virtual_smat*
171 Full_storage::clone()
172 {
173     return new Full_storage(*this);
174 }
175
176
177 virtual_smat *
178 virtual_smat::get_full(int n, int m)
179 {
180     return new Full_storage(n,m);
181 }