316 int nargin = args.length ();
318 if (nargin < 1 || nargin > 3)
322 error (
"qr: too many output arguments");
328 bool economy =
false;
329 bool is_cmplx =
false;
331 bool vector_p =
false;
338 if (args(nargin-1).is_scalar_type ())
340 int val = args(nargin-1).int_value ();
345 have_b = (nargin > 2);
347 else if (nargin == 3)
350 else if (args(nargin-1).is_string ())
352 std::string str = args(nargin-1).string_value ();
355 else if (str ==
"vector")
357 else if (str !=
"matrix")
358 error (
"qr: option string must be 'econ' or 'matrix' or 'vector', not \"%s\"", str.c_str ());
359 have_b = (nargin > 2);
361 else if (! args(nargin-1).isnumeric ())
363 else if (nargin == 3)
366 if (have_b && ! args(1).isnumeric ())
369 if (have_b && args(1).iscomplex ())
377 if (have_b && nargout == 1)
381 if (! args(1).issparse () && args(1).iscomplex ())
383 (math::sparse_qr<SparseComplexMatrix>::solve
386 args(1).complex_matrix_value (), info));
387 else if (args(1).issparse () && args(1).iscomplex ())
389 (math::sparse_qr<SparseComplexMatrix>::solve
392 args(1).sparse_complex_matrix_value (), info));
393 else if (! args(1).issparse () && ! args(1).iscomplex ())
395 (math::sparse_qr<SparseComplexMatrix>::solve
398 args(1).matrix_value (), info));
399 else if (args(1).issparse () && ! args(1).iscomplex ())
401 (math::sparse_qr<SparseComplexMatrix>::solve
404 args(1).sparse_matrix_value (), info));
406 else if (have_b && nargout == 2)
408 math::sparse_qr<SparseComplexMatrix>
410 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
413 else if (have_b && nargout == 3)
415 math::sparse_qr<SparseComplexMatrix>
418 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
419 q.R (economy), q.E ().transpose ());
421 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
422 q.R (economy), q.E_MAT ());
428 math::sparse_qr<SparseComplexMatrix>
431 retval =
ovl (q.Q (economy), q.R (economy),
432 q.E ().transpose ());
434 retval =
ovl (q.Q (economy), q.R (economy),
437 else if (nargout > 1)
439 math::sparse_qr<SparseComplexMatrix>
441 retval =
ovl (q.Q (economy), q.R (economy));
445 math::sparse_qr<SparseComplexMatrix>
447 retval =
ovl (q.R (economy));
453 if (have_b && nargout == 1)
456 if (args(1).issparse () && ! args(1).iscomplex ())
457 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
460 args (1).sparse_matrix_value (), info));
461 else if (! args(1).issparse () && args(1).iscomplex ())
462 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
465 args (1).complex_matrix_value (), info));
466 else if (! args(1).issparse () && ! args(1).iscomplex ())
467 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
470 args (1).matrix_value (), info));
471 else if (args(1).issparse () && args(1).iscomplex ())
472 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
475 args(1).sparse_complex_matrix_value (),
478 else if (have_b && nargout == 2)
480 math::sparse_qr<SparseMatrix>
482 retval =
ovl (q.C (args(1).matrix_value (), economy),
485 else if (have_b && nargout == 3)
487 math::sparse_qr<SparseMatrix>
490 retval =
ovl (q.C (args(1).matrix_value (), economy),
491 q.R (economy), q.E ().transpose ());
493 retval =
ovl (q.C (args(1).matrix_value (), economy),
494 q.R (economy), q.E_MAT ());
501 math::sparse_qr<SparseMatrix>
504 retval =
ovl (q.Q (economy), q.R (economy),
505 q.E ().transpose ());
507 retval =
ovl (q.Q (economy), q.R (economy),
510 else if (nargout > 1)
512 math::sparse_qr<SparseMatrix>
514 retval =
ovl (q.Q (economy), q.R (economy));
518 math::sparse_qr<SparseMatrix>
520 retval =
ovl (q.R (economy));
527 if (have_b && nargout > 2)
528 error (
"qr: too many output arguments when called with A and B");
534 math::qr<FloatMatrix>::type type
535 = qr_type<FloatMatrix> (nargout, economy);
544 math::qr<FloatMatrix> fact (m, type);
545 retval =
ovl (fact.R ());
551 math::qr<FloatMatrix> fact (m, type);
552 retval =
ovl (fact.Q (), get_qr_r (fact));
556 retval(0) = fact.Q ().transpose ()
557 * args(1).float_complex_matrix_value ();
559 retval(0) = fact.Q ().transpose ()
560 * args(1).float_matrix_value ();
567 math::qrp<FloatMatrix> fact (m, type);
570 retval =
ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
572 retval =
ovl (fact.Q (), get_qr_r (fact), fact.P ());
579 math::qr<FloatComplexMatrix>::type type
580 = qr_type<FloatComplexMatrix> (nargout, economy);
589 math::qr<FloatComplexMatrix> fact (m, type);
590 retval =
ovl (fact.R ());
596 math::qr<FloatComplexMatrix> fact (m, type);
597 retval =
ovl (fact.Q (), get_qr_r (fact));
599 retval(0) =
conj (fact.Q ().transpose ())
600 * args(1).float_complex_matrix_value ();
606 math::qrp<FloatComplexMatrix> fact (m, type);
608 retval =
ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
610 retval =
ovl (fact.Q (), get_qr_r (fact), fact.P ());
620 math::qr<Matrix>::type type = qr_type<Matrix> (nargout, economy);
629 math::qr<Matrix> fact (m, type);
630 retval =
ovl (fact.R ());
636 math::qr<Matrix> fact (m, type);
637 retval =
ovl (fact.Q (), get_qr_r (fact));
641 retval(0) = fact.Q ().transpose ()
642 * args(1).complex_matrix_value ();
644 retval(0) = fact.Q ().transpose ()
645 * args(1).matrix_value ();
652 math::qrp<Matrix> fact (m, type);
654 retval =
ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
656 retval =
ovl (fact.Q (), get_qr_r (fact), fact.P ());
663 math::qr<ComplexMatrix>::type type
664 = qr_type<ComplexMatrix> (nargout, economy);
673 math::qr<ComplexMatrix> fact (m, type);
674 retval =
ovl (fact.R ());
680 math::qr<ComplexMatrix> fact (m, type);
681 retval =
ovl (fact.Q (), get_qr_r (fact));
683 retval(0) =
conj (fact.Q ().transpose ())
684 * args(1).complex_matrix_value ();
690 math::qrp<ComplexMatrix> fact (m, type);
692 retval =
ovl (fact.Q (), get_qr_r (fact), fact.Pvec ());
694 retval =
ovl (fact.Q (), get_qr_r (fact), fact.P ());