comparison liboctave/chMatrix.cc @ 6979:2883ea1c5c18

[project @ 2007-10-08 20:23:48 by dbateman]
author dbateman
date Mon, 08 Oct 2007 20:26:01 +0000
parents 7f5316cadaa2
children 93c65f2a5668
comparison
equal deleted inserted replaced
6978:b75630794a11 6979:2883ea1c5c18
187 result.elem (i, j) = elem (r1+i, c1+j); 187 result.elem (i, j) = elem (r1+i, c1+j);
188 188
189 return result; 189 return result;
190 } 190 }
191 191
192 charMatrix
193 charMatrix::diag (void) const
194 {
195 return diag (0);
196 }
197
198 charMatrix
199 charMatrix::diag (octave_idx_type k) const
200 {
201 octave_idx_type nnr = rows ();
202 octave_idx_type nnc = cols ();
203 if (k > 0)
204 nnc -= k;
205 else if (k < 0)
206 nnr += k;
207
208 charMatrix d;
209
210 if (nnr > 0 && nnc > 0)
211 {
212 octave_idx_type ndiag = (nnr < nnc) ? nnr : nnc;
213
214 d.resize (ndiag, 1);
215
216 if (k > 0)
217 {
218 for (octave_idx_type i = 0; i < ndiag; i++)
219 d.xelem (i) = elem (i, i+k);
220 }
221 else if (k < 0)
222 {
223 for (octave_idx_type i = 0; i < ndiag; i++)
224 d.xelem (i) = elem (i-k, i);
225 }
226 else
227 {
228 for (octave_idx_type i = 0; i < ndiag; i++)
229 d.xelem (i) = elem (i, i);
230 }
231 }
232 else
233 (*current_liboctave_error_handler)
234 ("diag: requested diagonal out of range");
235
236 return d;
237 }
238
192 // FIXME Do these really belong here? Maybe they should be 239 // FIXME Do these really belong here? Maybe they should be
193 // in a base class? 240 // in a base class?
194 241
195 boolMatrix 242 boolMatrix
196 charMatrix::all (int dim) const 243 charMatrix::all (int dim) const