26 #if defined (HAVE_CONFIG_H)
61 template <
typename MT>
63 get_qr_r (
const math::qr<MT>& fact)
66 if (R.issquare () && fact.regular ())
73 static typename math::qr<T>::type
74 qr_type (
int nargout,
bool economy)
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)
407 math::sparse_qr<SparseComplexMatrix>
409 retval =
ovl (q.C (args(1).complex_matrix_value (), economy),
412 else if (have_b && nargout == 3)
414 math::sparse_qr<SparseComplexMatrix>
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 ());
427 math::sparse_qr<SparseComplexMatrix>
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)
437 math::sparse_qr<SparseComplexMatrix>
439 retval =
ovl (q.Q (economy), q.R (economy));
443 math::sparse_qr<SparseComplexMatrix>
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)
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 ());
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), q.E ());
506 retval =
ovl (q.Q (economy), q.R (economy),
509 else if (nargout > 1)
511 math::sparse_qr<SparseMatrix>
513 retval =
ovl (q.Q (economy), q.R (economy));
517 math::sparse_qr<SparseMatrix>
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);
551 retval =
ovl (fact.Q (), get_qr_r (fact));
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);
596 retval =
ovl (fact.Q (), get_qr_r (fact));
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);
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);
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);
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);
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 ());
1270 bool allow_ecf =
false)
1275 return ((q.
ndims () == 2 &&
r.ndims () == 2 && k == q.
columns ())
1276 && (
m == k || (allow_ecf && k ==
n && k <
m)));
1281 check_index (
const octave_value& i,
bool vector_allowed =
false)
1287 DEFUN (qrupdate, args, ,
1309 if (args.length () != 4)
1321 if (! check_qr_dims (argq, argr,
true))
1322 error (
"qrupdate: Q and R dimensions don't match");
1336 math::qr<FloatMatrix> fact (
Q, R);
1339 retval =
ovl (fact.Q (), get_qr_r (fact));
1348 math::qr<Matrix> fact (
Q, R);
1351 retval =
ovl (fact.Q (), get_qr_r (fact));
1365 math::qr<FloatComplexMatrix> fact (
Q, R);
1368 retval =
ovl (fact.Q (), get_qr_r (fact));
1377 math::qr<ComplexMatrix> fact (
Q, R);
1380 retval =
ovl (fact.Q (), get_qr_r (fact));
1455 DEFUN (qrinsert, args, ,
1485 int nargin = args.length ();
1487 if (nargin < 4 || nargin > 5)
1497 || (nargin > 4 && ! args(4).is_string ()))
1500 std::string orient = (nargin < 5) ?
"col" : args(4).string_value ();
1501 bool col = (orient ==
"col");
1503 if (! col && orient !=
"row")
1504 error (R
"(qrinsert: ORIENT must be "col" or "row")");
1506 if (! check_qr_dims (argq, argr, col) || (! col && argx.
rows () != 1))
1507 error (
"qrinsert: dimension mismatch");
1509 if (! check_index (argj, col))
1510 error (
"qrinsert: invalid index J");
1528 math::qr<FloatMatrix> fact (
Q, R);
1531 fact.insert_col (
x, j-one);
1533 fact.insert_row (
x.row (0), j(0)-one);
1535 retval =
ovl (fact.Q (), get_qr_r (fact));
1543 math::qr<Matrix> fact (
Q, R);
1546 fact.insert_col (
x, j-one);
1548 fact.insert_row (
x.row (0), j(0)-one);
1550 retval =
ovl (fact.Q (), get_qr_r (fact));
1563 math::qr<FloatComplexMatrix> fact (
Q, R);
1566 fact.insert_col (
x, j-one);
1568 fact.insert_row (
x.row (0), j(0)-one);
1570 retval =
ovl (fact.Q (), get_qr_r (fact));
1578 math::qr<ComplexMatrix> fact (
Q, R);
1581 fact.insert_col (
x, j-one);
1583 fact.insert_row (
x.row (0), j(0)-one);
1585 retval =
ovl (fact.Q (), get_qr_r (fact));
1662 DEFUN (qrdelete, args, ,
1691 int nargin = args.length ();
1693 if (nargin < 3 || nargin > 4)
1701 || (nargin > 3 && ! args(3).is_string ()))
1704 std::string orient = (nargin < 4) ?
"col" : args(3).string_value ();
1705 bool col = orient ==
"col";
1707 if (! col && orient !=
"row")
1708 error (R
"(qrdelete: ORIENT must be "col" or "row")");
1710 if (! check_qr_dims (argq, argr, col))
1711 error (
"qrdelete: dimension mismatch");
1714 if (! check_index (argj, col))
1715 error (
"qrdelete: invalid index J");
1729 math::qr<FloatMatrix> fact (
Q, R);
1732 fact.delete_col (j-one);
1734 fact.delete_row (j(0)-one);
1736 retval =
ovl (fact.Q (), get_qr_r (fact));
1743 math::qr<Matrix> fact (
Q, R);
1746 fact.delete_col (j-one);
1748 fact.delete_row (j(0)-one);
1750 retval =
ovl (fact.Q (), get_qr_r (fact));
1761 math::qr<FloatComplexMatrix> fact (
Q, R);
1764 fact.delete_col (j-one);
1766 fact.delete_row (j(0)-one);
1768 retval =
ovl (fact.Q (), get_qr_r (fact));
1775 math::qr<ComplexMatrix> fact (
Q, R);
1778 fact.delete_col (j-one);
1780 fact.delete_row (j(0)-one);
1782 retval =
ovl (fact.Q (), get_qr_r (fact));
1918 DEFUN (qrshift, args, ,
1935 if (args.length () != 4)
1946 if (! check_qr_dims (argq, argr,
true))
1947 error (
"qrshift: dimensions mismatch");
1952 if (! check_index (argi) || ! check_index (argj))
1953 error (
"qrshift: invalid index I or J");
1966 math::qr<FloatMatrix> fact (
Q, R);
1967 fact.shift_cols (i-1, j-1);
1969 retval =
ovl (fact.Q (), get_qr_r (fact));
1976 math::qr<Matrix> fact (
Q, R);
1977 fact.shift_cols (i-1, j-1);
1979 retval =
ovl (fact.Q (), get_qr_r (fact));
1991 math::qr<FloatComplexMatrix> fact (
Q, R);
1992 fact.shift_cols (i-1, j-1);
1994 retval =
ovl (fact.Q (), get_qr_r (fact));
2001 math::qr<ComplexMatrix> fact (
Q, R);
2002 fact.shift_cols (i-1, j-1);
2004 retval =
ovl (fact.Q (), get_qr_r (fact));
2093 OCTAVE_END_NAMESPACE(
octave)
ComplexColumnVector conj(const ComplexColumnVector &a)
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
octave_idx_type rows() const
bool is_scalar_type() const
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
octave_idx_type idx_type_value(bool req_int=false, bool frc_str_conv=false) const
bool is_single_type() const
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
octave_idx_type columns() const
Matrix matrix_value(bool frc_str_conv=false) const
FloatComplexMatrix float_complex_matrix_value(bool frc_str_conv=false) const
SparseComplexMatrix sparse_complex_matrix_value(bool frc_str_conv=false) const
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#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)
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.