1 /* ========================================================================= */ 2 /* === camd_internal.h ===================================================== */ 3 /* ========================================================================= */ 4 5 /* ------------------------------------------------------------------------- */ 6 /* CAMD, Copyright (c) Timothy A. Davis, Yanqing Chen, */ 7 /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */ 8 /* email: DrTimothyAldenDavis@gmail.com */ 9 /* ------------------------------------------------------------------------- */ 10 11 /* This file is for internal use in CAMD itself, and does not normally need to 12 * be included in user code (it is included in UMFPACK, however). All others 13 * should use camd.h instead. 14 */ 15 16 /* ========================================================================= */ 17 /* === NDEBUG ============================================================== */ 18 /* ========================================================================= */ 19 20 /* 21 * Turning on debugging takes some work (see below). If you do not edit this 22 * file, then debugging is always turned off, regardless of whether or not 23 * -DNDEBUG is specified in your compiler options. 24 * 25 * If CAMD is being compiled as a mexFunction, then MATLAB_MEX_FILE is defined, 26 * and mxAssert is used instead of assert. If debugging is not enabled, no 27 * MATLAB include files or functions are used. Thus, the CAMD library libcamd.a 28 * can be safely used in either a stand-alone C program or in another 29 * mexFunction, without any change. 30 */ 31 32 /* 33 CAMD will be exceedingly slow when running in debug mode. The next three 34 lines ensure that debugging is turned off. 35 */ 36 #ifndef NDEBUG 37 #define NDEBUG 38 #endif 39 40 /* 41 To enable debugging, uncomment the following line: 42 #undef NDEBUG 43 */ 44 45 46 /* ------------------------------------------------------------------------- */ 47 /* ANSI include files */ 48 /* ------------------------------------------------------------------------- */ 49 50 /* from stdlib.h: size_t, malloc, free, realloc, and calloc */ 51 #include <stdlib.h> 52 53 #if !defined(NPRINT) || !defined(NDEBUG) 54 /* from stdio.h: printf. Not included if NPRINT is defined at compile time. 55 * fopen and fscanf are used when debugging. */ 56 #include <stdio.h> 57 #endif 58 59 /* from limits.h: INT_MAX and LONG_MAX */ 60 #include <limits.h> 61 62 /* from math.h: sqrt */ 63 #include <math.h> 64 65 /* ------------------------------------------------------------------------- */ 66 /* MATLAB include files (only if being used in or via MATLAB) */ 67 /* ------------------------------------------------------------------------- */ 68 69 #ifdef MATLAB_MEX_FILE 70 #include "matrix.h" 71 #include "mex.h" 72 #endif 73 74 /* ------------------------------------------------------------------------- */ 75 /* basic definitions */ 76 /* ------------------------------------------------------------------------- */ 77 78 #ifdef FLIP 79 #undef FLIP 80 #endif 81 82 #ifdef MAX 83 #undef MAX 84 #endif 85 86 #ifdef MIN 87 #undef MIN 88 #endif 89 90 #ifdef EMPTY 91 #undef EMPTY 92 #endif 93 94 #ifdef GLOBAL 95 #undef GLOBAL 96 #endif 97 98 #ifdef PRIVATE 99 #undef PRIVATE 100 #endif 101 102 /* FLIP is a "negation about -1", and is used to mark an integer i that is 103 * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY 104 * is negative, and FLIP of a number < EMTPY is positive. FLIP (FLIP (i)) = i 105 * for all integers i. UNFLIP (i) is >= EMPTY. */ 106 #define EMPTY (-1) 107 #define FLIP(i) (-(i)-2) 108 #define UNFLIP(i) ((i < EMPTY) ? FLIP (i) : (i)) 109 110 /* for integer MAX/MIN, or for doubles when we don't care how NaN's behave: */ 111 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 112 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 113 114 /* logical expression of p implies q: */ 115 #define IMPLIES(p,q) (!(p) || (q)) 116 117 /* Note that the IBM RS 6000 xlc predefines TRUE and FALSE in <types.h>. */ 118 /* The Compaq Alpha also predefines TRUE and FALSE. */ 119 #ifdef TRUE 120 #undef TRUE 121 #endif 122 #ifdef FALSE 123 #undef FALSE 124 #endif 125 126 #define TRUE (1) 127 #define FALSE (0) 128 #define PRIVATE static 129 #define GLOBAL 130 #define EMPTY (-1) 131 132 /* Note that Linux's gcc 2.96 defines NULL as ((void *) 0), but other */ 133 /* compilers (even gcc 2.95.2 on Solaris) define NULL as 0 or (0). We */ 134 /* need to use the ANSI standard value of 0. */ 135 #ifdef NULL 136 #undef NULL 137 #endif 138 139 #define NULL 0 140 141 /* largest value of size_t */ 142 #ifndef SIZE_T_MAX 143 #ifdef SIZE_MAX 144 /* C99 only */ 145 #define SIZE_T_MAX SIZE_MAX 146 #else 147 #define SIZE_T_MAX ((size_t) (-1)) 148 #endif 149 #endif 150 151 /* ------------------------------------------------------------------------- */ 152 /* integer type for CAMD: int or SuiteSparse_long */ 153 /* ------------------------------------------------------------------------- */ 154 155 #include "camd.h" 156 157 #if defined (DLONG) || defined (ZLONG) 158 159 #define Int SuiteSparse_long 160 #define ID SuiteSparse_long_id 161 #define Int_MAX SuiteSparse_long_max 162 163 #define CAMD_order camd_l_order 164 #define CAMD_defaults camd_l_defaults 165 #define CAMD_control camd_l_control 166 #define CAMD_info camd_l_info 167 #define CAMD_1 camd_l1 168 #define CAMD_2 camd_l2 169 #define CAMD_valid camd_l_valid 170 #define CAMD_cvalid camd_l_cvalid 171 #define CAMD_aat camd_l_aat 172 #define CAMD_postorder camd_l_postorder 173 #define CAMD_post_tree camd_l_post_tree 174 #define CAMD_dump camd_l_dump 175 #define CAMD_debug camd_l_debug 176 #define CAMD_debug_init camd_l_debug_init 177 #define CAMD_preprocess camd_l_preprocess 178 179 #else 180 181 #define Int int 182 #define ID "%d" 183 #define Int_MAX INT_MAX 184 185 #define CAMD_order camd_order 186 #define CAMD_defaults camd_defaults 187 #define CAMD_control camd_control 188 #define CAMD_info camd_info 189 #define CAMD_1 camd_1 190 #define CAMD_2 camd_2 191 #define CAMD_valid camd_valid 192 #define CAMD_cvalid camd_cvalid 193 #define CAMD_aat camd_aat 194 #define CAMD_postorder camd_postorder 195 #define CAMD_post_tree camd_post_tree 196 #define CAMD_dump camd_dump 197 #define CAMD_debug camd_debug 198 #define CAMD_debug_init camd_debug_init 199 #define CAMD_preprocess camd_preprocess 200 201 #endif 202 203 /* ------------------------------------------------------------------------- */ 204 /* CAMD routine definitions (not user-callable) */ 205 /* ------------------------------------------------------------------------- */ 206 207 GLOBAL size_t CAMD_aat 208 ( 209 Int n, 210 const Int Ap [ ], 211 const Int Ai [ ], 212 Int Len [ ], 213 Int Tp [ ], 214 double Info [ ] 215 ) ; 216 217 GLOBAL void CAMD_1 218 ( 219 Int n, 220 const Int Ap [ ], 221 const Int Ai [ ], 222 Int P [ ], 223 Int Pinv [ ], 224 Int Len [ ], 225 Int slen, 226 Int S [ ], 227 double Control [ ], 228 double Info [ ], 229 const Int C [ ] 230 ) ; 231 232 GLOBAL Int CAMD_postorder 233 ( 234 Int j, Int k, Int n, Int head [], Int next [], Int post [], Int stack [] 235 ) ; 236 237 GLOBAL void CAMD_preprocess 238 ( 239 Int n, 240 const Int Ap [ ], 241 const Int Ai [ ], 242 Int Rp [ ], 243 Int Ri [ ], 244 Int W [ ], 245 Int Flag [ ] 246 ) ; 247 248 /* ------------------------------------------------------------------------- */ 249 /* debugging definitions */ 250 /* ------------------------------------------------------------------------- */ 251 252 #ifndef NDEBUG 253 254 /* from assert.h: assert macro */ 255 #include <assert.h> 256 257 #ifndef EXTERN 258 #define EXTERN extern 259 #endif 260 261 EXTERN Int CAMD_debug ; 262 263 GLOBAL void CAMD_debug_init ( char *s ) ; 264 265 GLOBAL void CAMD_dump 266 ( 267 Int n, 268 Int Pe [ ], 269 Int Iw [ ], 270 Int Len [ ], 271 Int iwlen, 272 Int pfree, 273 Int Nv [ ], 274 Int Next [ ], 275 Int Last [ ], 276 Int Head [ ], 277 Int Elen [ ], 278 Int Degree [ ], 279 Int W [ ], 280 Int nel, 281 Int BucketSet [], 282 const Int C [], 283 Int Curc 284 ) ; 285 286 #ifdef ASSERT 287 #undef ASSERT 288 #endif 289 290 /* Use mxAssert if CAMD is compiled into a mexFunction */ 291 #ifdef MATLAB_MEX_FILE 292 #define ASSERT(expression) (mxAssert ((expression), "")) 293 #else 294 #define ASSERT(expression) (assert (expression)) 295 #endif 296 297 #define CAMD_DEBUG0(params) { SUITESPARSE_PRINTF (params) ; } 298 #define CAMD_DEBUG1(params) \ 299 { if (CAMD_debug >= 1) SUITESPARSE_PRINTF (params) ; } 300 #define CAMD_DEBUG2(params) \ 301 { if (CAMD_debug >= 2) SUITESPARSE_PRINTF (params) ; } 302 #define CAMD_DEBUG3(params) \ 303 { if (CAMD_debug >= 3) SUITESPARSE_PRINTF (params) ; } 304 #define CAMD_DEBUG4(params) \ 305 { if (CAMD_debug >= 4) SUITESPARSE_PRINTF (params) ; } 306 307 #else 308 309 /* no debugging */ 310 #define ASSERT(expression) 311 #define CAMD_DEBUG0(params) 312 #define CAMD_DEBUG1(params) 313 #define CAMD_DEBUG2(params) 314 #define CAMD_DEBUG3(params) 315 #define CAMD_DEBUG4(params) 316 317 #endif 318