Mercurial > octave-nkf
comparison liboctave/dMatrix.cc @ 4316:236c10efcde2
[project @ 2003-02-10 21:57:15 by jwe]
author | jwe |
---|---|
date | Mon, 10 Feb 2003 21:57:15 +0000 |
parents | a9560cebae6e |
children | d53c33d93440 |
comparison
equal
deleted
inserted
replaced
4315:0a056052bc90 | 4316:236c10efcde2 |
---|---|
197 | 197 |
198 Matrix& | 198 Matrix& |
199 Matrix::insert (const RowVector& a, int r, int c) | 199 Matrix::insert (const RowVector& a, int r, int c) |
200 { | 200 { |
201 int a_len = a.length (); | 201 int a_len = a.length (); |
202 | |
202 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) | 203 if (r < 0 || r >= rows () || c < 0 || c + a_len > cols ()) |
203 { | 204 { |
204 (*current_liboctave_error_handler) ("range error for insert"); | 205 (*current_liboctave_error_handler) ("range error for insert"); |
205 return *this; | 206 return *this; |
206 } | 207 } |
207 | 208 |
208 for (int i = 0; i < a_len; i++) | 209 if (a_len > 0) |
209 elem (r, c+i) = a.elem (i); | 210 { |
211 make_unique (); | |
212 | |
213 for (int i = 0; i < a_len; i++) | |
214 xelem (r, c+i) = a.elem (i); | |
215 } | |
210 | 216 |
211 return *this; | 217 return *this; |
212 } | 218 } |
213 | 219 |
214 Matrix& | 220 Matrix& |
215 Matrix::insert (const ColumnVector& a, int r, int c) | 221 Matrix::insert (const ColumnVector& a, int r, int c) |
216 { | 222 { |
217 int a_len = a.length (); | 223 int a_len = a.length (); |
224 | |
218 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) | 225 if (r < 0 || r + a_len > rows () || c < 0 || c >= cols ()) |
219 { | 226 { |
220 (*current_liboctave_error_handler) ("range error for insert"); | 227 (*current_liboctave_error_handler) ("range error for insert"); |
221 return *this; | 228 return *this; |
222 } | 229 } |
223 | 230 |
224 for (int i = 0; i < a_len; i++) | 231 if (a_len > 0) |
225 elem (r+i, c) = a.elem (i); | 232 { |
233 make_unique (); | |
234 | |
235 for (int i = 0; i < a_len; i++) | |
236 xelem (r+i, c) = a.elem (i); | |
237 } | |
226 | 238 |
227 return *this; | 239 return *this; |
228 } | 240 } |
229 | 241 |
230 Matrix& | 242 Matrix& |
239 return *this; | 251 return *this; |
240 } | 252 } |
241 | 253 |
242 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); | 254 fill (0.0, r, c, r + a_nr - 1, c + a_nc - 1); |
243 | 255 |
244 for (int i = 0; i < a.length (); i++) | 256 int a_len = a.length (); |
245 elem (r+i, c+i) = a.elem (i, i); | 257 |
258 if (a_len > 0) | |
259 { | |
260 make_unique (); | |
261 | |
262 for (int i = 0; i < a_len; i++) | |
263 xelem (r+i, c+i) = a.elem (i, i); | |
264 } | |
246 | 265 |
247 return *this; | 266 return *this; |
248 } | 267 } |
249 | 268 |
250 Matrix& | 269 Matrix& |
251 Matrix::fill (double val) | 270 Matrix::fill (double val) |
252 { | 271 { |
253 int nr = rows (); | 272 int nr = rows (); |
254 int nc = cols (); | 273 int nc = cols (); |
274 | |
255 if (nr > 0 && nc > 0) | 275 if (nr > 0 && nc > 0) |
256 for (int j = 0; j < nc; j++) | 276 { |
257 for (int i = 0; i < nr; i++) | 277 make_unique (); |
258 elem (i, j) = val; | 278 |
279 for (int j = 0; j < nc; j++) | |
280 for (int i = 0; i < nr; i++) | |
281 xelem (i, j) = val; | |
282 } | |
259 | 283 |
260 return *this; | 284 return *this; |
261 } | 285 } |
262 | 286 |
263 Matrix& | 287 Matrix& |
264 Matrix::fill (double val, int r1, int c1, int r2, int c2) | 288 Matrix::fill (double val, int r1, int c1, int r2, int c2) |
265 { | 289 { |
266 int nr = rows (); | 290 int nr = rows (); |
267 int nc = cols (); | 291 int nc = cols (); |
292 | |
268 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 | 293 if (r1 < 0 || r2 < 0 || c1 < 0 || c2 < 0 |
269 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) | 294 || r1 >= nr || r2 >= nr || c1 >= nc || c2 >= nc) |
270 { | 295 { |
271 (*current_liboctave_error_handler) ("range error for fill"); | 296 (*current_liboctave_error_handler) ("range error for fill"); |
272 return *this; | 297 return *this; |
273 } | 298 } |
274 | 299 |
275 if (r1 > r2) { int tmp = r1; r1 = r2; r2 = tmp; } | 300 if (r1 > r2) { int tmp = r1; r1 = r2; r2 = tmp; } |
276 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } | 301 if (c1 > c2) { int tmp = c1; c1 = c2; c2 = tmp; } |
277 | 302 |
278 for (int j = c1; j <= c2; j++) | 303 if (r2 >= r1 && c2 >= c1) |
279 for (int i = r1; i <= r2; i++) | 304 { |
280 elem (i, j) = val; | 305 make_unique (); |
306 | |
307 for (int j = c1; j <= c2; j++) | |
308 for (int i = r1; i <= r2; i++) | |
309 xelem (i, j) = val; | |
310 } | |
281 | 311 |
282 return *this; | 312 return *this; |
283 } | 313 } |
284 | 314 |
285 Matrix | 315 Matrix |
463 | 493 |
464 Matrix result (new_r, new_c); | 494 Matrix result (new_r, new_c); |
465 | 495 |
466 for (int j = 0; j < new_c; j++) | 496 for (int j = 0; j < new_c; j++) |
467 for (int i = 0; i < new_r; i++) | 497 for (int i = 0; i < new_r; i++) |
468 result.elem (i, j) = elem (r1+i, c1+j); | 498 result.xelem (i, j) = elem (r1+i, c1+j); |
499 | |
500 return result; | |
501 } | |
502 | |
503 Matrix | |
504 Matrix::extract_n (int r1, int c1, int nr, int nc) const | |
505 { | |
506 Matrix result (nr, nc); | |
507 | |
508 for (int j = 0; j < nc; j++) | |
509 for (int i = 0; i < nr; i++) | |
510 result.xelem (i, j) = elem (r1+i, c1+j); | |
469 | 511 |
470 return result; | 512 return result; |
471 } | 513 } |
472 | 514 |
473 // extract row or column i. | 515 // extract row or column i. |
482 return RowVector (); | 524 return RowVector (); |
483 } | 525 } |
484 | 526 |
485 RowVector retval (nc); | 527 RowVector retval (nc); |
486 for (int j = 0; j < nc; j++) | 528 for (int j = 0; j < nc; j++) |
487 retval.elem (j) = elem (i, j); | 529 retval.xelem (j) = elem (i, j); |
488 | 530 |
489 return retval; | 531 return retval; |
490 } | 532 } |
491 | 533 |
492 RowVector | 534 RowVector |
520 return ColumnVector (); | 562 return ColumnVector (); |
521 } | 563 } |
522 | 564 |
523 ColumnVector retval (nr); | 565 ColumnVector retval (nr); |
524 for (int j = 0; j < nr; j++) | 566 for (int j = 0; j < nr; j++) |
525 retval.elem (j) = elem (j, i); | 567 retval.xelem (j) = elem (j, i); |
526 | 568 |
527 return retval; | 569 return retval; |
528 } | 570 } |
529 | 571 |
530 ColumnVector | 572 ColumnVector |