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 (m_chol_mat.hermitian () * m_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 (m_chol_mat))
309 info = init (m_chol_mat.hermitian () * m_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 (m_chol_mat))
340 T a = m_chol_mat.hermitian () * m_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 = m_chol_mat.hermitian () * m_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 = 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.fortran_vec ();
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);
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.fortran_vec (),
n,
497 utmp.fortran_vec (),
w));
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.fortran_vec (),
n,
516 utmp.fortran_vec (),
w, info));
527 F77_INT n = to_f77_int (m_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 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.fortran_vec (), ldcm,
543 j + 1, utmp.fortran_vec (),
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.fortran_vec (),
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.fortran_vec (),
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.fortran_vec ();
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);
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.fortran_vec (),
n,
673 utmp.fortran_vec (),
w));
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.fortran_vec (),
n,
692 utmp.fortran_vec (),
w, info));
704 F77_INT n = to_f77_int (m_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 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.fortran_vec (), ldcm,
720 j + 1, utmp.fortran_vec (),
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.fortran_vec (),
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.fortran_vec (),
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.fortran_vec ();
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);
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);
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);
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);
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 ());
1035 (*current_liboctave_error_handler) (
"cholupdate: dimension mismatch");
1051 F77_INT n = to_f77_int (m_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 (m_chol_mat.rows ());
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");
ComplexColumnVector conj(const ComplexColumnVector &a)
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type numel(void) const
Number of elements in the array.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type rows(void) const
OCTARRAY_API T * fortran_vec(void)
Size of the specified dimension.
OCTARRAY_OVERRIDABLE_FUNC_API octave_idx_type cols(void) const
OCTARRAY_OVERRIDABLE_FUNC_API T & xelem(octave_idx_type n)
Size of the specified dimension.
OCTAVE_API void set(const T &R)
OCTAVE_API void delete_sym(octave_idx_type j)
OCTAVE_API void update(const VT &u)
OCTAVE_API octave_idx_type downdate(const VT &u)
OCTAVE_API T inverse(void) const
OCTAVE_API octave_idx_type insert_sym(const VT &u, octave_idx_type j)
OCTAVE_API octave_idx_type init(const T &a, bool upper, bool calc_cond)
OCTAVE_API void shift_sym(octave_idx_type i, octave_idx_type j)
Vector representing the dimensions (size) of an Array.
ColumnVector imag(const ComplexColumnVector &a)
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 OCTAVE_API FloatMatrix chol2inv< FloatMatrix >(const FloatMatrix &r)
template OCTAVE_API Matrix chol2inv< Matrix >(const Matrix &r)
static Matrix chol2inv_internal(const Matrix &r, bool is_upper=true)
template OCTAVE_API ComplexMatrix chol2inv< ComplexMatrix >(const ComplexMatrix &r)
template OCTAVE_API FloatComplexMatrix chol2inv< FloatComplexMatrix >(const FloatComplexMatrix &r)
std::complex< double > w(std::complex< double > z, double relerr=0)
std::complex< double > Complex
std::complex< float > FloatComplex
#define OCTAVE_LOCAL_BUFFER(T, buf, size)
double xnorm(const ColumnVector &x, double p)
OCTAVE_API void warn_qrupdate_once(void)