26 #if defined (HAVE_CONFIG_H)
46 template <
typename CHOLT>
53 template <
typename CHOLT>
61 template <
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");
361 DEFUN (cholinv, args, ,
369 if (args.length () != 1)
378 if (nr == 0 || nc == 0)
395 error (
"cholinv: A must be positive definite");
401 math::sparse_chol<SparseComplexMatrix>
chol (
m, info);
406 error (
"cholinv: A must be positive definite");
418 math::chol<FloatMatrix>
chol (
m, info);
422 error (
"cholinv: A must be positive definite");
429 math::chol<FloatComplexMatrix>
chol (
m, info);
433 error (
"cholinv: A must be positive definite");
445 math::chol<Matrix>
chol (
m, info);
449 error (
"cholinv: A must be positive definite");
456 math::chol<ComplexMatrix>
chol (
m, info);
460 error (
"cholinv: A must be positive definite");
497 if (args.length () != 1)
507 if (nr == 0 || nc == 0)
597 DEFUN (cholupdate, args, nargout,
629 int nargin = args.length ();
631 if (nargin < 2 || nargin > 3)
638 || (nargin > 2 && ! args(2).is_string ()))
645 std::string op = (nargin < 3) ?
"+" : args(2).string_value ();
647 bool down = (op ==
"-");
649 if (! down && op !=
"+")
650 error (R
"(cholupdate: OP must be "+" or "-")");
653 error (
"cholupdate: dimension mismatch between R and U");
664 math::chol<FloatMatrix> fact;
668 err = fact.downdate (u);
681 math::chol<FloatComplexMatrix> fact;
685 err = fact.downdate (u);
700 math::chol<Matrix> fact;
704 err = fact.downdate (u);
716 math::chol<ComplexMatrix> fact;
720 err = fact.downdate (u);
731 error (
"cholupdate: downdate violates positiveness");
733 error (
"cholupdate: singular matrix");
800 DEFUN (cholinsert, args, nargout,
827 if (args.length () != 3)
842 error (
"cholinsert: dimension mismatch between R and U");
844 if (j < 1 || j >
n+1)
845 error (
"cholinsert: index J out of range");
858 math::chol<FloatMatrix> fact;
860 err = fact.insert_sym (u, j-1);
871 math::chol<FloatComplexMatrix> fact;
873 err = fact.insert_sym (u, j-1);
886 math::chol<Matrix> fact;
888 err = fact.insert_sym (u, j-1);
898 math::chol<ComplexMatrix> fact;
900 err = fact.insert_sym (u, j-1);
909 error (
"cholinsert: insertion violates positiveness");
911 error (
"cholinsert: singular matrix");
913 error (
"cholinsert: diagonal element must be real");
1055 DEFUN (choldelete, args, ,
1068 if (args.length () != 2)
1084 error (
"choldelete: index J out of range");
1095 math::chol<FloatMatrix> fact;
1097 fact.delete_sym (j-1);
1106 math::chol<FloatComplexMatrix> fact;
1108 fact.delete_sym (j-1);
1120 math::chol<Matrix> fact;
1122 fact.delete_sym (j-1);
1131 math::chol<ComplexMatrix> fact;
1133 fact.delete_sym (j-1);
1180 DEFUN (cholshift, args, ,
1197 if (args.length () != 3)
1215 if (j < 0 || j >
n+1 || i < 0 || i >
n+1)
1216 error (
"cholshift: index I or J is out of range");
1228 math::chol<FloatMatrix> fact;
1230 fact.shift_sym (i-1, j-1);
1239 math::chol<FloatComplexMatrix> fact;
1241 fact.shift_sym (i-1, j-1);
1253 math::chol<Matrix> fact;
1255 fact.shift_sym (i-1, j-1);
1264 math::chol<ComplexMatrix> fact;
1266 fact.shift_sym (i-1, j-1);
OCTAVE_API T inverse(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
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
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_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_value get_chol(const CHOLT &fact)
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.
template class OCTAVE_API sparse_chol< SparseMatrix >