26 #if defined (HAVE_CONFIG_H)
61 template <
typename MT>
66 if (R.issquare () && fact.regular ())
73 static 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;
313 int nargin = args.length ();
315 if (nargin < 1 || nargin > 3)
322 bool economy =
false;
323 bool is_cmplx =
false;
325 bool vector_p =
false;
332 if (args(nargin-1).is_scalar_type ())
334 int val = args(nargin-1).int_value ();
338 have_b = (nargin > 2);
340 else if (nargin == 3)
343 else if (args(nargin-1).is_string ())
345 std::string str = args(nargin-1).string_value ();
348 else if (str ==
"econ")
351 have_b = (nargin > 2);
353 else if (str !=
"matrix")
354 error (
"qr: option string must be 'econ' or 'matrix' or " \
355 "'vector', not \"%s\"", str.c_str ());
356 have_b = (nargin > 2);
358 else if (! args(nargin-1).is_matrix_type ())
360 else if (nargin == 3)
363 if (have_b && args(1).iscomplex ())
370 error (
"qr: too many output arguments");
374 if (have_b && nargout == 1)
378 if (! args(1).issparse () && args(1).iscomplex ())
380 (math::sparse_qr<SparseComplexMatrix>::solve
383 args(1).complex_matrix_value (), info));
384 else if (args(1).issparse () && args(1).iscomplex ())
386 (math::sparse_qr<SparseComplexMatrix>::solve
389 args(1).sparse_complex_matrix_value (), info));
390 else if (! args(1).issparse () && ! args(1).iscomplex ())
392 (math::sparse_qr<SparseComplexMatrix>::solve
395 args(1).matrix_value (), info));
396 else if (args(1).issparse () && ! args(1).iscomplex ())
398 (math::sparse_qr<SparseComplexMatrix>::solve
401 args(1).sparse_matrix_value (), info));
403 error (
"qr: b is not valid");
405 else if (have_b && nargout == 2)
409 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
412 else if (have_b && nargout == 3)
417 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
418 q.R (economy), q.E ());
420 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
421 q.R (economy), q.E_MAT ());
430 retval =
ovl (q.Q (economy), q.R (economy), q.E ());
432 retval =
ovl (q.Q (economy), q.R (economy),
435 else if (nargout > 1)
439 retval =
ovl (q.Q (economy), q.R (economy));
445 retval =
ovl (q.R (economy));
451 if (have_b && nargout == 1)
454 if (args(1).issparse () && ! args(1).iscomplex ())
455 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
458 args (1).sparse_matrix_value (), info));
459 else if (! args(1).issparse () && args(1).iscomplex ())
460 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
463 args (1).complex_matrix_value (), info));
464 else if (! args(1).issparse () && ! args(1).iscomplex ())
465 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
468 args (1).matrix_value (), info));
469 else if (args(1).issparse () && args(1).iscomplex ())
470 retval =
ovl (math::sparse_qr<SparseMatrix>::solve
473 args(1).sparse_complex_matrix_value (),
476 error (
"qr: b is not valid");
478 else if (have_b && nargout == 2)
482 retval =
ovl (q.C (args(1).matrix_value (), economy),
485 else if (have_b && nargout == 3)
490 retval =
ovl (q.C (args(1).matrix_value (), economy),
491 q.R (economy), q.E ());
493 retval =
ovl (q.C (args(1).matrix_value (), economy),
494 q.R (economy), q.E_MAT ());
504 retval =
ovl (q.Q (economy), q.R (economy), q.E ());
506 retval =
ovl (q.Q (economy), q.R (economy),
509 else if (nargout > 1)
513 retval =
ovl (q.Q (economy), q.R (economy));
519 retval =
ovl (q.R (economy));
526 if (have_b && nargout > 2)
527 error (
"qr: too many output arguments for dense A with B");
533 math::qr<FloatMatrix>::type type
534 = qr_type<FloatMatrix> (nargout, economy);
543 math::qr<FloatMatrix> fact (
m, type);
544 retval =
ovl (fact.R ());
550 math::qr<FloatMatrix> fact (
m, type);
555 retval(0) = fact.Q ().transpose ()
556 * args(1).float_complex_matrix_value ();
558 retval(0) = fact.Q ().transpose ()
559 * args(1).float_matrix_value ();
566 math::qrp<FloatMatrix> fact (
m, type);
568 if (economy || vector_p)
569 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
571 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
578 math::qr<FloatComplexMatrix>::type type
579 = qr_type<FloatComplexMatrix> (nargout, economy);
588 math::qr<FloatComplexMatrix> fact (
m, type);
589 retval =
ovl (fact.R ());
595 math::qr<FloatComplexMatrix> fact (
m, type);
598 retval(0) =
conj (fact.Q ().transpose ())
599 * args(1).float_complex_matrix_value ();
605 math::qrp<FloatComplexMatrix> fact (
m, type);
606 if (economy || vector_p)
607 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
609 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
619 math::qr<Matrix>::type type
620 = qr_type<Matrix> (nargout, economy);
629 math::qr<Matrix> fact (
m, type);
630 retval =
ovl (fact.R ());
636 math::qr<Matrix> fact (
m, type);
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);
653 if (economy || vector_p)
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);
683 retval(0) =
conj (fact.Q ().transpose ())
684 * args(1).complex_matrix_value ();
690 math::qrp<ComplexMatrix> fact (
m, type);
691 if (economy || vector_p)
692 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.Pvec ());
694 retval =
ovl (fact.Q (),
get_qr_r (fact), fact.P ());
1274 bool allow_ecf =
false)
1279 return ((q.
ndims () == 2 &&
r.ndims () == 2 && k == q.
columns ())
1280 && (
m == k || (allow_ecf && k ==
n && k <
m)));
1290 DEFUN (qrupdate, args, ,
1312 if (args.length () != 4)
1325 error (
"qrupdate: Q and R dimensions don't match");
1339 math::qr<FloatMatrix> fact (
Q, R);
1351 math::qr<Matrix> fact (
Q, R);
1368 math::qr<FloatComplexMatrix> fact (
Q, R);
1380 math::qr<ComplexMatrix> fact (
Q, R);
1456 DEFUN (qrinsert, args, ,
1486 int nargin = args.length ();
1488 if (nargin < 4 || nargin > 5)
1498 || (nargin > 4 && ! args(4).is_string ()))
1501 std::string orient = (nargin < 5) ?
"col" : args(4).string_value ();
1502 bool col = (orient ==
"col");
1504 if (! col && orient !=
"row")
1505 error (R
"(qrinsert: ORIENT must be "col" or "row")");
1508 error (
"qrinsert: dimension mismatch");
1511 error (
"qrinsert: invalid index J");
1529 math::qr<FloatMatrix> fact (
Q, R);
1532 fact.insert_col (
x, j-one);
1534 fact.insert_row (
x.row (0), j(0)-one);
1544 math::qr<Matrix> fact (
Q, R);
1547 fact.insert_col (
x, j-one);
1549 fact.insert_row (
x.row (0), j(0)-one);
1564 math::qr<FloatComplexMatrix> fact (
Q, R);
1567 fact.insert_col (
x, j-one);
1569 fact.insert_row (
x.row (0), j(0)-one);
1579 math::qr<ComplexMatrix> fact (
Q, R);
1582 fact.insert_col (
x, j-one);
1584 fact.insert_row (
x.row (0), j(0)-one);
1657 DEFUN (qrdelete, args, ,
1686 int nargin = args.length ();
1688 if (nargin < 3 || nargin > 4)
1696 || (nargin > 3 && ! args(3).is_string ()))
1699 std::string orient = (nargin < 4) ?
"col" : args(3).string_value ();
1700 bool col = orient ==
"col";
1702 if (! col && orient !=
"row")
1703 error (R
"(qrdelete: ORIENT must be "col" or "row")");
1706 error (
"qrdelete: dimension mismatch");
1710 error (
"qrdelete: invalid index J");
1724 math::qr<FloatMatrix> fact (
Q, R);
1727 fact.delete_col (j-one);
1729 fact.delete_row (j(0)-one);
1738 math::qr<Matrix> fact (
Q, R);
1741 fact.delete_col (j-one);
1743 fact.delete_row (j(0)-one);
1756 math::qr<FloatComplexMatrix> fact (
Q, R);
1759 fact.delete_col (j-one);
1761 fact.delete_row (j(0)-one);
1770 math::qr<ComplexMatrix> fact (
Q, R);
1773 fact.delete_col (j-one);
1775 fact.delete_row (j(0)-one);
1908 DEFUN (qrshift, args, ,
1925 if (args.length () != 4)
1937 error (
"qrshift: dimensions mismatch");
1943 error (
"qrshift: invalid index I or J");
1956 math::qr<FloatMatrix> fact (
Q, R);
1957 fact.shift_cols (i-1, j-1);
1966 math::qr<Matrix> fact (
Q, R);
1967 fact.shift_cols (i-1, j-1);
1981 math::qr<FloatComplexMatrix> fact (
Q, R);
1982 fact.shift_cols (i-1, j-1);
1991 math::qr<ComplexMatrix> fact (
Q, R);
1992 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
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
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
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
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 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)
static octave_value get_qr_r(const math::qr< MT > &fact)
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.
template class OCTAVE_EXTERN_TEMPLATE_API sparse_qr< SparseMatrix >
template class OCTAVE_EXTERN_TEMPLATE_API sparse_qr< SparseComplexMatrix >