bridge/class-master/depend/pari/src/basemath/alglin2.c
/* Cholesky decomposition for positive definite matrix a
 * [GTM138, Algo 2.7.6, matrix Q]
 * If a is not positive definite return NULL. */
Cholesky decomposition for positive definite matrix a
[GTM138, Algo 2.7.6, matrix Q]
If a is not positive definite return NULL.
Cholesky decomposition for positive definite matrix a [ GTM138 Algo 2 . 7 . 6 matrix Q ] If a is not positive definite return NULL .
GEN
qfgaussred_positive(GEN a)
{
  pari_sp av = avma;
  GEN b;
  long i,j,k, n = lg(a);
  if (typ(a)!=t_MAT) pari_err_TYPE("qfgaussred_positive",a);
  if (n == 1) return cgetg(1, t_MAT);
  if (lgcols(a)!=n) pari_err_DIM("qfgaussred_positive");
  b = cgetg(n,t_MAT);
  for (j=1; j<n; j++)
  {
    GEN p1=cgetg(n,t_COL), p2=gel(a,j);
    gel(b,j) = p1;
    for (i=1; i<=j; i++) gel(p1,i) = gel(p2,i);
    for (   ; i<n ; i++) gel(p1,i) = gen_0;
  }
  for (k=1; k<n; k++)
  {
    GEN bk, p = gcoeff(b,k,k), invp;
    if (gsigne(p)<=0) { avma = av; return NULL; } 
    invp = ginv(p);
    bk = row(b, k);
    for (i=k+1; i<n; i++) gcoeff(b,k,i) = gmul(gel(bk,i), invp);
    for (i=k+1; i<n; i++)
    {
      GEN c = gel(bk, i);
      for (j=i; j<n; j++)
        gcoeff(b,i,j) = gsub(gcoeff(b,i,j), gmul(c,gcoeff(b,k,j)));
    }
    if (gc_needed(av,1))
    {
      if (DEBUGMEM>1) pari_warn(warnmem,"qfgaussred_positive");
      b=gerepilecopy(av,b);
    }
  }
  return gerepilecopy(av,b);
}
GEN qfgaussred_positive ( GEN a ) { pari_sp av = avma ; GEN b ; long i , j , k , n = lg ( a ) ; if ( typ ( a ) != t_MAT ) pari_err_TYPE ( " " , a ) ; if ( n == 1 ) return cgetg ( 1 , t_MAT ) ; if ( lgcols ( a ) != n ) pari_err_DIM ( " " ) ; b = cgetg ( n , t_MAT ) ; for ( j = 1 ; j < n ; j ++ ) { GEN p1 = cgetg ( n , t_COL ) , p2 = gel ( a , j ) ; gel ( b , j ) = p1 ; for ( i = 1 ; i <= j ; i ++ ) gel ( p1 , i ) = gel ( p2 , i ) ; for ( ; i < n ; i ++ ) gel ( p1 , i ) = gen_0 ; } for ( k = 1 ; k < n ; k ++ ) { GEN bk , p = gcoeff ( b , k , k ) , invp ; if ( gsigne ( p ) <= 0 ) { avma = av ; return NULL ; } invp = ginv ( p ) ; bk = row ( b , k ) ; for ( i = k + 1 ; i < n ; i ++ ) gcoeff ( b , k , i ) = gmul ( gel ( bk , i ) , invp ) ; for ( i = k + 1 ; i < n ; i ++ ) { GEN c = gel ( bk , i ) ; for ( j = i ; j < n ; j ++ ) gcoeff ( b , i , j ) = gsub ( gcoeff ( b , i , j ) , gmul ( c , gcoeff ( b , k , j ) ) ) ; } if ( gc_needed ( av , 1 ) ) { if ( DEBUGMEM > 1 ) pari_warn ( warnmem , " " ) ; b = gerepilecopy ( av , b ) ; } } return gerepilecopy ( av , b ) ; }
Cholesky decomposition for positive definite matrix a
 [GTM138, Algo 2.7.6, matrix Q]
 If a is not positive definite return NULL.
Cholesky decomposition for positive definite matrix a [ GTM138 Algo 2 . 7 . 6 matrix Q ] If a is not positive definite return NULL .
/* not positive definite */