26 #if defined (HAVE_CONFIG_H)
46 #if ! defined (HAVE_QRUPDATE)
61 (*current_liboctave_error_handler) (
"chol2inv requires square matrix");
70 F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
72 F77_CHAR_ARG_LEN (1)));
74 F77_XFCN (dpotri, DPOTRI, (F77_CONST_CHAR_ARG2 (
"L", 1),
n,
76 F77_CHAR_ARG_LEN (1)));
109 (*current_liboctave_error_handler) (
"chol2inv requires square matrix");
118 F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
120 F77_CHAR_ARG_LEN (1)));
122 F77_XFCN (spotri, SPOTRI, (F77_CONST_CHAR_ARG2 (
"L", 1),
n,
124 F77_CHAR_ARG_LEN (1)));
157 (*current_liboctave_error_handler) (
"chol2inv requires square matrix");
165 F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
167 F77_CHAR_ARG_LEN (1)));
169 F77_XFCN (zpotri, ZPOTRI, (F77_CONST_CHAR_ARG2 (
"L", 1),
n,
171 F77_CHAR_ARG_LEN (1)));
202 (*current_liboctave_error_handler) (
"chol2inv requires square matrix");
210 F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
212 F77_CHAR_ARG_LEN (1)));
214 F77_XFCN (cpotri, CPOTRI, (F77_CONST_CHAR_ARG2 (
"L", 1),
n,
216 F77_CHAR_ARG_LEN (1)));
240 template <
typename T>
248 template <
typename T>
255 template <
typename T>
260 (*current_liboctave_error_handler) (
"chol: requires square matrix");
265 #if ! defined (HAVE_QRUPDATE)
267 template <
typename T>
276 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
278 init (chol_mat.hermitian () * chol_mat + T (u) * T (u).hermitian (),
282 template <
typename T>
284 singular (
const T& a)
286 static typename T::element_type zero (0);
288 if (a(i,i) == zero)
return true;
292 template <
typename T>
303 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
305 if (singular (chol_mat))
309 info = init (chol_mat.hermitian () * chol_mat
310 - T (u) * T (u).hermitian (),
true,
false);
317 template <
typename T>
321 static typename T::element_type zero (0);
329 if (u.numel () !=
n + 1)
330 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
332 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
334 if (singular (chol_mat))
340 T a = chol_mat.hermitian () * chol_mat;
350 a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1);
352 info = init (a1,
true,
false);
359 template <
typename T>
367 if (j < 0 || j >
n-1)
368 (*current_liboctave_error_handler) (
"choldelete: index out of range");
370 T a = chol_mat.hermitian () * chol_mat;
373 init (a,
true,
false);
376 template <
typename T>
384 if (i < 0 || i >
n-1 || j < 0 || j >
n-1)
385 (*current_liboctave_error_handler) (
"cholshift: index out of range");
387 T a = chol_mat.hermitian () * chol_mat;
416 (*current_liboctave_error_handler) (
"chol: requires square matrix");
423 chol_mat.clear (
n,
n);
428 chol_mat.xelem (i, j) = a(i, j);
430 chol_mat.xelem (i, j) = 0.0;
436 chol_mat.xelem (i, j) = 0.0;
438 chol_mat.xelem (i, j) = a(i, j);
440 double *h = chol_mat.fortran_vec ();
445 anorm =
xnorm (a, 1);
448 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1),
n, h,
n, info
449 F77_CHAR_ARG_LEN (1)));
451 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
n, h,
n, info
452 F77_CHAR_ARG_LEN (1)));
456 chol_mat.resize (info - 1, info - 1);
466 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1),
n, h,
467 n, anorm, xrcond, pz, iz, dpocon_info
468 F77_CHAR_ARG_LEN (1)));
470 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (
"L", 1),
n, h,
471 n, anorm, xrcond, pz, iz, dpocon_info
472 F77_CHAR_ARG_LEN (1)));
474 if (dpocon_info != 0)
481 #if defined (HAVE_QRUPDATE)
487 F77_INT n = to_f77_int (chol_mat.rows ());
490 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
496 F77_XFCN (dch1up, DCH1UP, (
n, chol_mat.fortran_vec (),
n,
497 utmp.fortran_vec (),
w));
506 F77_INT n = to_f77_int (chol_mat.rows ());
509 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
515 F77_XFCN (dch1dn, DCH1DN, (
n, chol_mat.fortran_vec (),
n,
516 utmp.fortran_vec (),
w, info));
527 F77_INT n = to_f77_int (chol_mat.rows ());
528 F77_INT j = to_f77_int (j_arg);
531 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
533 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
539 chol_mat.resize (
n+1,
n+1);
540 F77_INT ldcm = to_f77_int (chol_mat.rows ());
542 F77_XFCN (dchinx, DCHINX, (
n, chol_mat.fortran_vec (), ldcm,
543 j + 1, utmp.fortran_vec (),
w, info));
552 F77_INT n = to_f77_int (chol_mat.rows ());
553 F77_INT j = to_f77_int (j_arg);
555 if (j < 0 || j >
n-1)
556 (*current_liboctave_error_handler) (
"choldelete: index out of range");
560 F77_XFCN (dchdex, DCHDEX, (
n, chol_mat.fortran_vec (),
n, j + 1,
w));
562 chol_mat.resize (
n-1,
n-1);
569 F77_INT n = to_f77_int (chol_mat.rows ());
570 F77_INT i = to_f77_int (i_arg);
571 F77_INT j = to_f77_int (j_arg);
573 if (i < 0 || i >
n-1 || j < 0 || j >
n-1)
574 (*current_liboctave_error_handler) (
"cholshift: index out of range");
578 F77_XFCN (dchshx, DCHSHX, (
n, chol_mat.fortran_vec (),
n,
592 (*current_liboctave_error_handler) (
"chol: requires square matrix");
599 chol_mat.clear (
n,
n);
604 chol_mat.xelem (i, j) = a(i, j);
606 chol_mat.xelem (i, j) = 0.0f;
612 chol_mat.xelem (i, j) = 0.0f;
614 chol_mat.xelem (i, j) = a(i, j);
616 float *h = chol_mat.fortran_vec ();
621 anorm =
xnorm (a, 1);
624 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1),
n, h,
n, info
625 F77_CHAR_ARG_LEN (1)));
627 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
n, h,
n, info
628 F77_CHAR_ARG_LEN (1)));
632 chol_mat.resize (info - 1, info - 1);
642 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1),
n, h,
643 n, anorm, xrcond, pz, iz, spocon_info
644 F77_CHAR_ARG_LEN (1)));
646 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (
"L", 1),
n, h,
647 n, anorm, xrcond, pz, iz, spocon_info
648 F77_CHAR_ARG_LEN (1)));
650 if (spocon_info != 0)
657 #if defined (HAVE_QRUPDATE)
663 F77_INT n = to_f77_int (chol_mat.rows ());
666 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
672 F77_XFCN (sch1up, SCH1UP, (
n, chol_mat.fortran_vec (),
n,
673 utmp.fortran_vec (),
w));
682 F77_INT n = to_f77_int (chol_mat.rows ());
685 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
691 F77_XFCN (sch1dn, SCH1DN, (
n, chol_mat.fortran_vec (),
n,
692 utmp.fortran_vec (),
w, info));
704 F77_INT n = to_f77_int (chol_mat.rows ());
705 F77_INT j = to_f77_int (j_arg);
708 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
710 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
716 chol_mat.resize (
n+1,
n+1);
717 F77_INT ldcm = to_f77_int (chol_mat.rows ());
719 F77_XFCN (schinx, SCHINX, (
n, chol_mat.fortran_vec (), ldcm,
720 j + 1, utmp.fortran_vec (),
w, info));
729 F77_INT n = to_f77_int (chol_mat.rows ());
730 F77_INT j = to_f77_int (j_arg);
732 if (j < 0 || j >
n-1)
733 (*current_liboctave_error_handler) (
"choldelete: index out of range");
737 F77_XFCN (schdex, SCHDEX, (
n, chol_mat.fortran_vec (),
n,
740 chol_mat.resize (
n-1,
n-1);
747 F77_INT n = to_f77_int (chol_mat.rows ());
748 F77_INT i = to_f77_int (i_arg);
749 F77_INT j = to_f77_int (j_arg);
751 if (i < 0 || i >
n-1 || j < 0 || j >
n-1)
752 (*current_liboctave_error_handler) (
"cholshift: index out of range");
756 F77_XFCN (schshx, SCHSHX, (
n, chol_mat.fortran_vec (),
n,
770 (*current_liboctave_error_handler) (
"chol: requires square matrix");
777 chol_mat.clear (
n,
n);
782 chol_mat.xelem (i, j) = a(i, j);
784 chol_mat.xelem (i, j) = 0.0;
790 chol_mat.xelem (i, j) = 0.0;
792 chol_mat.xelem (i, j) = a(i, j);
794 Complex *h = chol_mat.fortran_vec ();
799 anorm =
xnorm (a, 1);
802 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
804 F77_CHAR_ARG_LEN (1)));
806 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
n,
808 F77_CHAR_ARG_LEN (1)));
812 chol_mat.resize (info - 1, info - 1);
822 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
825 F77_CHAR_ARG_LEN (1)));
827 if (zpocon_info != 0)
834 #if defined (HAVE_QRUPDATE)
840 F77_INT n = to_f77_int (chol_mat.rows ());
843 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
862 F77_INT n = to_f77_int (chol_mat.rows ());
865 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
887 F77_INT n = to_f77_int (chol_mat.rows ());
888 F77_INT j = to_f77_int (j_arg);
891 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
893 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
899 chol_mat.resize (
n+1,
n+1);
900 F77_INT ldcm = to_f77_int (chol_mat.rows ());
915 F77_INT n = to_f77_int (chol_mat.rows ());
916 F77_INT j = to_f77_int (j_arg);
918 if (j < 0 || j >
n-1)
919 (*current_liboctave_error_handler) (
"choldelete: index out of range");
927 chol_mat.resize (
n-1,
n-1);
935 F77_INT n = to_f77_int (chol_mat.rows ());
936 F77_INT i = to_f77_int (i_arg);
937 F77_INT j = to_f77_int (j_arg);
939 if (i < 0 || i >
n-1 || j < 0 || j >
n-1)
940 (*current_liboctave_error_handler) (
"cholshift: index out of range");
962 (*current_liboctave_error_handler) (
"chol: requires square matrix");
969 chol_mat.clear (
n,
n);
974 chol_mat.xelem (i, j) = a(i, j);
976 chol_mat.xelem (i, j) = 0.0f;
982 chol_mat.xelem (i, j) = 0.0f;
984 chol_mat.xelem (i, j) = a(i, j);
991 anorm =
xnorm (a, 1);
994 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1),
996 F77_CHAR_ARG_LEN (1)));
998 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
1000 F77_CHAR_ARG_LEN (1)));
1004 chol_mat.resize (info - 1, info - 1);
1014 F77_XFCN (cpocon, CPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1),
n,
1017 F77_CHAR_ARG_LEN (1)));
1019 if (cpocon_info != 0)
1026 #if defined (HAVE_QRUPDATE)
1032 F77_INT n = to_f77_int (chol_mat.rows ());
1035 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
1051 F77_INT n = to_f77_int (chol_mat.rows ());
1054 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
1073 F77_INT j = to_f77_int (j_arg);
1075 F77_INT n = to_f77_int (chol_mat.rows ());
1078 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
1080 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
1086 chol_mat.resize (
n+1,
n+1);
1087 F77_INT ldcm = to_f77_int (chol_mat.rows ());
1101 F77_INT n = to_f77_int (chol_mat.rows ());
1102 F77_INT j = to_f77_int (j_arg);
1104 if (j < 0 || j >
n-1)
1105 (*current_liboctave_error_handler) (
"choldelete: index out of range");
1112 chol_mat.resize (
n-1,
n-1);
1120 F77_INT n = to_f77_int (chol_mat.rows ());
1121 F77_INT i = to_f77_int (i_arg);
1122 F77_INT j = to_f77_int (j_arg);
1124 if (i < 0 || i >
n-1 || j < 0 || j >
n-1)
1125 (*current_liboctave_error_handler) (
"cholshift: index out of range");
ComplexColumnVector conj(const ComplexColumnVector &a)
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type numel(void) const
Number of elements in the array.
octave_idx_type cols(void) const
octave_idx_type rows(void) const
const T * fortran_vec(void) const
Size of the specified dimension.
Vector representing the dimensions (size) of an Array.
octave_idx_type insert_sym(const VT &u, octave_idx_type j)
octave_idx_type downdate(const VT &u)
octave_idx_type init(const T &a, bool upper, bool calc_cond)
void shift_sym(octave_idx_type i, octave_idx_type j)
void delete_sym(octave_idx_type j)
ColumnVector imag(const ComplexColumnVector &a)
#define F77_DBLE_CMPLX_ARG(x)
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_INT
std::complex< double > w(std::complex< double > z, double relerr=0)
template FloatMatrix chol2inv< FloatMatrix >(const FloatMatrix &r)
template ComplexMatrix chol2inv< ComplexMatrix >(const ComplexMatrix &r)
void warn_qrupdate_once(void)
template FloatComplexMatrix chol2inv< FloatComplexMatrix >(const FloatComplexMatrix &r)
template Matrix chol2inv< Matrix >(const Matrix &r)
static Matrix chol2inv_internal(const Matrix &r, bool is_upper=true)
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
OCTAVE_API double xnorm(const ColumnVector &x, double p)
octave_value::octave_value(const Array< char > &chm, char type) return retval