26#if defined (HAVE_CONFIG_H)
46#if ! defined (HAVE_QRUPDATE)
53chol2inv_internal (
const Matrix& r,
bool is_upper =
true)
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)));
101chol2inv_internal (
const FloatMatrix& r,
bool is_upper =
true)
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)));
149chol2inv_internal (
const ComplexMatrix& r,
bool is_upper =
true)
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)));
181 tmp.
xelem (i, j) = std::conj (tmp.
xelem (j, i));
185 tmp.
xelem (j, i) = std::conj (tmp.
xelem (i, j));
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)));
226 tmp.
xelem (i, j) = std::conj (tmp.
xelem (j, i));
230 tmp.
xelem (j, i) = std::conj (tmp.
xelem (i, j));
244 return chol2inv_internal (r);
252 return chol2inv_internal (m_chol_mat, m_is_upper);
260 (*current_liboctave_error_handler) (
"chol: requires square matrix");
265#if ! defined (HAVE_QRUPDATE)
276 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
278 init (m_chol_mat.hermitian () * m_chol_mat + T (u) * T (u).hermitian (),
286 static typename T::element_type zero (0);
288 if (a(i, i) == zero)
return true;
303 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
305 if (singular (m_chol_mat))
309 info = init (m_chol_mat.hermitian () * m_chol_mat
310 - T (u) * T (u).hermitian (),
true,
false);
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 (m_chol_mat))
336 else if (std::imag (u(j)) != zero)
340 T a = m_chol_mat.hermitian () * m_chol_mat;
348 a1(k, l) = math::conj (u(l));
350 a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1);
352 info = init (a1,
true,
false);
367 if (j < 0 || j > n-1)
368 (*current_liboctave_error_handler) (
"choldelete: index out of range");
370 T a = m_chol_mat.hermitian () * m_chol_mat;
373 init (a,
true,
false);
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 = m_chol_mat.hermitian () * m_chol_mat;
416 (*current_liboctave_error_handler) (
"chol: requires square matrix");
423 m_chol_mat.clear (n, n);
428 m_chol_mat.xelem (i, j) = a(i, j);
430 m_chol_mat.xelem (i, j) = 0.0;
436 m_chol_mat.xelem (i, j) = 0.0;
438 m_chol_mat.xelem (i, j) = a(i, j);
440 double *h = m_chol_mat.rwdata ();
445 anorm = octave::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 m_chol_mat.resize (info - 1, info - 1);
463 double *pz = z.rwdata ();
466 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1), n, h,
467 n, anorm, m_rcond, 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, m_rcond, 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 (m_chol_mat.rows ());
490 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
496 F77_XFCN (dch1up, DCH1UP, (n, m_chol_mat.rwdata (), n,
506 F77_INT n = to_f77_int (m_chol_mat.rows ());
509 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
515 F77_XFCN (dch1dn, DCH1DN, (n, m_chol_mat.rwdata (), n,
516 utmp.rwdata (), w, info));
527 F77_INT n = to_f77_int (m_chol_mat.rows ());
528 F77_INT j = to_f77_int (j_arg);
530 if (u.
numel () != n + 1)
531 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
533 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
539 m_chol_mat.resize (n+1, n+1);
540 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
542 F77_XFCN (dchinx, DCHINX, (n, m_chol_mat.rwdata (), ldcm,
543 j + 1, utmp.rwdata (), w, info));
552 F77_INT n = to_f77_int (m_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, m_chol_mat.rwdata (), n, j + 1, w));
562 m_chol_mat.resize (n-1, n-1);
569 F77_INT n = to_f77_int (m_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, m_chol_mat.rwdata (), n,
592 (*current_liboctave_error_handler) (
"chol: requires square matrix");
599 m_chol_mat.clear (n, n);
604 m_chol_mat.xelem (i, j) = a(i, j);
606 m_chol_mat.xelem (i, j) = 0.0f;
612 m_chol_mat.xelem (i, j) = 0.0f;
614 m_chol_mat.xelem (i, j) = a(i, j);
616 float *h = m_chol_mat.rwdata ();
621 anorm = octave::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 m_chol_mat.resize (info - 1, info - 1);
639 float *pz = z.rwdata ();
642 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1), n, h,
643 n, anorm, m_rcond, 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, m_rcond, 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 (m_chol_mat.rows ());
666 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
672 F77_XFCN (sch1up, SCH1UP, (n, m_chol_mat.rwdata (), n,
682 F77_INT n = to_f77_int (m_chol_mat.rows ());
685 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
691 F77_XFCN (sch1dn, SCH1DN, (n, m_chol_mat.rwdata (), n,
692 utmp.rwdata (), w, info));
704 F77_INT n = to_f77_int (m_chol_mat.rows ());
705 F77_INT j = to_f77_int (j_arg);
707 if (u.
numel () != n + 1)
708 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
710 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
716 m_chol_mat.resize (n+1, n+1);
717 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
719 F77_XFCN (schinx, SCHINX, (n, m_chol_mat.rwdata (), ldcm,
720 j + 1, utmp.rwdata (), w, info));
729 F77_INT n = to_f77_int (m_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, m_chol_mat.rwdata (), n,
740 m_chol_mat.resize (n-1, n-1);
747 F77_INT n = to_f77_int (m_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, m_chol_mat.rwdata (), n,
770 (*current_liboctave_error_handler) (
"chol: requires square matrix");
777 m_chol_mat.clear (n, n);
782 m_chol_mat.xelem (i, j) = a(i, j);
784 m_chol_mat.xelem (i, j) = 0.0;
790 m_chol_mat.xelem (i, j) = 0.0;
792 m_chol_mat.xelem (i, j) = a(i, j);
794 Complex *h = m_chol_mat.rwdata ();
799 anorm = octave::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 m_chol_mat.resize (info - 1, info - 1);
821 double *prz = rz.rwdata ();
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 (m_chol_mat.rows ());
843 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
862 F77_INT n = to_f77_int (m_chol_mat.rows ());
865 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
887 F77_INT n = to_f77_int (m_chol_mat.rows ());
888 F77_INT j = to_f77_int (j_arg);
890 if (u.
numel () != n + 1)
891 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
893 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
899 m_chol_mat.resize (n+1, n+1);
900 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
915 F77_INT n = to_f77_int (m_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 m_chol_mat.resize (n-1, n-1);
935 F77_INT n = to_f77_int (m_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 m_chol_mat.clear (n, n);
974 m_chol_mat.xelem (i, j) = a(i, j);
976 m_chol_mat.xelem (i, j) = 0.0f;
982 m_chol_mat.xelem (i, j) = 0.0f;
984 m_chol_mat.xelem (i, j) = a(i, j);
991 anorm = octave::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 m_chol_mat.resize (info - 1, info - 1);
1013 float *prz = rz.rwdata ();
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 (m_chol_mat.rows ());
1034 if (u.
numel () != n)
1035 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
1051 F77_INT n = to_f77_int (m_chol_mat.rows ());
1053 if (u.
numel () != n)
1054 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
1073 F77_INT j = to_f77_int (j_arg);
1075 F77_INT n = to_f77_int (m_chol_mat.rows ());
1077 if (u.
numel () != n + 1)
1078 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
1080 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
1086 m_chol_mat.resize (n+1, n+1);
1087 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
1101 F77_INT n = to_f77_int (m_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 m_chol_mat.resize (n-1, n-1);
1120 F77_INT n = to_f77_int (m_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");
1158OCTAVE_END_NAMESPACE(math)
1159OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
T & xelem(octave_idx_type n)
Size of the specified dimension.
octave_idx_type rows() const
octave_idx_type cols() const
T * rwdata()
Size of the specified dimension.
octave_idx_type numel() const
Number of elements in the array.
void shift_sym(octave_idx_type i, octave_idx_type j)
void delete_sym(octave_idx_type j)
octave_idx_type insert_sym(const VT &u, octave_idx_type j)
octave_idx_type downdate(const VT &u)
Vector representing the dimensions (size) of an Array.
OCTAVE_BEGIN_NAMESPACE(octave) static octave_value daspk_fcn
#define F77_DBLE_CMPLX_ARG(x)
#define F77_XFCN(f, F, args)
octave_f77_int_type F77_INT
template Matrix chol2inv< Matrix >(const Matrix &r)
template FloatComplexMatrix chol2inv< FloatComplexMatrix >(const FloatComplexMatrix &r)
template ComplexMatrix chol2inv< ComplexMatrix >(const ComplexMatrix &r)
template FloatMatrix chol2inv< FloatMatrix >(const FloatMatrix &r)
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
void warn_qrupdate_once()