26 #if defined (HAVE_CONFIG_H)
59 template <
typename MT>
64 if (R.issquare () && fact.
regular ())
74 if (nargout == 0 || nargout == 1)
283 int nargin = args.length ();
285 if (nargin < 1 || nargin > 3)
292 bool economy =
false;
293 bool is_cmplx =
false;
302 if (args(nargin-1).is_scalar_type ())
304 int val = args(nargin-1).int_value ();
308 have_b = (nargin > 2);
310 else if (nargin == 3)
313 else if (args(nargin-1).is_string ())
315 std::string str = args(nargin-1).string_value ();
318 else if (str !=
"matrix")
319 error (
"qr: type for P must be 'matrix' or 'vector', not %s",
321 have_b = (nargin > 2);
323 else if (! args(nargin-1).is_matrix_type ())
325 else if (nargin == 3)
328 if (have_b && args(1).iscomplex ())
335 error (
"qr: Permutation output is not supported for sparse input");
343 retval =
ovl (q.
C (args(1).complex_matrix_value ()),
346 warning (
"qr: non minimum norm solution for under-determined "
347 "problem %" OCTAVE_IDX_TYPE_FORMAT
348 "x%" OCTAVE_IDX_TYPE_FORMAT,
351 else if (nargout > 1)
362 retval =
ovl (q.
C (args(1).matrix_value ()), q.
R (economy));
364 warning (
"qr: non minimum norm solution for under-determined "
365 "problem %" OCTAVE_IDX_TYPE_FORMAT
366 "x%" OCTAVE_IDX_TYPE_FORMAT,
369 else if (nargout > 1)
377 if (have_b && nargout > 2)
378 error (
"qr: too many output arguments for dense A with B");
385 = qr_type<FloatMatrix> (nargout, economy);
406 retval(0) = fact.
Q ().transpose ()
407 * args(1).float_complex_matrix_value ();
409 retval(0) = fact.
Q ().transpose ()
410 * args(1).float_matrix_value ();
419 if (economy || vector_p)
430 = qr_type<FloatComplexMatrix> (nargout, economy);
450 * args(1).float_complex_matrix_value ();
457 if (economy || vector_p)
471 = qr_type<Matrix> (nargout, economy);
492 retval(0) = fact.
Q ().transpose ()
493 * args(1).complex_matrix_value ();
495 retval(0) = fact.
Q ().transpose ()
496 * args(1).matrix_value ();
504 if (economy || vector_p)
515 = qr_type<ComplexMatrix> (nargout, economy);
535 * args(1).complex_matrix_value ();
542 if (economy || vector_p)
967 bool allow_ecf =
false)
972 return ((q.
ndims () == 2 &&
r.ndims () == 2 && k == q.
columns ())
973 && (
m == k || (allow_ecf && k ==
n && k <
m)));
983 DEFUN (qrupdate, args, ,
1005 if (args.length () != 4)
1018 error (
"qrupdate: Q and R dimensions don't match");
1147 DEFUN (qrinsert, args, ,
1177 int nargin = args.length ();
1179 if (nargin < 4 || nargin > 5)
1189 || (nargin > 4 && ! args(4).is_string ()))
1192 std::string orient = (nargin < 5) ?
"col" : args(4).string_value ();
1193 bool col = (orient ==
"col");
1195 if (! col && orient !=
"row")
1196 error (R
"(qrinsert: ORIENT must be "col" or "row")");
1199 error (
"qrinsert: dimension mismatch");
1202 error (
"qrinsert: invalid index J");
1344 DEFUN (qrdelete, args, ,
1373 int nargin = args.length ();
1375 if (nargin < 3 || nargin > 4)
1383 || (nargin > 3 && ! args(3).is_string ()))
1386 std::string orient = (nargin < 4) ?
"col" : args(3).string_value ();
1387 bool col = orient ==
"col";
1389 if (! col && orient !=
"row")
1390 error (R
"(qrdelete: ORIENT must be "col" or "row")");
1393 error (
"qrdelete: dimension mismatch");
1397 error (
"qrdelete: invalid index J");
1590 DEFUN (qrshift, args, ,
1607 if (args.length () != 4)
1619 error (
"qrshift: dimensions mismatch");
1625 error (
"qrshift: invalid index I or J");
ComplexColumnVector conj(const ComplexColumnVector &a)
void update(const CV_T &u, const CV_T &v)
void insert_row(const RV_T &u, octave_idx_type j)
void insert_col(const CV_T &u, octave_idx_type j)
void shift_cols(octave_idx_type i, octave_idx_type j)
void delete_col(octave_idx_type j)
void delete_row(octave_idx_type j)
SPARSE_T R(bool econ=false) const
SPARSE_T::dense_matrix_type C(const typename SPARSE_T::dense_matrix_type &b) const
SPARSE_T::dense_matrix_type Q(void) const
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
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 warning(const char *fmt,...)
void error(const char *fmt,...)
void err_wrong_type_arg(const char *name, const char *s)
static octave_value get_qr_r(const octave::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 octave::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::octave_value(const Array< char > &chm, char type) return retval
octave_value_list ovl(const OV_Args &... args)
Construct an octave_value_list with less typing.