26#if defined (HAVE_CONFIG_H)
46template <
typename CHOLT>
53template <
typename CHOLT>
61template <
typename CHOLT>
155 int nargin = args.length ();
157 if (nargin < 1 || nargin > 3 || nargout > 3)
159 if (nargout > 2 && ! args(0).issparse ())
160 error (
"chol: using three output arguments, matrix A must be sparse");
168 std::string tmp = args(n++).xstring_value (
"chol: optional arguments must be strings");
177 error (R
"(chol: optional argument must be one of "vector", "lower", or "upper")");
189 bool natural = (nargout != 3);
190 bool force = nargout > 1;
201 retval(2) = fact.perm ();
203 retval(2) = fact.Q ();
206 if (nargout >= 2 || info == 0)
210 retval(0) = fact.L ();
212 retval(0) = fact.R ();
215 error (
"chol: input matrix must be positive definite");
221 math::sparse_chol<SparseComplexMatrix> fact (m, info, natural, force);
226 retval(2) = fact.perm ();
228 retval(2) = fact.Q ();
231 if (nargout >= 2 || info == 0)
235 retval(0) = fact.L ();
237 retval(0) = fact.R ();
240 error (
"chol: input matrix must be positive definite");
248 error (R
"(chol: A must be sparse for the "vector" option)");
255 math::chol<FloatMatrix> fact (m, info, LLt !=
true);
257 if (nargout == 2 || info == 0)
260 error (
"chol: input matrix must be positive definite");
268 math::chol<FloatComplexMatrix> fact (m, info, LLt !=
true);
270 if (nargout == 2 || info == 0)
273 error (
"chol: input matrix must be positive definite");
281 error (R
"(chol: A must be sparse for the "vector" option)");
288 math::chol<Matrix> fact (m, info, LLt !=
true);
290 if (nargout == 2 || info == 0)
293 error (
"chol: input matrix must be positive definite");
301 math::chol<ComplexMatrix> fact (m, info, LLt !=
true);
303 if (nargout == 2 || info == 0)
306 error (
"chol: input matrix must be positive definite");
360DEFUN (cholinv, args, ,
368 if (args.length () != 1)
377 if (nr == 0 || nc == 0)
392 retval =
chol.inverse ();
394 error (
"cholinv: A must be positive definite");
400 math::sparse_chol<SparseComplexMatrix>
chol (m, info);
403 retval =
chol.inverse ();
405 error (
"cholinv: A must be positive definite");
417 math::chol<FloatMatrix>
chol (m, info);
419 retval =
chol.inverse ();
421 error (
"cholinv: A must be positive definite");
428 math::chol<FloatComplexMatrix>
chol (m, info);
430 retval =
chol.inverse ();
432 error (
"cholinv: A must be positive definite");
444 math::chol<Matrix>
chol (m, info);
446 retval =
chol.inverse ();
448 error (
"cholinv: A must be positive definite");
455 math::chol<ComplexMatrix>
chol (m, info);
457 retval =
chol.inverse ();
459 error (
"cholinv: A must be positive definite");
496 if (args.length () != 1)
506 if (nr == 0 || nc == 0)
596DEFUN (cholupdate, args, nargout,
628 int nargin = args.length ();
630 if (nargin < 2 || nargin > 3)
637 || (nargin > 2 && ! args(2).is_string ()))
644 std::string op = (nargin < 3) ?
"+" : args(2).string_value ();
646 bool down = (op ==
"-");
648 if (! down && op !=
"+")
649 error (R
"(cholupdate: OP must be "+" or "-")");
652 error (
"cholupdate: dimension mismatch between R and U");
663 math::chol<FloatMatrix> fact;
667 err = fact.downdate (u);
680 math::chol<FloatComplexMatrix> fact;
684 err = fact.downdate (u);
699 math::chol<Matrix> fact;
703 err = fact.downdate (u);
715 math::chol<ComplexMatrix> fact;
719 err = fact.downdate (u);
730 error (
"cholupdate: downdate violates positiveness");
732 error (
"cholupdate: singular matrix");
799DEFUN (cholinsert, args, nargout,
826 if (args.length () != 3)
841 error (
"cholinsert: dimension mismatch between R and U");
843 if (j < 1 || j > n+1)
844 error (
"cholinsert: index J out of range");
857 math::chol<FloatMatrix> fact;
859 err = fact.insert_sym (u, j-1);
870 math::chol<FloatComplexMatrix> fact;
872 err = fact.insert_sym (u, j-1);
885 math::chol<Matrix> fact;
887 err = fact.insert_sym (u, j-1);
897 math::chol<ComplexMatrix> fact;
899 err = fact.insert_sym (u, j-1);
908 error (
"cholinsert: insertion violates positiveness");
910 error (
"cholinsert: singular matrix");
912 error (
"cholinsert: diagonal element must be real");
1054DEFUN (choldelete, args, ,
1067 if (args.length () != 2)
1083 error (
"choldelete: index J out of range");
1094 math::chol<FloatMatrix> fact;
1096 fact.delete_sym (j-1);
1105 math::chol<FloatComplexMatrix> fact;
1107 fact.delete_sym (j-1);
1119 math::chol<Matrix> fact;
1121 fact.delete_sym (j-1);
1130 math::chol<ComplexMatrix> fact;
1132 fact.delete_sym (j-1);
1179DEFUN (cholshift, args, ,
1196 if (args.length () != 3)
1214 if (j < 0 || j > n+1 || i < 0 || i > n+1)
1215 error (
"cholshift: index I or J is out of range");
1227 math::chol<FloatMatrix> fact;
1229 fact.shift_sym (i-1, j-1);
1238 math::chol<FloatComplexMatrix> fact;
1240 fact.shift_sym (i-1, j-1);
1252 math::chol<Matrix> fact;
1254 fact.shift_sym (i-1, j-1);
1263 math::chol<ComplexMatrix> fact;
1265 fact.shift_sym (i-1, j-1);
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
OCTINTERP_API FloatComplexColumnVector float_complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
octave_idx_type columns(void) const
OCTINTERP_API ColumnVector column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
double scalar_value(bool frc_str_conv=false) const
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
bool is_single_type(void) const
OCTINTERP_API ComplexColumnVector complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
bool is_real_scalar(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 FloatColumnVector float_column_vector_value(bool frc_str_conv=false, bool frc_vec_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_square_matrix_required(const char *fcn, const char *name)
void err_wrong_type_arg(const char *name, const char *s)
static octave_value get_chol_r(const CHOLT &fact)
static octave_value get_chol_l(const CHOLT &fact)
static OCTAVE_NAMESPACE_BEGIN octave_value get_chol(const CHOLT &fact)
template class OCTAVE_API sparse_chol< SparseMatrix >
OCTAVE_API bool strcmpi(const T &str_a, const T &str_b)
True if strings are the same, ignoring case.
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.