Amesos Package Browser (Single Doxygen Collection)  Development
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
amesos_t_cholmod_solve.c
Go to the documentation of this file.
1 /* ========================================================================== */
2 /* === Cholesky/t_cholmod_solve ============================================= */
3 /* ========================================================================== */
4 
5 /* -----------------------------------------------------------------------------
6  * CHOLMOD/Cholesky Module. Copyright (C) 2005-2006, Timothy A. Davis
7  * The CHOLMOD/Cholesky Module is licensed under Version 2.1 of the GNU
8  * Lesser General Public License. See lesser.txt for a text of the license.
9  * CHOLMOD is also available under other licenses; contact authors for details.
10  * http://www.cise.ufl.edu/research/sparse
11  * -------------------------------------------------------------------------- */
12 
13 /* Template routine for cholmod_solve. Supports any numeric xtype (real,
14  * complex, or zomplex). The xtypes of all matrices (L and Y) must match.
15  */
16 
18 
19 /* ========================================================================== */
20 /* === simplicial template solvers ========================================== */
21 /* ========================================================================== */
22 
23 /* LL': solve Lx=b with non-unit diagonal */
24 #define LL
26 
27 /* LDL': solve LDx=b */
28 #define LD
30 
31 /* LDL': solve Lx=b with unit diagonal */
33 
34 /* LL': solve L'x=b with non-unit diagonal */
35 #define LL
37 
38 /* LDL': solve DL'x=b */
39 #define LD
41 
42 /* LDL': solve L'x=b with unit diagonal */
44 
45 
46 /* ========================================================================== */
47 /* === t_ldl_dsolve ========================================================= */
48 /* ========================================================================== */
49 
50 /* Solve Dx=b for an LDL' factorization, where Y holds b' on input and x' on
51  * output. */
52 
53 static void TEMPLATE (ldl_dsolve)
54 (
55  cholmod_factor *L,
56  cholmod_dense *Y /* nr-by-n with leading dimension nr */
57 )
58 {
59  double d [1] ;
60  double *Lx, *Yx, *Yz ;
61  Int *Lp ;
62  Int n, nrhs, k, p, k1, k2 ;
63 
64  ASSERT (L->xtype == Y->xtype) ; /* L and Y must have the same xtype */
65  ASSERT (L->n == Y->ncol) ; /* dimensions must match */
66  ASSERT (Y->nrow == Y->d) ; /* leading dimension of Y = # rows of Y */
67  ASSERT (L->xtype != CHOLMOD_PATTERN) ; /* L is not symbolic */
68  ASSERT (!(L->is_super) && !(L->is_ll)) ; /* L is simplicial LDL' */
69 
70  nrhs = Y->nrow ;
71  n = L->n ;
72  Lp = L->p ;
73  Lx = L->x ;
74  Yx = Y->x ;
75  Yz = Y->z ;
76  for (k = 0 ; k < n ; k++)
77  {
78  k1 = k*nrhs ;
79  k2 = (k+1)*nrhs ;
80  ASSIGN_REAL (d,0, Lx,Lp[k]) ;
81  for (p = k1 ; p < k2 ; p++)
82  {
83  DIV_REAL (Yx,Yz,p, Yx,Yz,p, d,0) ;
84  }
85  }
86 }
87 
88 
89 /* ========================================================================== */
90 /* === t_simplicial_solver ================================================== */
91 /* ========================================================================== */
92 
93 /* Solve a linear system, where Y' contains the (array-transposed) right-hand
94  * side on input, and the solution on output. No permutations are applied;
95  * these must have already been applied to Y on input. */
96 
97 static void TEMPLATE (simplicial_solver)
98 (
99  int sys, /* system to solve */
100  cholmod_factor *L, /* factor to use, a simplicial LL' or LDL' */
101  cholmod_dense *Y /* right-hand-side on input, solution on output */
102 )
103 {
104  if (L->is_ll)
105  {
106  /* The factorization is LL' */
107  if (sys == CHOLMOD_A || sys == CHOLMOD_LDLt)
108  {
109  /* Solve Ax=b or LL'x=b */
110  TEMPLATE (ll_lsolve_k) (L, Y) ;
111  TEMPLATE (ll_ltsolve_k) (L, Y) ;
112  }
113  else if (sys == CHOLMOD_L || sys == CHOLMOD_LD)
114  {
115  /* Solve Lx=b */
116  TEMPLATE (ll_lsolve_k) (L, Y) ;
117  }
118  else if (sys == CHOLMOD_Lt || sys == CHOLMOD_DLt)
119  {
120  /* Solve L'x=b */
121  TEMPLATE (ll_ltsolve_k) (L, Y) ;
122  }
123  }
124  else
125  {
126  /* The factorization is LDL' */
127  if (sys == CHOLMOD_A || sys == CHOLMOD_LDLt)
128  {
129  /* Solve Ax=b or LDL'x=b */
130  TEMPLATE (ldl_lsolve_k) (L, Y) ;
131  TEMPLATE (ldl_dltsolve_k) (L, Y) ;
132  }
133  else if (sys == CHOLMOD_LD)
134  {
135  /* Solve LDx=b */
136  TEMPLATE (ldl_ldsolve_k) (L, Y) ;
137  }
138  else if (sys == CHOLMOD_L)
139  {
140  /* Solve Lx=b */
141  TEMPLATE (ldl_lsolve_k) (L, Y) ;
142  }
143  else if (sys == CHOLMOD_Lt)
144  {
145  /* Solve L'x=b */
146  TEMPLATE (ldl_ltsolve_k) (L, Y) ;
147  }
148  else if (sys == CHOLMOD_DLt)
149  {
150  /* Solve DL'x=b */
151  TEMPLATE (ldl_dltsolve_k) (L, Y) ;
152  }
153  else if (sys == CHOLMOD_D)
154  {
155  /* Solve Dx=b */
156  TEMPLATE (ldl_dsolve) (L, Y) ;
157  }
158  }
159 }
160 
161 #undef PATTERN
162 #undef REAL
163 #undef COMPLEX
164 #undef ZOMPLEX
#define CHOLMOD_A
#define Int
#define CHOLMOD_PATTERN
#define CHOLMOD_D
#define ASSERT(expression)
#define CHOLMOD_L
#define CHOLMOD_LD
#define CHOLMOD_LDLt
#define CHOLMOD_DLt
#define CHOLMOD_Lt
static void TEMPLATE() ldl_dsolve(cholmod_factor *L, cholmod_dense *Y)
int n
static void TEMPLATE() simplicial_solver(int sys, cholmod_factor *L, cholmod_dense *Y)