26#if defined (HAVE_CONFIG_H)
46#if ! defined (HAVE_QRUPDATE)
55 const char *str = is_upper ?
"U" :
"L";
56 F77_FUNC (dpotri, DPOTRI) (F77_CONST_CHAR_ARG2 (str, 1), n, r.
rwdata (), n,
57 info F77_CHAR_ARG_LEN (1));
63 const char *str = is_upper ?
"U" :
"L";
64 F77_FUNC (spotri, SPOTRI) (F77_CONST_CHAR_ARG2 (str, 1), n, r.
rwdata (), n,
65 info F77_CHAR_ARG_LEN (1));
71 const char *str = is_upper ?
"U" :
"L";
72 F77_FUNC (zpotri, ZPOTRI) (F77_CONST_CHAR_ARG2 (str, 1), n,
74 F77_CHAR_ARG_LEN (1));
80 const char *str = is_upper ?
"U" :
"L";
81 F77_FUNC (cpotri, CPOTRI) (F77_CONST_CHAR_ARG2 (str, 1), n,
83 F77_CHAR_ARG_LEN (1));
88chol2inv_internal (
const T& r,
bool is_upper =
true)
94 (*current_liboctave_error_handler) (
"chol2inv requires square matrix");
100 blas_potri (n, retval, info, is_upper);
110 retval.xelem (i, j) = math::conj (retval.xelem (j, i));
114 retval.xelem (j, i) = math::conj (retval.xelem (i, j));
126 return chol2inv_internal<T> (r);
134 return chol2inv_internal<T> (m_chol_mat, m_is_upper);
142 (*current_liboctave_error_handler) (
"chol: requires square matrix");
147#if ! defined (HAVE_QRUPDATE)
158 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
160 init (m_chol_mat.hermitian () * m_chol_mat + T (u) * T (u).hermitian (),
168 static typename T::element_type zero (0);
170 if (a(i, i) == zero)
return true;
185 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
187 if (singular (m_chol_mat))
191 info = init (m_chol_mat.hermitian () * m_chol_mat
192 - T (u) * T (u).hermitian (),
true,
false);
203 static typename T::element_type zero (0);
211 if (u.numel () != n + 1)
212 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
214 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
216 if (singular (m_chol_mat))
218 else if (std::imag (u(j)) != zero)
222 T a = m_chol_mat.hermitian () * m_chol_mat;
230 a1(k, l) = math::conj (u(l));
232 a1(k, l) = a(k < j ? k : k-1, l < j ? l : l-1);
234 info = init (a1,
true,
false);
249 if (j < 0 || j > n-1)
250 (*current_liboctave_error_handler) (
"choldelete: index out of range");
252 T a = m_chol_mat.hermitian () * m_chol_mat;
255 init (a,
true,
false);
266 if (i < 0 || i > n-1 || j < 0 || j > n-1)
267 (*current_liboctave_error_handler) (
"cholshift: index out of range");
269 T a = m_chol_mat.hermitian () * m_chol_mat;
298 (*current_liboctave_error_handler) (
"chol: requires square matrix");
305 m_chol_mat.clear (n, n);
310 m_chol_mat.xelem (i, j) = a(i, j);
312 m_chol_mat.xelem (i, j) = 0.0;
318 m_chol_mat.xelem (i, j) = 0.0;
320 m_chol_mat.xelem (i, j) = a(i, j);
322 double *h = m_chol_mat.rwdata ();
327 anorm = octave::xnorm (a, 1);
330 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1), n, h, n, info
331 F77_CHAR_ARG_LEN (1)));
333 F77_XFCN (dpotrf, DPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1), n, h, n, info
334 F77_CHAR_ARG_LEN (1)));
338 m_chol_mat.resize (info - 1, info - 1);
345 double *pz = z.rwdata ();
348 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1), n, h,
349 n, anorm, m_rcond, pz, iz, dpocon_info
350 F77_CHAR_ARG_LEN (1)));
352 F77_XFCN (dpocon, DPOCON, (F77_CONST_CHAR_ARG2 (
"L", 1), n, h,
353 n, anorm, m_rcond, pz, iz, dpocon_info
354 F77_CHAR_ARG_LEN (1)));
356 if (dpocon_info != 0)
363#if defined (HAVE_QRUPDATE)
369 F77_INT n = to_f77_int (m_chol_mat.rows ());
372 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
378 F77_XFCN (dch1up, DCH1UP, (n, m_chol_mat.rwdata (), n,
388 F77_INT n = to_f77_int (m_chol_mat.rows ());
391 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
397 F77_XFCN (dch1dn, DCH1DN, (n, m_chol_mat.rwdata (), n,
398 utmp.rwdata (), w, info));
409 F77_INT n = to_f77_int (m_chol_mat.rows ());
410 F77_INT j = to_f77_int (j_arg);
412 if (u.
numel () != n + 1)
413 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
415 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
421 m_chol_mat.resize (n+1, n+1);
422 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
424 F77_XFCN (dchinx, DCHINX, (n, m_chol_mat.rwdata (), ldcm,
425 j + 1, utmp.rwdata (), w, info));
434 F77_INT n = to_f77_int (m_chol_mat.rows ());
435 F77_INT j = to_f77_int (j_arg);
437 if (j < 0 || j > n-1)
438 (*current_liboctave_error_handler) (
"choldelete: index out of range");
442 F77_XFCN (dchdex, DCHDEX, (n, m_chol_mat.rwdata (), n, j + 1, w));
444 m_chol_mat.resize (n-1, n-1);
451 F77_INT n = to_f77_int (m_chol_mat.rows ());
452 F77_INT i = to_f77_int (i_arg);
453 F77_INT j = to_f77_int (j_arg);
455 if (i < 0 || i > n-1 || j < 0 || j > n-1)
456 (*current_liboctave_error_handler) (
"cholshift: index out of range");
460 F77_XFCN (dchshx, DCHSHX, (n, m_chol_mat.rwdata (), n,
474 (*current_liboctave_error_handler) (
"chol: requires square matrix");
481 m_chol_mat.clear (n, n);
486 m_chol_mat.xelem (i, j) = a(i, j);
488 m_chol_mat.xelem (i, j) = 0.0f;
494 m_chol_mat.xelem (i, j) = 0.0f;
496 m_chol_mat.xelem (i, j) = a(i, j);
498 float *h = m_chol_mat.rwdata ();
503 anorm = octave::xnorm (a, 1);
506 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1), n, h, n, info
507 F77_CHAR_ARG_LEN (1)));
509 F77_XFCN (spotrf, SPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1), n, h, n, info
510 F77_CHAR_ARG_LEN (1)));
514 m_chol_mat.resize (info - 1, info - 1);
521 float *pz = z.rwdata ();
524 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1), n, h,
525 n, anorm, m_rcond, pz, iz, spocon_info
526 F77_CHAR_ARG_LEN (1)));
528 F77_XFCN (spocon, SPOCON, (F77_CONST_CHAR_ARG2 (
"L", 1), n, h,
529 n, anorm, m_rcond, pz, iz, spocon_info
530 F77_CHAR_ARG_LEN (1)));
532 if (spocon_info != 0)
539#if defined (HAVE_QRUPDATE)
545 F77_INT n = to_f77_int (m_chol_mat.rows ());
548 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
554 F77_XFCN (sch1up, SCH1UP, (n, m_chol_mat.rwdata (), n,
564 F77_INT n = to_f77_int (m_chol_mat.rows ());
567 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
573 F77_XFCN (sch1dn, SCH1DN, (n, m_chol_mat.rwdata (), n,
574 utmp.rwdata (), w, info));
586 F77_INT n = to_f77_int (m_chol_mat.rows ());
587 F77_INT j = to_f77_int (j_arg);
589 if (u.
numel () != n + 1)
590 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
592 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
598 m_chol_mat.resize (n+1, n+1);
599 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
601 F77_XFCN (schinx, SCHINX, (n, m_chol_mat.rwdata (), ldcm,
602 j + 1, utmp.rwdata (), w, info));
611 F77_INT n = to_f77_int (m_chol_mat.rows ());
612 F77_INT j = to_f77_int (j_arg);
614 if (j < 0 || j > n-1)
615 (*current_liboctave_error_handler) (
"choldelete: index out of range");
619 F77_XFCN (schdex, SCHDEX, (n, m_chol_mat.rwdata (), n,
622 m_chol_mat.resize (n-1, n-1);
629 F77_INT n = to_f77_int (m_chol_mat.rows ());
630 F77_INT i = to_f77_int (i_arg);
631 F77_INT j = to_f77_int (j_arg);
633 if (i < 0 || i > n-1 || j < 0 || j > n-1)
634 (*current_liboctave_error_handler) (
"cholshift: index out of range");
638 F77_XFCN (schshx, SCHSHX, (n, m_chol_mat.rwdata (), n,
652 (*current_liboctave_error_handler) (
"chol: requires square matrix");
659 m_chol_mat.clear (n, n);
664 m_chol_mat.xelem (i, j) = a(i, j);
666 m_chol_mat.xelem (i, j) = 0.0;
672 m_chol_mat.xelem (i, j) = 0.0;
674 m_chol_mat.xelem (i, j) = a(i, j);
676 Complex *h = m_chol_mat.rwdata ();
681 anorm = octave::xnorm (a, 1);
684 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1), n,
686 F77_CHAR_ARG_LEN (1)));
688 F77_XFCN (zpotrf, ZPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1), n,
690 F77_CHAR_ARG_LEN (1)));
694 m_chol_mat.resize (info - 1, info - 1);
703 double *prz = rz.rwdata ();
704 F77_XFCN (zpocon, ZPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1), n,
707 F77_CHAR_ARG_LEN (1)));
709 if (zpocon_info != 0)
716#if defined (HAVE_QRUPDATE)
722 F77_INT n = to_f77_int (m_chol_mat.rows ());
725 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
744 F77_INT n = to_f77_int (m_chol_mat.rows ());
747 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
769 F77_INT n = to_f77_int (m_chol_mat.rows ());
770 F77_INT j = to_f77_int (j_arg);
772 if (u.
numel () != n + 1)
773 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
775 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
781 m_chol_mat.resize (n+1, n+1);
782 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
797 F77_INT n = to_f77_int (m_chol_mat.rows ());
798 F77_INT j = to_f77_int (j_arg);
800 if (j < 0 || j > n-1)
801 (*current_liboctave_error_handler) (
"choldelete: index out of range");
809 m_chol_mat.resize (n-1, n-1);
817 F77_INT n = to_f77_int (m_chol_mat.rows ());
818 F77_INT i = to_f77_int (i_arg);
819 F77_INT j = to_f77_int (j_arg);
821 if (i < 0 || i > n-1 || j < 0 || j > n-1)
822 (*current_liboctave_error_handler) (
"cholshift: index out of range");
844 (*current_liboctave_error_handler) (
"chol: requires square matrix");
851 m_chol_mat.clear (n, n);
856 m_chol_mat.xelem (i, j) = a(i, j);
858 m_chol_mat.xelem (i, j) = 0.0f;
864 m_chol_mat.xelem (i, j) = 0.0f;
866 m_chol_mat.xelem (i, j) = a(i, j);
873 anorm = octave::xnorm (a, 1);
876 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (
"U", 1),
878 F77_CHAR_ARG_LEN (1)));
880 F77_XFCN (cpotrf, CPOTRF, (F77_CONST_CHAR_ARG2 (
"L", 1),
882 F77_CHAR_ARG_LEN (1)));
886 m_chol_mat.resize (info - 1, info - 1);
895 float *prz = rz.rwdata ();
896 F77_XFCN (cpocon, CPOCON, (F77_CONST_CHAR_ARG2 (
"U", 1), n,
899 F77_CHAR_ARG_LEN (1)));
901 if (cpocon_info != 0)
908#if defined (HAVE_QRUPDATE)
914 F77_INT n = to_f77_int (m_chol_mat.rows ());
917 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
933 F77_INT n = to_f77_int (m_chol_mat.rows ());
936 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
955 F77_INT j = to_f77_int (j_arg);
957 F77_INT n = to_f77_int (m_chol_mat.rows ());
959 if (u.
numel () != n + 1)
960 (*current_liboctave_error_handler) (
"cholinsert: dimension mismatch");
962 (*current_liboctave_error_handler) (
"cholinsert: index out of range");
968 m_chol_mat.resize (n+1, n+1);
969 F77_INT ldcm = to_f77_int (m_chol_mat.rows ());
983 F77_INT n = to_f77_int (m_chol_mat.rows ());
984 F77_INT j = to_f77_int (j_arg);
986 if (j < 0 || j > n-1)
987 (*current_liboctave_error_handler) (
"choldelete: index out of range");
994 m_chol_mat.resize (n-1, n-1);
1002 F77_INT n = to_f77_int (m_chol_mat.rows ());
1003 F77_INT i = to_f77_int (i_arg);
1004 F77_INT j = to_f77_int (j_arg);
1006 if (i < 0 || i > n-1 || j < 0 || j > n-1)
1007 (*current_liboctave_error_handler) (
"cholshift: index out of range");
1040OCTAVE_END_NAMESPACE(math)
1041OCTAVE_END_NAMESPACE(octave)
N Dimensional Array with copy-on-write semantics.
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()
F77_RET_T F77_FUNC(xerbla, XERBLA)(F77_CONST_CHAR_ARG_DEF(s_arg