Amesos Package Browser (Single Doxygen Collection) Development
amesos_t_cholmod_solve.c
Go to the documentation of this file.
```00001 /* ========================================================================== */
00002 /* === Cholesky/t_cholmod_solve ============================================= */
00003 /* ========================================================================== */
00004
00005 /* -----------------------------------------------------------------------------
00006  * CHOLMOD/Cholesky Module.  Copyright (C) 2005-2006, Timothy A. Davis
00008  * Lesser General Public License.  See lesser.txt for a text of the license.
00009  * CHOLMOD is also available under other licenses; contact authors for details.
00010  * http://www.cise.ufl.edu/research/sparse
00011  * -------------------------------------------------------------------------- */
00012
00013 /* Template routine for cholmod_solve.  Supports any numeric xtype (real,
00014  * complex, or zomplex).  The xtypes of all matrices (L and Y) must match.
00015  */
00016
00017 #include "amesos_cholmod_template.h"
00018
00019 /* ========================================================================== */
00020 /* === simplicial template solvers ========================================== */
00021 /* ========================================================================== */
00022
00023 /* LL': solve Lx=b with non-unit diagonal */
00024 #define LL
00025 #include "amesos_t_cholmod_lsolve.c"
00026
00027 /* LDL': solve LDx=b */
00028 #define LD
00029 #include "amesos_t_cholmod_lsolve.c"
00030
00031 /* LDL': solve Lx=b with unit diagonal */
00032 #include "amesos_t_cholmod_lsolve.c"
00033
00034 /* LL': solve L'x=b with non-unit diagonal */
00035 #define LL
00036 #include "amesos_t_cholmod_ltsolve.c"
00037
00038 /* LDL': solve DL'x=b */
00039 #define LD
00040 #include "amesos_t_cholmod_ltsolve.c"
00041
00042 /* LDL': solve L'x=b with unit diagonal */
00043 #include "amesos_t_cholmod_ltsolve.c"
00044
00045
00046 /* ========================================================================== */
00047 /* === t_ldl_dsolve ========================================================= */
00048 /* ========================================================================== */
00049
00050 /* Solve Dx=b for an LDL' factorization, where Y holds b' on input and x' on
00051  * output. */
00052
00053 static void TEMPLATE (ldl_dsolve)
00054 (
00055     cholmod_factor *L,
00056     cholmod_dense *Y    /* nr-by-n with leading dimension nr */
00057 )
00058 {
00059     double d [1] ;
00060     double *Lx, *Yx, *Yz ;
00061     Int *Lp ;
00062     Int n, nrhs, k, p, k1, k2 ;
00063
00064     ASSERT (L->xtype == Y->xtype) ; /* L and Y must have the same xtype */
00065     ASSERT (L->n == Y->ncol) ;      /* dimensions must match */
00066     ASSERT (Y->nrow == Y->d) ;      /* leading dimension of Y = # rows of Y */
00067     ASSERT (L->xtype != CHOLMOD_PATTERN) ;  /* L is not symbolic */
00068     ASSERT (!(L->is_super) && !(L->is_ll)) ;  /* L is simplicial LDL' */
00069
00070     nrhs = Y->nrow ;
00071     n = L->n ;
00072     Lp = L->p ;
00073     Lx = L->x ;
00074     Yx = Y->x ;
00075     Yz = Y->z ;
00076     for (k = 0 ; k < n ; k++)
00077     {
00078   k1 = k*nrhs ;
00079   k2 = (k+1)*nrhs ;
00080   ASSIGN_REAL (d,0, Lx,Lp[k]) ;
00081   for (p = k1 ; p < k2 ; p++)
00082   {
00083       DIV_REAL (Yx,Yz,p, Yx,Yz,p, d,0) ;
00084   }
00085     }
00086 }
00087
00088
00089 /* ========================================================================== */
00090 /* === t_simplicial_solver ================================================== */
00091 /* ========================================================================== */
00092
00093 /* Solve a linear system, where Y' contains the (array-transposed) right-hand
00094  * side on input, and the solution on output.  No permutations are applied;
00095  * these must have already been applied to Y on input. */
00096
00097 static void TEMPLATE (simplicial_solver)
00098 (
00099     int sys,        /* system to solve */
00100     cholmod_factor *L,      /* factor to use, a simplicial LL' or LDL' */
00101     cholmod_dense *Y      /* right-hand-side on input, solution on output */
00102 )
00103 {
00104     if (L->is_ll)
00105     {
00106   /* The factorization is LL' */
00107   if (sys == CHOLMOD_A || sys == CHOLMOD_LDLt)
00108   {
00109       /* Solve Ax=b or LL'x=b */
00110       TEMPLATE (ll_lsolve_k) (L, Y) ;
00111       TEMPLATE (ll_ltsolve_k) (L, Y) ;
00112   }
00113   else if (sys == CHOLMOD_L || sys == CHOLMOD_LD)
00114   {
00115       /* Solve Lx=b */
00116       TEMPLATE (ll_lsolve_k) (L, Y) ;
00117   }
00118   else if (sys == CHOLMOD_Lt || sys == CHOLMOD_DLt)
00119   {
00120       /* Solve L'x=b */
00121       TEMPLATE (ll_ltsolve_k) (L, Y) ;
00122   }
00123     }
00124     else
00125     {
00126   /* The factorization is LDL' */
00127   if (sys == CHOLMOD_A || sys == CHOLMOD_LDLt)
00128   {
00129       /* Solve Ax=b or LDL'x=b */
00130       TEMPLATE (ldl_lsolve_k) (L, Y) ;
00131       TEMPLATE (ldl_dltsolve_k) (L, Y) ;
00132   }
00133   else if (sys == CHOLMOD_LD)
00134   {
00135       /* Solve LDx=b */
00136       TEMPLATE (ldl_ldsolve_k) (L, Y) ;
00137   }
00138   else if (sys == CHOLMOD_L)
00139   {
00140       /* Solve Lx=b */
00141       TEMPLATE (ldl_lsolve_k) (L, Y) ;
00142   }
00143   else if (sys == CHOLMOD_Lt)
00144   {
00145       /* Solve L'x=b */
00146       TEMPLATE (ldl_ltsolve_k) (L, Y) ;
00147   }
00148   else if (sys == CHOLMOD_DLt)
00149   {
00150       /* Solve DL'x=b */
00151       TEMPLATE (ldl_dltsolve_k) (L, Y) ;
00152   }
00153   else if (sys == CHOLMOD_D)
00154   {
00155       /* Solve Dx=b */
00156       TEMPLATE (ldl_dsolve) (L, Y) ;
00157   }
00158     }
00159 }
00160
00161 #undef PATTERN
00162 #undef REAL
00163 #undef COMPLEX
00164 #undef ZOMPLEX
```