00001 /* ========================================================================== */ 00002 /* === Include/cholmod_internal.h =========================================== */ 00003 /* ========================================================================== */ 00004 00005 /* ----------------------------------------------------------------------------- 00006 * CHOLMOD/Include/cholmod_internal.h. 00007 * Copyright (C) 2005-2006, Univ. of Florida. Author: Timothy A. Davis 00008 * CHOLMOD/Include/cholmod_internal.h is licensed under Version 2.1 of the GNU 00009 * Lesser General Public License. See lesser.txt for a text of the license. 00010 * CHOLMOD is also available under other licenses; contact authors for details. 00011 * http://www.cise.ufl.edu/research/sparse 00012 * -------------------------------------------------------------------------- */ 00013 00014 /* CHOLMOD internal include file. 00015 * 00016 * This file contains internal definitions for CHOLMOD, not meant to be included 00017 * in user code. They define macros that are not prefixed with CHOLMOD_. This 00018 * file can safely #include'd in user code if you want to make use of the 00019 * macros defined here, and don't mind the possible name conflicts with your 00020 * code, however. 00021 * 00022 * Required by all CHOLMOD routines. Not required by any user routine that 00023 * uses CHOLMOMD. Unless debugging is enabled, this file does not require any 00024 * CHOLMOD module (not even the Core module). 00025 * 00026 * If debugging is enabled, all CHOLMOD modules require the Check module. 00027 * Enabling debugging requires that this file be editted. Debugging cannot be 00028 * enabled with a compiler flag. This is because CHOLMOD is exceedingly slow 00029 * when debugging is enabled. Debugging is meant for development of CHOLMOD 00030 * itself, not by users of CHOLMOD. 00031 */ 00032 00033 #ifndef CHOLMOD_INTERNAL_H 00034 #define CHOLMOD_INTERNAL_H 00035 00036 /* ========================================================================== */ 00037 /* === large file I/O ======================================================= */ 00038 /* ========================================================================== */ 00039 00040 /* Definitions for large file I/O must come before any other #includes. If 00041 * this causes problems (may not be portable to all platforms), then compile 00042 * CHOLMOD with -DNLARGEFILE. You must do this for MATLAB 6.5 and earlier, 00043 * for example. */ 00044 00045 #include "cholmod_io64.h" 00046 00047 /* ========================================================================== */ 00048 /* === debugging and basic includes ========================================= */ 00049 /* ========================================================================== */ 00050 00051 /* turn off debugging */ 00052 #ifndef NDEBUG 00053 #define NDEBUG 00054 #endif 00055 00056 /* Uncomment this line to enable debugging. CHOLMOD will be very slow. 00057 #undef NDEBUG 00058 */ 00059 00060 #ifdef MATLAB_MEX_FILE 00061 #include "mex.h" 00062 #endif 00063 00064 #if !defined(NPRINT) || !defined(NDEBUG) 00065 #include <stdio.h> 00066 #endif 00067 00068 #include <stddef.h> 00069 #include <math.h> 00070 #include <limits.h> 00071 #include <float.h> 00072 #include <stdlib.h> 00073 00074 /* ========================================================================== */ 00075 /* === basic definitions ==================================================== */ 00076 /* ========================================================================== */ 00077 00078 /* Some non-conforming compilers insist on defining TRUE and FALSE. */ 00079 #undef TRUE 00080 #undef FALSE 00081 #define TRUE 1 00082 #define FALSE 0 00083 #define BOOLEAN(x) ((x) ? TRUE : FALSE) 00084 00085 /* NULL should already be defined, but ensure it is here. */ 00086 #ifndef NULL 00087 #define NULL ((void *) 0) 00088 #endif 00089 00090 /* FLIP is a "negation about -1", and is used to mark an integer i that is 00091 * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY 00092 * is negative, and FLIP of a number < EMTPY is positive. FLIP (FLIP (i)) = i 00093 * for all integers i. UNFLIP (i) is >= EMPTY. */ 00094 #define EMPTY (-1) 00095 #define FLIP(i) (-(i)-2) 00096 #define UNFLIP(i) (((i) < EMPTY) ? FLIP (i) : (i)) 00097 00098 /* MAX and MIN are not safe to use for NaN's */ 00099 #define MAX(a,b) (((a) > (b)) ? (a) : (b)) 00100 #define MAX3(a,b,c) (((a) > (b)) ? (MAX (a,c)) : (MAX (b,c))) 00101 #define MAX4(a,b,c,d) (((a) > (b)) ? (MAX3 (a,c,d)) : (MAX3 (b,c,d))) 00102 #define MIN(a,b) (((a) < (b)) ? (a) : (b)) 00103 #define IMPLIES(p,q) (!(p) || (q)) 00104 00105 /* find the sign: -1 if x < 0, 1 if x > 0, zero otherwise. 00106 * Not safe for NaN's */ 00107 #define SIGN(x) (((x) < 0) ? (-1) : (((x) > 0) ? 1 : 0)) 00108 00109 /* round up an integer x to a multiple of s */ 00110 #define ROUNDUP(x,s) ((s) * (((x) + ((s) - 1)) / (s))) 00111 00112 #define ERROR(status,msg) \ 00113 CHOLMOD(error) (status, __FILE__, __LINE__, msg, Common) 00114 00115 /* Check a pointer and return if null. Set status to invalid, unless the 00116 * status is already "out of memory" */ 00117 #define RETURN_IF_NULL(A,result) \ 00118 { \ 00119 if ((A) == NULL) \ 00120 { \ 00121 if (Common->status != CHOLMOD_OUT_OF_MEMORY) \ 00122 { \ 00123 ERROR (CHOLMOD_INVALID, "argument missing") ; \ 00124 } \ 00125 return (result) ; \ 00126 } \ 00127 } 00128 00129 /* Return if Common is NULL or invalid */ 00130 #define RETURN_IF_NULL_COMMON(result) \ 00131 { \ 00132 if (Common == NULL) \ 00133 { \ 00134 return (result) ; \ 00135 } \ 00136 if (Common->itype != ITYPE || Common->dtype != DTYPE) \ 00137 { \ 00138 Common->status = CHOLMOD_INVALID ; \ 00139 return (result) ; \ 00140 } \ 00141 } 00142 00143 #define IS_NAN(x) CHOLMOD_IS_NAN(x) 00144 #define IS_ZERO(x) CHOLMOD_IS_ZERO(x) 00145 #define IS_NONZERO(x) CHOLMOD_IS_NONZERO(x) 00146 #define IS_LT_ZERO(x) CHOLMOD_IS_LT_ZERO(x) 00147 #define IS_GT_ZERO(x) CHOLMOD_IS_GT_ZERO(x) 00148 #define IS_LE_ZERO(x) CHOLMOD_IS_LE_ZERO(x) 00149 00150 /* 1e308 is a huge number that doesn't take many characters to print in a 00151 * file, in CHOLMOD/Check/cholmod_read and _write. Numbers larger than this 00152 * are interpretted as Inf, since sscanf doesn't read in Inf's properly. 00153 * This assumes IEEE double precision arithmetic. DBL_MAX would be a little 00154 * better, except that it takes too many digits to print in a file. */ 00155 #define HUGE_DOUBLE 1e308 00156 00157 /* ========================================================================== */ 00158 /* === int/UF_long and double/float definitions ============================= */ 00159 /* ========================================================================== */ 00160 00161 /* CHOLMOD is designed for 3 types of integer variables: 00162 * 00163 * (1) all integers are int 00164 * (2) most integers are int, some are UF_long 00165 * (3) all integers are UF_long 00166 * 00167 * and two kinds of floating-point values: 00168 * 00169 * (1) double 00170 * (2) float 00171 * 00172 * the complex types (ANSI-compatible complex, and MATLAB-compatable zomplex) 00173 * are based on the double or float type, and are not selected here. They 00174 * are typically selected via template routines. 00175 * 00176 * This gives 6 different modes in which CHOLMOD can be compiled (only the 00177 * first two are currently supported): 00178 * 00179 * DINT double, int prefix: cholmod_ 00180 * DLONG double, UF_long prefix: cholmod_l_ 00181 * DMIX double, mixed int/UF_long prefix: cholmod_m_ 00182 * SINT float, int prefix: cholmod_si_ 00183 * SLONG float, UF_long prefix: cholmod_sl_ 00184 * SMIX float, mixed int/log prefix: cholmod_sm_ 00185 * 00186 * These are selected with compile time flags (-DDLONG, for example). If no 00187 * flag is selected, the default is DINT. 00188 * 00189 * All six versions use the same include files. The user-visible include files 00190 * are completely independent of which int/UF_long/double/float version is being 00191 * used. The integer / real types in all data structures (sparse, triplet, 00192 * dense, common, and triplet) are defined at run-time, not compile-time, so 00193 * there is only one "cholmod_sparse" data type. Void pointers are used inside 00194 * that data structure to point to arrays of the proper type. Each data 00195 * structure has an itype and dtype field which determines the kind of basic 00196 * types used. These are defined in Include/cholmod_core.h. 00197 * 00198 * FUTURE WORK: support all six types (float, and mixed int/UF_long) 00199 * 00200 * UF_long is normally defined as long. However, for WIN64 it is __int64. 00201 * It can also be redefined for other platforms, by modifying UFconfig.h. 00202 */ 00203 00204 #include "UFconfig.h" 00205 00206 /* -------------------------------------------------------------------------- */ 00207 /* Size_max: the largest value of size_t */ 00208 /* -------------------------------------------------------------------------- */ 00209 00210 #define Size_max ((size_t) (-1)) 00211 00212 /* routines for doing arithmetic on size_t, and checking for overflow */ 00213 size_t cholmod_add_size_t (size_t a, size_t b, int *ok) ; 00214 size_t cholmod_mult_size_t (size_t a, size_t k, int *ok) ; 00215 size_t cholmod_l_add_size_t (size_t a, size_t b, int *ok) ; 00216 size_t cholmod_l_mult_size_t (size_t a, size_t k, int *ok) ; 00217 00218 /* -------------------------------------------------------------------------- */ 00219 /* double (also complex double), UF_long */ 00220 /* -------------------------------------------------------------------------- */ 00221 00222 #ifdef DLONG 00223 #define Real double 00224 #define Int UF_long 00225 #define Int_max UF_long_max 00226 #define CHOLMOD(name) cholmod_l_ ## name 00227 #define LONG 00228 #define DOUBLE 00229 #define ITYPE CHOLMOD_LONG 00230 #define DTYPE CHOLMOD_DOUBLE 00231 #define ID UF_long_id 00232 00233 /* -------------------------------------------------------------------------- */ 00234 /* double, int/UF_long */ 00235 /* -------------------------------------------------------------------------- */ 00236 00237 #elif defined (DMIX) 00238 #error "mixed int/UF_long not yet supported" 00239 00240 /* -------------------------------------------------------------------------- */ 00241 /* single, int */ 00242 /* -------------------------------------------------------------------------- */ 00243 00244 #elif defined (SINT) 00245 #error "single-precision not yet supported" 00246 00247 /* -------------------------------------------------------------------------- */ 00248 /* single, UF_long */ 00249 /* -------------------------------------------------------------------------- */ 00250 00251 #elif defined (SLONG) 00252 #error "single-precision not yet supported" 00253 00254 /* -------------------------------------------------------------------------- */ 00255 /* single, int/UF_long */ 00256 /* -------------------------------------------------------------------------- */ 00257 00258 #elif defined (SMIX) 00259 #error "single-precision not yet supported" 00260 00261 /* -------------------------------------------------------------------------- */ 00262 /* double (also complex double), int: this is the default */ 00263 /* -------------------------------------------------------------------------- */ 00264 00265 #else 00266 00267 #ifndef DINT 00268 #define DINT 00269 #endif 00270 #define INT 00271 #define DOUBLE 00272 00273 #define Real double 00274 #define Int int 00275 #define Int_max INT_MAX 00276 #define CHOLMOD(name) cholmod_ ## name 00277 #define ITYPE CHOLMOD_INT 00278 #define DTYPE CHOLMOD_DOUBLE 00279 #define ID "%d" 00280 00281 #endif 00282 00283 00284 /* ========================================================================== */ 00285 /* === real/complex arithmetic ============================================== */ 00286 /* ========================================================================== */ 00287 00288 #include "cholmod_complexity.h" 00289 00290 /* ========================================================================== */ 00291 /* === Architecture and BLAS ================================================ */ 00292 /* ========================================================================== */ 00293 00294 #include "cholmod_blas.h" 00295 00296 /* ========================================================================== */ 00297 /* === debugging definitions ================================================ */ 00298 /* ========================================================================== */ 00299 00300 #ifndef NDEBUG 00301 00302 #include <assert.h> 00303 #include "cholmod.h" 00304 00305 /* The cholmod_dump routines are in the Check module. No CHOLMOD routine 00306 * calls the cholmod_check_* or cholmod_print_* routines in the Check module, 00307 * since they use Common workspace that may already be in use. Instead, they 00308 * use the cholmod_dump_* routines defined there, which allocate their own 00309 * workspace if they need it. */ 00310 00311 #ifndef EXTERN 00312 #define EXTERN extern 00313 #endif 00314 00315 /* double, int */ 00316 EXTERN int cholmod_dump ; 00317 EXTERN int cholmod_dump_malloc ; 00318 UF_long cholmod_dump_sparse (cholmod_sparse *, const char *, cholmod_common *); 00319 int cholmod_dump_factor (cholmod_factor *, const char *, cholmod_common *) ; 00320 int cholmod_dump_triplet (cholmod_triplet *, const char *, cholmod_common *) ; 00321 int cholmod_dump_dense (cholmod_dense *, const char *, cholmod_common *) ; 00322 int cholmod_dump_subset (int *, size_t, size_t, const char *, 00323 cholmod_common *) ; 00324 int cholmod_dump_perm (int *, size_t, size_t, const char *, cholmod_common *) ; 00325 int cholmod_dump_parent (int *, size_t, const char *, cholmod_common *) ; 00326 void cholmod_dump_init (const char *, cholmod_common *) ; 00327 int cholmod_dump_mem (const char *, UF_long, cholmod_common *) ; 00328 void cholmod_dump_real (const char *, Real *, UF_long, UF_long, int, int, 00329 cholmod_common *) ; 00330 void cholmod_dump_super (UF_long, int *, int *, int *, int *, double *, int, 00331 cholmod_common *) ; 00332 int cholmod_dump_partition (UF_long, int *, int *, int *, int *, UF_long, 00333 cholmod_common *) ; 00334 int cholmod_dump_work(int, int, UF_long, cholmod_common *) ; 00335 00336 /* double, UF_long */ 00337 EXTERN int cholmod_l_dump ; 00338 EXTERN int cholmod_l_dump_malloc ; 00339 UF_long cholmod_l_dump_sparse (cholmod_sparse *, const char *, 00340 cholmod_common *) ; 00341 int cholmod_l_dump_factor (cholmod_factor *, const char *, cholmod_common *) ; 00342 int cholmod_l_dump_triplet (cholmod_triplet *, const char *, cholmod_common *); 00343 int cholmod_l_dump_dense (cholmod_dense *, const char *, cholmod_common *) ; 00344 int cholmod_l_dump_subset (UF_long *, size_t, size_t, const char *, 00345 cholmod_common *) ; 00346 int cholmod_l_dump_perm (UF_long *, size_t, size_t, const char *, 00347 cholmod_common *) ; 00348 int cholmod_l_dump_parent (UF_long *, size_t, const char *, cholmod_common *) ; 00349 void cholmod_l_dump_init (const char *, cholmod_common *) ; 00350 int cholmod_l_dump_mem (const char *, UF_long, cholmod_common *) ; 00351 void cholmod_l_dump_real (const char *, Real *, UF_long, UF_long, int, int, 00352 cholmod_common *) ; 00353 void cholmod_l_dump_super (UF_long, UF_long *, UF_long *, UF_long *, UF_long *, 00354 double *, int, cholmod_common *) ; 00355 int cholmod_l_dump_partition (UF_long, UF_long *, UF_long *, UF_long *, 00356 UF_long *, UF_long, cholmod_common *) ; 00357 int cholmod_l_dump_work(int, int, UF_long, cholmod_common *) ; 00358 00359 #define DEBUG_INIT(s,Common) { CHOLMOD(dump_init)(s, Common) ; } 00360 #define ASSERT(expression) (assert (expression)) 00361 00362 #define PRK(k,params) \ 00363 { \ 00364 if (CHOLMOD(dump) >= (k) && Common->print_function != NULL) \ 00365 { \ 00366 (Common->print_function) params ; \ 00367 } \ 00368 } 00369 00370 #define PRINT0(params) PRK (0, params) 00371 #define PRINT1(params) PRK (1, params) 00372 #define PRINT2(params) PRK (2, params) 00373 #define PRINT3(params) PRK (3, params) 00374 00375 #define PRINTM(params) \ 00376 { \ 00377 if (CHOLMOD(dump_malloc) > 0) \ 00378 { \ 00379 printf params ; \ 00380 } \ 00381 } 00382 00383 #define DEBUG(statement) statement 00384 00385 #else 00386 00387 /* Debugging disabled (the normal case) */ 00388 #define PRK(k,params) 00389 #define DEBUG_INIT(s,Common) 00390 #define PRINT0(params) 00391 #define PRINT1(params) 00392 #define PRINT2(params) 00393 #define PRINT3(params) 00394 #define PRINTM(params) 00395 #define ASSERT(expression) 00396 #define DEBUG(statement) 00397 #endif 00398 00399 #endif