1 /* ========================================================================== */ 2 /* === KLU/Include/klu_internal.h =========================================== */ 3 /* ========================================================================== */ 4 5 /* For internal use in KLU routines only, not for user programs */ 6 7 #ifndef _KLU_INTERNAL_H 8 #define _KLU_INTERNAL_H 9 10 #include "klu.h" 11 #include "btf.h" 12 #include "klu_version.h" 13 14 /* ========================================================================== */ 15 /* make sure debugging and printing is turned off */ 16 17 #ifndef NDEBUG 18 #define NDEBUG 19 #endif 20 #ifndef NPRINT 21 #define NPRINT 22 #endif 23 24 /* To enable debugging and assertions, uncomment this line: 25 #undef NDEBUG 26 */ 27 28 /* To enable diagnostic printing, uncomment this line: 29 #undef NPRINT 30 */ 31 32 /* ========================================================================== */ 33 34 #include <stdio.h> 35 #include <assert.h> 36 #include <limits.h> 37 #include <stdlib.h> 38 #include <math.h> 39 40 #undef ASSERT 41 #ifndef NDEBUG 42 #define ASSERT(a) assert(a) 43 #else 44 #define ASSERT(a) 45 #endif 46 47 #define SCALAR_IS_NAN(x) ((x) != (x)) 48 49 /* true if an integer (stored in double x) would overflow (or if x is NaN) */ 50 #define INT_OVERFLOW(x) ((!((x) * (1.0+1e-8) <= (double) Int_MAX)) \ 51 || SCALAR_IS_NAN (x)) 52 53 #undef TRUE 54 #undef FALSE 55 #undef MAX 56 #undef MIN 57 #undef PRINTF 58 #undef FLIP 59 60 #ifndef NPRINT 61 #define PRINTF(s) SUITESPARSE_PRINTF (s) 62 #else 63 #define PRINTF(s) 64 #endif 65 66 #define TRUE 1 67 #define FALSE 0 68 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 69 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 70 71 /* FLIP is a "negation about -1", and is used to mark an integer i that is 72 * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY 73 * is negative, and FLIP of a number < EMTPY is positive. FLIP (FLIP (i)) = i 74 * for all integers i. UNFLIP (i) is >= EMPTY. */ 75 #define EMPTY (-1) 76 #define FLIP(i) (-(i)-2) 77 #define UNFLIP(i) (((i) < EMPTY) ? FLIP (i) : (i)) 78 79 80 size_t KLU_kernel /* final size of LU on output */ 81 ( 82 /* input, not modified */ 83 Int n, /* A is n-by-n */ 84 Int Ap [ ], /* size n+1, column pointers for A */ 85 Int Ai [ ], /* size nz = Ap [n], row indices for A */ 86 Entry Ax [ ], /* size nz, values of A */ 87 Int Q [ ], /* size n, optional input permutation */ 88 size_t lusize, /* initial size of LU */ 89 90 /* output, not defined on input */ 91 Int Pinv [ ], /* size n */ 92 Int P [ ], /* size n */ 93 Unit **p_LU, /* size lusize on input, size Uxp[n] on output*/ 94 Entry Udiag [ ], /* size n, diagonal of U */ 95 Int Llen [ ], /* size n, column length of L */ 96 Int Ulen [ ], /* size n, column length of U */ 97 Int Lip [ ], /* size n+1 */ 98 Int Uip [ ], /* size n+1 */ 99 Int *lnz, /* size of L */ 100 Int *unz, /* size of U */ 101 102 /* workspace, not defined on input */ 103 Entry X [ ], /* size n, zero on output */ 104 105 /* workspace, not defined on input or output */ 106 Int Stack [ ], /* size n */ 107 Int Flag [ ], /* size n */ 108 Int adj_pos [ ], /* size n */ 109 110 /* workspace for pruning only */ 111 Int Lpend [ ], /* size n workspace */ 112 113 /* inputs, not modified on output */ 114 Int k1, /* the block of A is from k1 to k2-1 */ 115 Int PSinv [ ], /* inverse of P from symbolic factorization */ 116 double Rs [ ], /* scale factors for A */ 117 118 /* inputs, modified on output */ 119 Int Offp [ ], /* off-diagonal matrix (modified by this routine) */ 120 Int Offi [ ], 121 Entry Offx [ ], 122 KLU_common *Common /* the control input/output structure */ 123 ) ; 124 125 126 size_t KLU_kernel_factor /* 0 if failure, size of LU if OK */ 127 ( 128 /* inputs, not modified */ 129 Int n, /* A is n-by-n. n must be > 0. */ 130 Int Ap [ ], /* size n+1, column pointers for A */ 131 Int Ai [ ], /* size nz = Ap [n], row indices for A */ 132 Entry Ax [ ], /* size nz, values of A */ 133 Int Q [ ], /* size n, optional column permutation */ 134 double Lsize, /* initial size of L and U */ 135 136 /* outputs, not defined on input */ 137 Unit **p_LU, /* row indices and values of L and U */ 138 Entry Udiag [ ], /* size n, diagonal of U */ 139 Int Llen [ ], /* size n, column length of L */ 140 Int Ulen [ ], /* size n, column length of U */ 141 Int Lip [ ], /* size n+1, column pointers of L */ 142 Int Uip [ ], /* size n+1, column pointers of U */ 143 Int P [ ], /* row permutation, size n */ 144 Int *lnz, /* size of L */ 145 Int *unz, /* size of U */ 146 147 /* workspace, undefined on input */ 148 Entry *X, /* size n entries. Zero on output */ 149 Int *Work, /* size 5n Int's */ 150 151 /* inputs, not modified on output */ 152 Int k1, /* the block of A is from k1 to k2-1 */ 153 Int PSinv [ ], /* inverse of P from symbolic factorization */ 154 double Rs [ ], /* scale factors for A */ 155 156 /* inputs, modified on output */ 157 Int Offp [ ], /* off-diagonal matrix (modified by this routine) */ 158 Int Offi [ ], 159 Entry Offx [ ], 160 KLU_common *Common /* the control input/output structure */ 161 ) ; 162 163 void KLU_lsolve 164 ( 165 /* inputs, not modified: */ 166 Int n, 167 Int Lp [ ], 168 Int Li [ ], 169 Unit LU [ ], 170 Int nrhs, 171 /* right-hand-side on input, solution to Lx=b on output */ 172 Entry X [ ] 173 ) ; 174 175 void KLU_ltsolve 176 ( 177 /* inputs, not modified: */ 178 Int n, 179 Int Lp [ ], 180 Int Li [ ], 181 Unit LU [ ], 182 Int nrhs, 183 #ifdef COMPLEX 184 Int conj_solve, 185 #endif 186 /* right-hand-side on input, solution to L'x=b on output */ 187 Entry X [ ] 188 ) ; 189 190 191 void KLU_usolve 192 ( 193 /* inputs, not modified: */ 194 Int n, 195 Int Up [ ], 196 Int Ui [ ], 197 Unit LU [ ], 198 Entry Udiag [ ], 199 Int nrhs, 200 /* right-hand-side on input, solution to Ux=b on output */ 201 Entry X [ ] 202 ) ; 203 204 void KLU_utsolve 205 ( 206 /* inputs, not modified: */ 207 Int n, 208 Int Up [ ], 209 Int Ui [ ], 210 Unit LU [ ], 211 Entry Udiag [ ], 212 Int nrhs, 213 #ifdef COMPLEX 214 Int conj_solve, 215 #endif 216 /* right-hand-side on input, solution to U'x=b on output */ 217 Entry X [ ] 218 ) ; 219 220 Int KLU_valid 221 ( 222 Int n, 223 Int Ap [ ], 224 Int Ai [ ], 225 Entry Ax [ ] 226 ) ; 227 228 Int KLU_valid_LU 229 ( 230 Int n, 231 Int flag_test_start_ptr, 232 Int Xip [ ], 233 Int Xlen [ ], 234 Unit LU [ ] 235 ); 236 237 size_t KLU_add_size_t (size_t a, size_t b, Int *ok) ; 238 239 size_t KLU_mult_size_t (size_t a, size_t k, Int *ok) ; 240 241 KLU_symbolic *KLU_alloc_symbolic (Int n, Int *Ap, Int *Ai, KLU_common *Common) ; 242 243 #endif 244