26 #if defined (HAVE_CONFIG_H)
46 template <
typename CHOLT>
48 get_chol (
const CHOLT& fact)
53 template <
typename CHOLT>
55 get_chol_r (
const CHOLT& fact)
61 template <
typename CHOLT>
63 get_chol_l (
const CHOLT& fact)
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;
196 math::sparse_chol<SparseMatrix> fact (
m, info, natural, force);
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)
258 retval =
ovl (get_chol (fact), info);
260 error (
"chol: input matrix must be positive definite");
268 math::chol<FloatComplexMatrix> fact (
m, info, LLt !=
true);
270 if (nargout == 2 || info == 0)
271 retval =
ovl (get_chol (fact), info);
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)
291 retval =
ovl (get_chol (fact), info);
293 error (
"chol: input matrix must be positive definite");
301 math::chol<ComplexMatrix> fact (
m, info, LLt !=
true);
303 if (nargout == 2 || info == 0)
304 retval =
ovl (get_chol (fact), info);
306 error (
"chol: input matrix must be positive definite");
361 DEFUN (cholinv, args, ,
369 if (args.length () != 1)
378 if (nr == 0 || nc == 0)
390 math::sparse_chol<SparseMatrix>
chol (
m, info);
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);
672 retval =
ovl (get_chol_r (fact));
681 math::chol<FloatComplexMatrix> fact;
685 err = fact.downdate (u);
689 retval =
ovl (get_chol_r (fact));
700 math::chol<Matrix> fact;
704 err = fact.downdate (u);
708 retval =
ovl (get_chol_r (fact));
716 math::chol<ComplexMatrix> fact;
720 err = fact.downdate (u);
724 retval =
ovl (get_chol_r (fact));
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);
862 retval =
ovl (get_chol_r (fact));
871 math::chol<FloatComplexMatrix> fact;
873 err = fact.insert_sym (u, j-1);
875 retval =
ovl (get_chol_r (fact));
886 math::chol<Matrix> fact;
888 err = fact.insert_sym (u, j-1);
890 retval =
ovl (get_chol_r (fact));
898 math::chol<ComplexMatrix> fact;
900 err = fact.insert_sym (u, j-1);
902 retval =
ovl (get_chol_r (fact));
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);
1099 retval =
ovl (get_chol_r (fact));
1106 math::chol<FloatComplexMatrix> fact;
1108 fact.delete_sym (j-1);
1110 retval =
ovl (get_chol_r (fact));
1120 math::chol<Matrix> fact;
1122 fact.delete_sym (j-1);
1124 retval =
ovl (get_chol_r (fact));
1131 math::chol<ComplexMatrix> fact;
1133 fact.delete_sym (j-1);
1135 retval =
ovl (get_chol_r (fact));
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);
1232 retval =
ovl (get_chol_r (fact));
1239 math::chol<FloatComplexMatrix> fact;
1241 fact.shift_sym (i-1, j-1);
1243 retval =
ovl (get_chol_r (fact));
1253 math::chol<Matrix> fact;
1255 fact.shift_sym (i-1, j-1);
1257 retval =
ovl (get_chol_r (fact));
1264 math::chol<ComplexMatrix> fact;
1266 fact.shift_sym (i-1, j-1);
1268 retval =
ovl (get_chol_r (fact));
1337 OCTAVE_END_NAMESPACE(
octave)
SparseMatrix sparse_matrix_value(bool frc_str_conv=false) const
bool is_real_scalar() const
octave_idx_type rows() const
ComplexMatrix complex_matrix_value(bool frc_str_conv=false) const
bool is_single_type() const
FloatColumnVector float_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
double scalar_value(bool frc_str_conv=false) const
FloatComplexColumnVector float_complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
FloatMatrix float_matrix_value(bool frc_str_conv=false) const
ComplexColumnVector complex_column_vector_value(bool frc_str_conv=false, bool frc_vec_conv=false) const
ColumnVector column_vector_value(bool frc_str_conv=false, bool frc_vec_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_square_matrix_required(const char *fcn, const char *name)
void err_wrong_type_arg(const char *name, const char *s)
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.