Mercurial > octave
comparison liboctave/numeric/fCmplxQR.cc @ 21136:7cac4e7458f2
maint: clean up code around calls to current_liboctave_error_handler.
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
* Array-util.cc, Array.cc, CColVector.cc, CDiagMatrix.cc, CMatrix.cc,
CNDArray.cc, CRowVector.cc, CSparse.cc, DiagArray2.cc, MArray.cc,
PermMatrix.cc, Sparse.cc, Sparse.h, chMatrix.cc, chNDArray.cc, dColVector.cc,
dDiagMatrix.cc, dMatrix.cc, dNDArray.cc, dRowVector.cc, dSparse.cc,
fCColVector.cc, fCDiagMatrix.cc, fCMatrix.cc, fCNDArray.cc, fCRowVector.cc,
fColVector.cc, fDiagMatrix.cc, fMatrix.cc, fNDArray.cc, fRowVector.cc,
idx-vector.cc, CmplxAEPBAL.cc, CmplxCHOL.cc, CmplxGEPBAL.cc, CmplxHESS.cc,
CmplxLU.cc, CmplxQR.cc, CmplxSCHUR.cc, CmplxSVD.cc, DASPK.cc, EIG.cc, LSODE.cc,
Quad.cc, SparseCmplxCHOL.cc, SparseCmplxLU.cc, SparseCmplxQR.cc, SparseQR.cc,
SparsedbleCHOL.cc, SparsedbleLU.cc, base-lu.cc, bsxfun-defs.cc, dbleAEPBAL.cc,
dbleCHOL.cc, dbleGEPBAL.cc, dbleHESS.cc, dbleLU.cc, dbleQR.cc, dbleSCHUR.cc,
dbleSVD.cc, eigs-base.cc, fCmplxAEPBAL.cc, fCmplxCHOL.cc, fCmplxLU.cc,
fCmplxQR.cc, fCmplxSCHUR.cc, fEIG.cc, floatAEPBAL.cc, floatCHOL.cc,
floatGEPBAL.cc, floatHESS.cc, floatLU.cc, floatQR.cc, floatSCHUR.cc,
floatSVD.cc, lo-specfun.cc, oct-fftw.cc, oct-rand.cc, oct-spparms.cc,
sparse-base-chol.cc, sparse-dmsolve.cc, file-ops.cc, lo-sysdep.cc,
mach-info.cc, oct-env.cc, oct-syscalls.cc, cmd-edit.cc, cmd-hist.cc,
data-conv.cc, lo-ieee.cc, lo-regexp.cc, oct-base64.cc, oct-shlib.cc,
pathsearch.cc, singleton-cleanup.cc, sparse-util.cc, unwind-prot.cc:
Remove statements after call to handler that are no longer reachable.
Place input validation first and immediately call handler if necessary.
Change if/error_handler/else to if/error_handler and re-indent code.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 23 Jan 2016 13:52:03 -0800 |
parents | a9574e3c6e9e |
children | f7121e111991 |
comparison
equal
deleted
inserted
replaced
21135:95da3bc8a281 | 21136:7cac4e7458f2 |
---|---|
214 { | 214 { |
215 octave_idx_type m = q.rows (); | 215 octave_idx_type m = q.rows (); |
216 octave_idx_type n = r.columns (); | 216 octave_idx_type n = r.columns (); |
217 octave_idx_type k = q.columns (); | 217 octave_idx_type k = q.columns (); |
218 | 218 |
219 if (u.numel () == m && v.numel () == n) | 219 if (u.numel () != m || v.numel () != n) |
220 { | 220 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); |
221 FloatComplexColumnVector utmp = u; | 221 |
222 FloatComplexColumnVector vtmp = v; | 222 FloatComplexColumnVector utmp = u; |
223 OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); | 223 FloatComplexColumnVector vtmp = v; |
224 OCTAVE_LOCAL_BUFFER (float, rw, k); | 224 OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); |
225 OCTAVE_LOCAL_BUFFER (float, rw, k); | |
226 F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), | |
227 m, r.fortran_vec (), k, | |
228 utmp.fortran_vec (), vtmp.fortran_vec (), | |
229 w, rw)); | |
230 } | |
231 | |
232 void | |
233 FloatComplexQR::update (const FloatComplexMatrix& u, | |
234 const FloatComplexMatrix& v) | |
235 { | |
236 octave_idx_type m = q.rows (); | |
237 octave_idx_type n = r.columns (); | |
238 octave_idx_type k = q.columns (); | |
239 | |
240 if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) | |
241 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); | |
242 | |
243 OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); | |
244 OCTAVE_LOCAL_BUFFER (float, rw, k); | |
245 for (volatile octave_idx_type i = 0; i < u.cols (); i++) | |
246 { | |
247 FloatComplexColumnVector utmp = u.column (i); | |
248 FloatComplexColumnVector vtmp = v.column (i); | |
225 F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), | 249 F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), |
226 m, r.fortran_vec (), k, | 250 m, r.fortran_vec (), k, |
227 utmp.fortran_vec (), vtmp.fortran_vec (), | 251 utmp.fortran_vec (), vtmp.fortran_vec (), |
228 w, rw)); | 252 w, rw)); |
229 } | 253 } |
230 else | |
231 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); | |
232 } | |
233 | |
234 void | |
235 FloatComplexQR::update (const FloatComplexMatrix& u, | |
236 const FloatComplexMatrix& v) | |
237 { | |
238 octave_idx_type m = q.rows (); | |
239 octave_idx_type n = r.columns (); | |
240 octave_idx_type k = q.columns (); | |
241 | |
242 if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) | |
243 { | |
244 OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); | |
245 OCTAVE_LOCAL_BUFFER (float, rw, k); | |
246 for (volatile octave_idx_type i = 0; i < u.cols (); i++) | |
247 { | |
248 FloatComplexColumnVector utmp = u.column (i); | |
249 FloatComplexColumnVector vtmp = v.column (i); | |
250 F77_XFCN (cqr1up, CQR1UP, (m, n, k, q.fortran_vec (), | |
251 m, r.fortran_vec (), k, | |
252 utmp.fortran_vec (), vtmp.fortran_vec (), | |
253 w, rw)); | |
254 } | |
255 } | |
256 else | |
257 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); | |
258 } | 254 } |
259 | 255 |
260 void | 256 void |
261 FloatComplexQR::insert_col (const FloatComplexColumnVector& u, | 257 FloatComplexQR::insert_col (const FloatComplexColumnVector& u, |
262 octave_idx_type j) | 258 octave_idx_type j) |
265 octave_idx_type n = r.columns (); | 261 octave_idx_type n = r.columns (); |
266 octave_idx_type k = q.columns (); | 262 octave_idx_type k = q.columns (); |
267 | 263 |
268 if (u.numel () != m) | 264 if (u.numel () != m) |
269 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); | 265 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); |
270 else if (j < 0 || j > n) | 266 if (j < 0 || j > n) |
271 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 267 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
268 | |
269 if (k < m) | |
270 { | |
271 q.resize (m, k+1); | |
272 r.resize (k+1, n+1); | |
273 } | |
272 else | 274 else |
273 { | 275 { |
274 if (k < m) | 276 r.resize (k, n+1); |
275 { | 277 } |
276 q.resize (m, k+1); | 278 |
277 r.resize (k+1, n+1); | 279 FloatComplexColumnVector utmp = u; |
278 } | 280 OCTAVE_LOCAL_BUFFER (float, rw, k); |
279 else | 281 F77_XFCN (cqrinc, CQRINC, (m, n, k, q.fortran_vec (), q.rows (), |
280 { | 282 r.fortran_vec (), r.rows (), j + 1, |
281 r.resize (k, n+1); | 283 utmp.data (), rw)); |
282 } | |
283 | |
284 FloatComplexColumnVector utmp = u; | |
285 OCTAVE_LOCAL_BUFFER (float, rw, k); | |
286 F77_XFCN (cqrinc, CQRINC, (m, n, k, q.fortran_vec (), q.rows (), | |
287 r.fortran_vec (), r.rows (), j + 1, | |
288 utmp.data (), rw)); | |
289 } | |
290 } | 284 } |
291 | 285 |
292 void | 286 void |
293 FloatComplexQR::insert_col (const FloatComplexMatrix& u, | 287 FloatComplexQR::insert_col (const FloatComplexMatrix& u, |
294 const Array<octave_idx_type>& j) | 288 const Array<octave_idx_type>& j) |
304 for (octave_idx_type i = 0; i < nj - 1; i++) | 298 for (octave_idx_type i = 0; i < nj - 1; i++) |
305 dups = dups && js(i) == js(i+1); | 299 dups = dups && js(i) == js(i+1); |
306 | 300 |
307 if (dups) | 301 if (dups) |
308 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); | 302 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); |
309 else if (u.numel () != m || u.columns () != nj) | 303 if (u.numel () != m || u.columns () != nj) |
310 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); | 304 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); |
311 else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) | 305 if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) |
312 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 306 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
313 else if (nj > 0) | 307 |
308 if (nj > 0) | |
314 { | 309 { |
315 octave_idx_type kmax = std::min (k + nj, m); | 310 octave_idx_type kmax = std::min (k + nj, m); |
316 if (k < m) | 311 if (k < m) |
317 { | 312 { |
318 q.resize (m, kmax); | 313 q.resize (m, kmax); |
342 octave_idx_type k = r.rows (); | 337 octave_idx_type k = r.rows (); |
343 octave_idx_type n = r.columns (); | 338 octave_idx_type n = r.columns (); |
344 | 339 |
345 if (j < 0 || j > n-1) | 340 if (j < 0 || j > n-1) |
346 (*current_liboctave_error_handler) ("qrdelete: index out of range"); | 341 (*current_liboctave_error_handler) ("qrdelete: index out of range"); |
342 | |
343 OCTAVE_LOCAL_BUFFER (float, rw, k); | |
344 F77_XFCN (cqrdec, CQRDEC, (m, n, k, q.fortran_vec (), q.rows (), | |
345 r.fortran_vec (), r.rows (), j + 1, rw)); | |
346 | |
347 if (k < m) | |
348 { | |
349 q.resize (m, k-1); | |
350 r.resize (k-1, n-1); | |
351 } | |
347 else | 352 else |
348 { | 353 { |
349 OCTAVE_LOCAL_BUFFER (float, rw, k); | 354 r.resize (k, n-1); |
350 F77_XFCN (cqrdec, CQRDEC, (m, n, k, q.fortran_vec (), q.rows (), | |
351 r.fortran_vec (), r.rows (), j + 1, rw)); | |
352 | |
353 if (k < m) | |
354 { | |
355 q.resize (m, k-1); | |
356 r.resize (k-1, n-1); | |
357 } | |
358 else | |
359 { | |
360 r.resize (k, n-1); | |
361 } | |
362 } | 355 } |
363 } | 356 } |
364 | 357 |
365 void | 358 void |
366 FloatComplexQR::delete_col (const Array<octave_idx_type>& j) | 359 FloatComplexQR::delete_col (const Array<octave_idx_type>& j) |
376 for (octave_idx_type i = 0; i < nj - 1; i++) | 369 for (octave_idx_type i = 0; i < nj - 1; i++) |
377 dups = dups && js(i) == js(i+1); | 370 dups = dups && js(i) == js(i+1); |
378 | 371 |
379 if (dups) | 372 if (dups) |
380 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); | 373 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); |
381 else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) | 374 if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) |
382 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 375 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
383 else if (nj > 0) | 376 |
377 if (nj > 0) | |
384 { | 378 { |
385 OCTAVE_LOCAL_BUFFER (float, rw, k); | 379 OCTAVE_LOCAL_BUFFER (float, rw, k); |
386 for (volatile octave_idx_type i = 0; i < js.numel (); i++) | 380 for (volatile octave_idx_type i = 0; i < js.numel (); i++) |
387 { | 381 { |
388 octave_idx_type ii = i; | 382 octave_idx_type ii = i; |
411 octave_idx_type n = r.columns (); | 405 octave_idx_type n = r.columns (); |
412 octave_idx_type k = std::min (m, n); | 406 octave_idx_type k = std::min (m, n); |
413 | 407 |
414 if (! q.is_square () || u.numel () != n) | 408 if (! q.is_square () || u.numel () != n) |
415 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); | 409 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); |
416 else if (j < 0 || j > m) | 410 if (j < 0 || j > m) |
417 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 411 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
418 else | 412 |
419 { | 413 q.resize (m + 1, m + 1); |
420 q.resize (m + 1, m + 1); | 414 r.resize (m + 1, n); |
421 r.resize (m + 1, n); | 415 FloatComplexRowVector utmp = u; |
422 FloatComplexRowVector utmp = u; | 416 OCTAVE_LOCAL_BUFFER (float, rw, k); |
423 OCTAVE_LOCAL_BUFFER (float, rw, k); | 417 F77_XFCN (cqrinr, CQRINR, (m, n, q.fortran_vec (), q.rows (), |
424 F77_XFCN (cqrinr, CQRINR, (m, n, q.fortran_vec (), q.rows (), | 418 r.fortran_vec (), r.rows (), |
425 r.fortran_vec (), r.rows (), | 419 j + 1, utmp.fortran_vec (), rw)); |
426 j + 1, utmp.fortran_vec (), rw)); | 420 |
427 | |
428 } | |
429 } | 421 } |
430 | 422 |
431 void | 423 void |
432 FloatComplexQR::delete_row (octave_idx_type j) | 424 FloatComplexQR::delete_row (octave_idx_type j) |
433 { | 425 { |
434 octave_idx_type m = r.rows (); | 426 octave_idx_type m = r.rows (); |
435 octave_idx_type n = r.columns (); | 427 octave_idx_type n = r.columns (); |
436 | 428 |
437 if (! q.is_square ()) | 429 if (! q.is_square ()) |
438 (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); | 430 (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); |
439 else if (j < 0 || j > m-1) | 431 if (j < 0 || j > m-1) |
440 (*current_liboctave_error_handler) ("qrdelete: index out of range"); | 432 (*current_liboctave_error_handler) ("qrdelete: index out of range"); |
441 else | 433 |
442 { | 434 OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); |
443 OCTAVE_LOCAL_BUFFER (FloatComplex, w, m); | 435 OCTAVE_LOCAL_BUFFER (float, rw, m); |
444 OCTAVE_LOCAL_BUFFER (float, rw, m); | 436 F77_XFCN (cqrder, CQRDER, (m, n, q.fortran_vec (), q.rows (), |
445 F77_XFCN (cqrder, CQRDER, (m, n, q.fortran_vec (), q.rows (), | 437 r.fortran_vec (), r.rows (), j + 1, |
446 r.fortran_vec (), r.rows (), j + 1, | 438 w, rw)); |
447 w, rw)); | 439 |
448 | 440 q.resize (m - 1, m - 1); |
449 q.resize (m - 1, m - 1); | 441 r.resize (m - 1, n); |
450 r.resize (m - 1, n); | |
451 } | |
452 } | 442 } |
453 | 443 |
454 void | 444 void |
455 FloatComplexQR::shift_cols (octave_idx_type i, octave_idx_type j) | 445 FloatComplexQR::shift_cols (octave_idx_type i, octave_idx_type j) |
456 { | 446 { |
458 octave_idx_type k = r.rows (); | 448 octave_idx_type k = r.rows (); |
459 octave_idx_type n = r.columns (); | 449 octave_idx_type n = r.columns (); |
460 | 450 |
461 if (i < 0 || i > n-1 || j < 0 || j > n-1) | 451 if (i < 0 || i > n-1 || j < 0 || j > n-1) |
462 (*current_liboctave_error_handler) ("qrshift: index out of range"); | 452 (*current_liboctave_error_handler) ("qrshift: index out of range"); |
463 else | 453 |
464 { | 454 OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); |
465 OCTAVE_LOCAL_BUFFER (FloatComplex, w, k); | 455 OCTAVE_LOCAL_BUFFER (float, rw, k); |
466 OCTAVE_LOCAL_BUFFER (float, rw, k); | 456 F77_XFCN (cqrshc, CQRSHC, (m, n, k, |
467 F77_XFCN (cqrshc, CQRSHC, (m, n, k, | 457 q.fortran_vec (), q.rows (), |
468 q.fortran_vec (), q.rows (), | 458 r.fortran_vec (), r.rows (), |
469 r.fortran_vec (), r.rows (), | 459 i + 1, j + 1, w, rw)); |
470 i + 1, j + 1, w, rw)); | |
471 } | |
472 } | 460 } |
473 | 461 |
474 #else | 462 #else |
475 | 463 |
476 // Replacement update methods. | 464 // Replacement update methods. |
482 warn_qrupdate_once (); | 470 warn_qrupdate_once (); |
483 | 471 |
484 octave_idx_type m = q.rows (); | 472 octave_idx_type m = q.rows (); |
485 octave_idx_type n = r.columns (); | 473 octave_idx_type n = r.columns (); |
486 | 474 |
487 if (u.numel () == m && v.numel () == n) | 475 if (u.numel () != m || v.numel () != n) |
488 { | |
489 init (q*r + FloatComplexMatrix (u) * FloatComplexMatrix (v).hermitian (), | |
490 get_type ()); | |
491 } | |
492 else | |
493 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); | 476 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); |
477 | |
478 init (q*r + FloatComplexMatrix (u) * FloatComplexMatrix (v).hermitian (), | |
479 get_type ()); | |
494 } | 480 } |
495 | 481 |
496 void | 482 void |
497 FloatComplexQR::update (const FloatComplexMatrix& u, | 483 FloatComplexQR::update (const FloatComplexMatrix& u, |
498 const FloatComplexMatrix& v) | 484 const FloatComplexMatrix& v) |
500 warn_qrupdate_once (); | 486 warn_qrupdate_once (); |
501 | 487 |
502 octave_idx_type m = q.rows (); | 488 octave_idx_type m = q.rows (); |
503 octave_idx_type n = r.columns (); | 489 octave_idx_type n = r.columns (); |
504 | 490 |
505 if (u.rows () == m && v.rows () == n && u.cols () == v.cols ()) | 491 if (u.rows () != m || v.rows () != n || u.cols () != v.cols ()) |
506 { | |
507 init (q*r + u * v.hermitian (), get_type ()); | |
508 } | |
509 else | |
510 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); | 492 (*current_liboctave_error_handler) ("qrupdate: dimensions mismatch"); |
493 | |
494 init (q*r + u * v.hermitian (), get_type ()); | |
511 } | 495 } |
512 | 496 |
513 static | 497 static |
514 FloatComplexMatrix insert_col (const FloatComplexMatrix& a, octave_idx_type i, | 498 FloatComplexMatrix insert_col (const FloatComplexMatrix& a, octave_idx_type i, |
515 const FloatComplexColumnVector& x) | 499 const FloatComplexColumnVector& x) |
582 octave_idx_type m = q.rows (); | 566 octave_idx_type m = q.rows (); |
583 octave_idx_type n = r.columns (); | 567 octave_idx_type n = r.columns (); |
584 | 568 |
585 if (u.numel () != m) | 569 if (u.numel () != m) |
586 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); | 570 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); |
587 else if (j < 0 || j > n) | 571 if (j < 0 || j > n) |
588 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 572 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
589 else | 573 |
590 { | 574 init (::insert_col (q*r, j, u), get_type ()); |
591 init (::insert_col (q*r, j, u), get_type ()); | |
592 } | |
593 } | 575 } |
594 | 576 |
595 void | 577 void |
596 FloatComplexQR::insert_col (const FloatComplexMatrix& u, | 578 FloatComplexQR::insert_col (const FloatComplexMatrix& u, |
597 const Array<octave_idx_type>& j) | 579 const Array<octave_idx_type>& j) |
608 for (octave_idx_type i = 0; i < nj - 1; i++) | 590 for (octave_idx_type i = 0; i < nj - 1; i++) |
609 dups = dups && js(i) == js(i+1); | 591 dups = dups && js(i) == js(i+1); |
610 | 592 |
611 if (dups) | 593 if (dups) |
612 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); | 594 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); |
613 else if (u.numel () != m || u.columns () != nj) | 595 if (u.numel () != m || u.columns () != nj) |
614 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); | 596 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); |
615 else if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) | 597 if (nj > 0 && (js(0) < 0 || js(nj-1) > n)) |
616 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 598 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
617 else if (nj > 0) | 599 |
600 if (nj > 0) | |
618 { | 601 { |
619 FloatComplexMatrix a = q*r; | 602 FloatComplexMatrix a = q*r; |
620 for (octave_idx_type i = 0; i < js.numel (); i++) | 603 for (octave_idx_type i = 0; i < js.numel (); i++) |
621 a = ::insert_col (a, js(i), u.column (i)); | 604 a = ::insert_col (a, js(i), u.column (i)); |
622 init (a, get_type ()); | 605 init (a, get_type ()); |
630 | 613 |
631 octave_idx_type n = r.columns (); | 614 octave_idx_type n = r.columns (); |
632 | 615 |
633 if (j < 0 || j > n-1) | 616 if (j < 0 || j > n-1) |
634 (*current_liboctave_error_handler) ("qrdelete: index out of range"); | 617 (*current_liboctave_error_handler) ("qrdelete: index out of range"); |
635 else | 618 |
636 { | 619 init (::delete_col (q*r, j), get_type ()); |
637 init (::delete_col (q*r, j), get_type ()); | |
638 } | |
639 } | 620 } |
640 | 621 |
641 void | 622 void |
642 FloatComplexQR::delete_col (const Array<octave_idx_type>& j) | 623 FloatComplexQR::delete_col (const Array<octave_idx_type>& j) |
643 { | 624 { |
652 for (octave_idx_type i = 0; i < nj - 1; i++) | 633 for (octave_idx_type i = 0; i < nj - 1; i++) |
653 dups = dups && js(i) == js(i+1); | 634 dups = dups && js(i) == js(i+1); |
654 | 635 |
655 if (dups) | 636 if (dups) |
656 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); | 637 (*current_liboctave_error_handler) ("qrinsert: duplicate index detected"); |
657 else if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) | 638 if (nj > 0 && (js(0) > n-1 || js(nj-1) < 0)) |
658 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 639 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
659 else if (nj > 0) | 640 |
641 if (nj > 0) | |
660 { | 642 { |
661 FloatComplexMatrix a = q*r; | 643 FloatComplexMatrix a = q*r; |
662 for (octave_idx_type i = 0; i < js.numel (); i++) | 644 for (octave_idx_type i = 0; i < js.numel (); i++) |
663 a = ::delete_col (a, js(i)); | 645 a = ::delete_col (a, js(i)); |
664 init (a, get_type ()); | 646 init (a, get_type ()); |
673 octave_idx_type m = r.rows (); | 655 octave_idx_type m = r.rows (); |
674 octave_idx_type n = r.columns (); | 656 octave_idx_type n = r.columns (); |
675 | 657 |
676 if (! q.is_square () || u.numel () != n) | 658 if (! q.is_square () || u.numel () != n) |
677 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); | 659 (*current_liboctave_error_handler) ("qrinsert: dimensions mismatch"); |
678 else if (j < 0 || j > m) | 660 if (j < 0 || j > m) |
679 (*current_liboctave_error_handler) ("qrinsert: index out of range"); | 661 (*current_liboctave_error_handler) ("qrinsert: index out of range"); |
680 else | 662 |
681 { | 663 init (::insert_row (q*r, j, u), get_type ()); |
682 init (::insert_row (q*r, j, u), get_type ()); | |
683 } | |
684 } | 664 } |
685 | 665 |
686 void | 666 void |
687 FloatComplexQR::delete_row (octave_idx_type j) | 667 FloatComplexQR::delete_row (octave_idx_type j) |
688 { | 668 { |
690 | 670 |
691 octave_idx_type m = r.rows (); | 671 octave_idx_type m = r.rows (); |
692 | 672 |
693 if (! q.is_square ()) | 673 if (! q.is_square ()) |
694 (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); | 674 (*current_liboctave_error_handler) ("qrdelete: dimensions mismatch"); |
695 else if (j < 0 || j > m-1) | 675 if (j < 0 || j > m-1) |
696 (*current_liboctave_error_handler) ("qrdelete: index out of range"); | 676 (*current_liboctave_error_handler) ("qrdelete: index out of range"); |
697 else | 677 |
698 { | 678 init (::delete_row (q*r, j), get_type ()); |
699 init (::delete_row (q*r, j), get_type ()); | |
700 } | |
701 } | 679 } |
702 | 680 |
703 void | 681 void |
704 FloatComplexQR::shift_cols (octave_idx_type i, octave_idx_type j) | 682 FloatComplexQR::shift_cols (octave_idx_type i, octave_idx_type j) |
705 { | 683 { |
707 | 685 |
708 octave_idx_type n = r.columns (); | 686 octave_idx_type n = r.columns (); |
709 | 687 |
710 if (i < 0 || i > n-1 || j < 0 || j > n-1) | 688 if (i < 0 || i > n-1 || j < 0 || j > n-1) |
711 (*current_liboctave_error_handler) ("qrshift: index out of range"); | 689 (*current_liboctave_error_handler) ("qrshift: index out of range"); |
712 else | 690 |
713 { | 691 init (::shift_cols (q*r, i, j), get_type ()); |
714 init (::shift_cols (q*r, i, j), get_type ()); | |
715 } | |
716 } | 692 } |
717 | 693 |
718 #endif | 694 #endif |