26#if defined (HAVE_CONFIG_H)
66 if (R.issquare () && fact.regular ())
73static typename math::qr<T>::type
76 if (nargout == 0 || nargout == 1)
77 return math::qr<T>::raw;
79 return math::qr<T>::economy;
81 return math::qr<T>::std;
312 int nargin = args.length ();
314 if (nargin < 1 || nargin > 3)
321 bool economy =
false;
322 bool is_cmplx =
false;
331 if (args(nargin-1).is_scalar_type ())
333 int val = args(nargin-1).int_value ();
337 have_b = (nargin > 2);
339 else if (nargin == 3)
342 else if (args(nargin-1).is_string ())
344 std::string str = args(nargin-1).string_value ();
347 else if (str !=
"matrix")
348 error (
"qr: type for P must be 'matrix' or 'vector', not %s",
350 have_b = (nargin > 2);
352 else if (! args(nargin-1).is_matrix_type ())
354 else if (nargin == 3)
357 if (have_b && args(1).iscomplex ())
364 error (
"qr: too many output arguments");
368 if (have_b && nargout == 1)
372 if (! args(1).issparse () && args(1).iscomplex ())
374 (math::sparse_qr<SparseComplexMatrix>::solve
377 args(1).complex_matrix_value (), info));
378 else if (args(1).issparse () && args(1).iscomplex ())
380 (math::sparse_qr<SparseComplexMatrix>::solve
383 args(1).sparse_complex_matrix_value (), info));
384 else if (! args(1).issparse () && ! args(1).iscomplex ())
386 (math::sparse_qr<SparseComplexMatrix>::solve
389 args(1).matrix_value (), info));
390 else if (args(1).issparse () && ! args(1).iscomplex ())
392 (math::sparse_qr<SparseComplexMatrix>::solve
395 args(1).sparse_matrix_value (), info));
397 error (
"qr: b is not valid");
399 else if (have_b && nargout == 2)
401 math::sparse_qr<SparseComplexMatrix>
403 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
406 else if (have_b && nargout == 3)
408 math::sparse_qr<SparseComplexMatrix>
411 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
412 q.R (economy), q.E ());
414 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
415 q.R (economy), q.E_MAT ());
421 math::sparse_qr<SparseComplexMatrix>
424 retval =
ovl (q.Q (economy), q.R (economy), q.E ());
426 retval =
ovl (q.Q (economy), q.R (economy),
429 else if (nargout > 1)
431 math::sparse_qr<SparseComplexMatrix>
433 retval =
ovl (q.Q (economy), q.R (economy));
437 math::sparse_qr<SparseComplexMatrix>
439 retval =
ovl (q.R (economy));
445 if (have_b && nargout == 1)
448 if (args(1).issparse () && ! args(1).iscomplex ())
449 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
452 args (1).sparse_matrix_value (), info));
453 else if (! args(1).issparse () && args(1).iscomplex ())
454 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
457 args (1).complex_matrix_value (), info));
458 else if (! args(1).issparse () && ! args(1).iscomplex ())
459 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
462 args (1).matrix_value (), info));
463 else if (args(1).issparse () && args(1).iscomplex ())
464 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
467 args(1).sparse_complex_matrix_value (),
470 error (
"qr: b is not valid");
472 else if (have_b && nargout == 2)
474 math::sparse_qr<SparseMatrix>
476 retval =
ovl (q.C (args(1).matrix_value (), economy),
479 else if (have_b && nargout == 3)
481 math::sparse_qr<SparseMatrix>
484 retval =
ovl (q.C (args(1).matrix_value (), economy),
485 q.R (economy), q.E ());
487 retval =
ovl (q.C (args(1).matrix_value (), economy),
488 q.R (economy), q.E_MAT ());
495 math::sparse_qr<SparseMatrix>
498 retval =
ovl (q.Q (economy), q.R (economy), q.E ());
500 retval =
ovl (q.Q (economy), q.R (economy),
503 else if (nargout > 1)
505 math::sparse_qr<SparseMatrix>
507 retval =
ovl (q.Q (economy), q.R (economy));
511 math::sparse_qr<SparseMatrix>
513 retval =
ovl (q.R (economy));
520 if (have_b && nargout > 2)
521 error (
"qr: too many output arguments for dense A with B");
527 math::qr<FloatMatrix>::type type
528 = qr_type<FloatMatrix> (nargout, economy);
537 math::qr<FloatMatrix> fact (m, type);
538 retval =
ovl (fact.R ());
544 math::qr<FloatMatrix> fact (m, type);
549 retval(0) = fact.Q ().transpose ()
550 * args(1).float_complex_matrix_value ();
552 retval(0) = fact.Q ().transpose ()
553 * args(1).float_matrix_value ();
560 math::qrp<FloatMatrix> fact (m, type);
562 if (economy || vector_p)
563 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
565 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
572 math::qr<FloatComplexMatrix>::type type
573 = qr_type<FloatComplexMatrix> (nargout, economy);
582 math::qr<FloatComplexMatrix> fact (m, type);
583 retval =
ovl (fact.R ());
589 math::qr<FloatComplexMatrix> fact (m, type);
592 retval(0) =
conj (fact.Q ().transpose ())
593 * args(1).float_complex_matrix_value ();
599 math::qrp<FloatComplexMatrix> fact (m, type);
600 if (economy || vector_p)
601 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
603 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
613 math::qr<Matrix>::type type
614 = qr_type<Matrix> (nargout, economy);
623 math::qr<Matrix> fact (m, type);
624 retval =
ovl (fact.R ());
630 math::qr<Matrix> fact (m, type);
635 retval(0) = fact.Q ().transpose ()
636 * args(1).complex_matrix_value ();
638 retval(0) = fact.Q ().transpose ()
639 * args(1).matrix_value ();
646 math::qrp<Matrix> fact (m, type);
647 if (economy || vector_p)
648 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
650 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
657 math::qr<ComplexMatrix>::type type
658 = qr_type<ComplexMatrix> (nargout, economy);
667 math::qr<ComplexMatrix> fact (m, type);
668 retval =
ovl (fact.R ());
674 math::qr<ComplexMatrix> fact (m, type);
677 retval(0) =
conj (fact.Q ().transpose ())
678 * args(1).complex_matrix_value ();
684 math::qrp<ComplexMatrix> fact (m, type);
685 if (economy || vector_p)
686 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
688 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
1250 bool allow_ecf =
false)
1256 && (m == k || (allow_ecf && k == n && k < m)));
1266DEFUN (qrupdate, args, ,
1288 if (args.length () != 4)
1301 error (
"qrupdate: Q and R dimensions don't match");
1315 math::qr<FloatMatrix> fact (
Q, R);
1327 math::qr<Matrix> fact (
Q, R);
1344 math::qr<FloatComplexMatrix> fact (
Q, R);
1356 math::qr<ComplexMatrix> fact (
Q, R);
1430DEFUN (qrinsert, args, ,
1460 int nargin = args.length ();
1462 if (nargin < 4 || nargin > 5)
1472 || (nargin > 4 && ! args(4).is_string ()))
1475 std::string orient = (nargin < 5) ?
"col" : args(4).string_value ();
1476 bool col = (orient ==
"col");
1478 if (! col && orient !=
"row")
1479 error (R
"(qrinsert: ORIENT must be "col" or "row")");
1482 error (
"qrinsert: dimension mismatch");
1485 error (
"qrinsert: invalid index J");
1503 math::qr<FloatMatrix> fact (
Q, R);
1506 fact.insert_col (
x, j-one);
1508 fact.insert_row (
x.row (0), j(0)-one);
1518 math::qr<Matrix> fact (
Q, R);
1521 fact.insert_col (
x, j-one);
1523 fact.insert_row (
x.row (0), j(0)-one);
1538 math::qr<FloatComplexMatrix> fact (
Q, R);
1541 fact.insert_col (
x, j-one);
1543 fact.insert_row (
x.row (0), j(0)-one);
1553 math::qr<ComplexMatrix> fact (
Q, R);
1556 fact.insert_col (
x, j-one);
1558 fact.insert_row (
x.row (0), j(0)-one);
1627DEFUN (qrdelete, args, ,
1656 int nargin = args.length ();
1658 if (nargin < 3 || nargin > 4)
1666 || (nargin > 3 && ! args(3).is_string ()))
1669 std::string orient = (nargin < 4) ?
"col" : args(3).string_value ();
1670 bool col = orient ==
"col";
1672 if (! col && orient !=
"row")
1673 error (R
"(qrdelete: ORIENT must be "col" or "row")");
1676 error (
"qrdelete: dimension mismatch");
1680 error (
"qrdelete: invalid index J");
1694 math::qr<FloatMatrix> fact (
Q, R);
1697 fact.delete_col (j-one);
1699 fact.delete_row (j(0)-one);
1708 math::qr<Matrix> fact (
Q, R);
1711 fact.delete_col (j-one);
1713 fact.delete_row (j(0)-one);
1726 math::qr<FloatComplexMatrix> fact (
Q, R);
1729 fact.delete_col (j-one);
1731 fact.delete_row (j(0)-one);
1740 math::qr<ComplexMatrix> fact (
Q, R);
1743 fact.delete_col (j-one);
1745 fact.delete_row (j(0)-one);
1873DEFUN (qrshift, args, ,
1890 if (args.length () != 4)
1902 error (
"qrshift: dimensions mismatch");
1908 error (
"qrshift: invalid index I or J");
1921 math::qr<FloatMatrix> fact (
Q, R);
1922 fact.shift_cols (i-1, j-1);
1931 math::qr<Matrix> fact (
Q, R);
1932 fact.shift_cols (i-1, j-1);
1946 math::qr<FloatComplexMatrix> fact (
Q, R);
1947 fact.shift_cols (i-1, j-1);
1956 math::qr<ComplexMatrix> fact (
Q, R);
1957 fact.shift_cols (i-1, j-1);
ComplexColumnVector conj(const ComplexColumnVector &a)
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
bool issparse(void) const
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
octave_idx_type rows(void) const
bool isnumeric(void) const
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
bool is_scalar_type(void) const
bool isinteger(void) const
octave_idx_type columns(void) const
OCTINTERP_API Array< octave_idx_type > octave_idx_type_vector_value(bool req_int=false, bool frc_str_conv=false, bool frc_vec_conv=false) const
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
bool is_single_type(void) const
Matrix matrix_value(bool frc_str_conv=false) const
FloatComplexMatrix float_complex_matrix_value(bool frc_str_conv=false) const
bool iscomplex(void) const
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
OCTINTERP_API void print_usage(void)
#define DEFUN(name, args_name, nargout_name, doc)
Macro to define a builtin function.
void error(const char *fmt,...)
void err_wrong_type_arg(const char *name, const char *s)
static OCTAVE_NAMESPACE_BEGIN octave_value get_qr_r(const math::qr< MT > &fact)
static bool check_index(const octave_value &i, bool vector_allowed=false)
static bool check_qr_dims(const octave_value &q, const octave_value &r, bool allow_ecf=false)
static math::qr< T >::type qr_type(int nargout, bool economy)
F77_RET_T const F77_INT const F77_INT const F77_INT F77_DBLE const F77_INT F77_DBLE const F77_INT F77_DBLE * Q
F77_RET_T const F77_DBLE * x
return octave_value(v1.char_array_value() . concat(v2.char_array_value(), ra_idx),((a1.is_sq_string()||a2.is_sq_string()) ? '\'' :'"'))
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.