amd_internal.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. /* ========================================================================= */
  2. /* === amd_internal.h ====================================================== */
  3. /* ========================================================================= */
  4. /* ------------------------------------------------------------------------- */
  5. /* AMD, Copyright (c) Timothy A. Davis, */
  6. /* Patrick R. Amestoy, and Iain S. Duff. See ../README.txt for License. */
  7. /* email: DrTimothyAldenDavis@gmail.com */
  8. /* ------------------------------------------------------------------------- */
  9. /* This file is for internal use in AMD itself, and does not normally need to
  10. * be included in user code (it is included in UMFPACK, however). All others
  11. * should use amd.h instead.
  12. *
  13. * The following compile-time definitions affect how AMD is compiled.
  14. *
  15. * -DNPRINT
  16. *
  17. * Disable all printing. stdio.h will not be included. Printing can
  18. * be re-enabled at run-time by setting the global pointer amd_printf
  19. * to printf (or mexPrintf for a MATLAB mexFunction).
  20. *
  21. * -DNMALLOC
  22. *
  23. * No memory manager is defined at compile-time. You MUST define the
  24. * function pointers amd_malloc, amd_free, amd_realloc, and
  25. * amd_calloc at run-time for AMD to work properly.
  26. */
  27. /* ========================================================================= */
  28. /* === NDEBUG ============================================================== */
  29. /* ========================================================================= */
  30. /*
  31. * Turning on debugging takes some work (see below). If you do not edit this
  32. * file, then debugging is always turned off, regardless of whether or not
  33. * -DNDEBUG is specified in your compiler options.
  34. *
  35. * If AMD is being compiled as a mexFunction, then MATLAB_MEX_FILE is defined,
  36. * and mxAssert is used instead of assert. If debugging is not enabled, no
  37. * MATLAB include files or functions are used. Thus, the AMD library libamd.a
  38. * can be safely used in either a stand-alone C program or in another
  39. * mexFunction, without any change.
  40. */
  41. /*
  42. AMD will be exceedingly slow when running in debug mode. The next three
  43. lines ensure that debugging is turned off.
  44. */
  45. #ifndef NDEBUG
  46. #define NDEBUG
  47. #endif
  48. /*
  49. To enable debugging, uncomment the following line:
  50. #undef NDEBUG
  51. */
  52. /* ------------------------------------------------------------------------- */
  53. /* ANSI include files */
  54. /* ------------------------------------------------------------------------- */
  55. /* from stdlib.h: size_t, malloc, free, realloc, and calloc */
  56. #include <stdlib.h>
  57. #if !defined(NPRINT) || !defined(NDEBUG)
  58. /* from stdio.h: printf. Not included if NPRINT is defined at compile time.
  59. * fopen and fscanf are used when debugging. */
  60. #include <stdio.h>
  61. #endif
  62. /* from limits.h: INT_MAX and LONG_MAX */
  63. #include <limits.h>
  64. /* from math.h: sqrt */
  65. #include <math.h>
  66. /* ------------------------------------------------------------------------- */
  67. /* MATLAB include files (only if being used in or via MATLAB) */
  68. /* ------------------------------------------------------------------------- */
  69. #ifdef MATLAB_MEX_FILE
  70. #include "matrix.h"
  71. #include "mex.h"
  72. #endif
  73. /* ------------------------------------------------------------------------- */
  74. /* basic definitions */
  75. /* ------------------------------------------------------------------------- */
  76. #ifdef FLIP
  77. #undef FLIP
  78. #endif
  79. #ifdef MAX
  80. #undef MAX
  81. #endif
  82. #ifdef MIN
  83. #undef MIN
  84. #endif
  85. #ifdef EMPTY
  86. #undef EMPTY
  87. #endif
  88. #ifdef GLOBAL
  89. #undef GLOBAL
  90. #endif
  91. #ifdef PRIVATE
  92. #undef PRIVATE
  93. #endif
  94. /* FLIP is a "negation about -1", and is used to mark an integer i that is
  95. * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY
  96. * is negative, and FLIP of a number < EMTPY is positive. FLIP (FLIP (i)) = i
  97. * for all integers i. UNFLIP (i) is >= EMPTY. */
  98. #define EMPTY (-1)
  99. #define FLIP(i) (-(i)-2)
  100. #define UNFLIP(i) ((i < EMPTY) ? FLIP (i) : (i))
  101. /* for integer MAX/MIN, or for doubles when we don't care how NaN's behave: */
  102. #define MAX(a,b) (((a) > (b)) ? (a) : (b))
  103. #define MIN(a,b) (((a) < (b)) ? (a) : (b))
  104. /* logical expression of p implies q: */
  105. #define IMPLIES(p,q) (!(p) || (q))
  106. /* Note that the IBM RS 6000 xlc predefines TRUE and FALSE in <types.h>. */
  107. /* The Compaq Alpha also predefines TRUE and FALSE. */
  108. #ifdef TRUE
  109. #undef TRUE
  110. #endif
  111. #ifdef FALSE
  112. #undef FALSE
  113. #endif
  114. #define TRUE (1)
  115. #define FALSE (0)
  116. #define PRIVATE static
  117. #define GLOBAL
  118. #define EMPTY (-1)
  119. /* Note that Linux's gcc 2.96 defines NULL as ((void *) 0), but other */
  120. /* compilers (even gcc 2.95.2 on Solaris) define NULL as 0 or (0). We */
  121. /* need to use the ANSI standard value of 0. */
  122. #ifdef NULL
  123. #undef NULL
  124. #endif
  125. #define NULL 0
  126. /* largest value of size_t */
  127. #ifndef SIZE_T_MAX
  128. #ifdef SIZE_MAX
  129. /* C99 only */
  130. #define SIZE_T_MAX SIZE_MAX
  131. #else
  132. #define SIZE_T_MAX ((size_t) (-1))
  133. #endif
  134. #endif
  135. /* ------------------------------------------------------------------------- */
  136. /* integer type for AMD: int or SuiteSparse_long */
  137. /* ------------------------------------------------------------------------- */
  138. #include "amd.h"
  139. #if defined (DLONG) || defined (ZLONG)
  140. #define Int SuiteSparse_long
  141. #define ID SuiteSparse_long_id
  142. #define Int_MAX SuiteSparse_long_max
  143. #define AMD_order amd_l_order
  144. #define AMD_defaults amd_l_defaults
  145. #define AMD_control amd_l_control
  146. #define AMD_info amd_l_info
  147. #define AMD_1 amd_l1
  148. #define AMD_2 amd_l2
  149. #define AMD_valid amd_l_valid
  150. #define AMD_aat amd_l_aat
  151. #define AMD_postorder amd_l_postorder
  152. #define AMD_post_tree amd_l_post_tree
  153. #define AMD_dump amd_l_dump
  154. #define AMD_debug amd_l_debug
  155. #define AMD_debug_init amd_l_debug_init
  156. #define AMD_preprocess amd_l_preprocess
  157. #else
  158. #define Int int
  159. #define ID "%d"
  160. #define Int_MAX INT_MAX
  161. #define AMD_order amd_order
  162. #define AMD_defaults amd_defaults
  163. #define AMD_control amd_control
  164. #define AMD_info amd_info
  165. #define AMD_1 amd_1
  166. #define AMD_2 amd_2
  167. #define AMD_valid amd_valid
  168. #define AMD_aat amd_aat
  169. #define AMD_postorder amd_postorder
  170. #define AMD_post_tree amd_post_tree
  171. #define AMD_dump amd_dump
  172. #define AMD_debug amd_debug
  173. #define AMD_debug_init amd_debug_init
  174. #define AMD_preprocess amd_preprocess
  175. #endif
  176. /* ========================================================================= */
  177. /* === PRINTF macro ======================================================== */
  178. /* ========================================================================= */
  179. /* All output goes through the PRINTF macro. */
  180. #define PRINTF(params) { if (amd_printf != NULL) (void) amd_printf params ; }
  181. /* ------------------------------------------------------------------------- */
  182. /* AMD routine definitions (not user-callable) */
  183. /* ------------------------------------------------------------------------- */
  184. GLOBAL size_t AMD_aat
  185. (
  186. Int n,
  187. const Int Ap [ ],
  188. const Int Ai [ ],
  189. Int Len [ ],
  190. Int Tp [ ],
  191. double Info [ ]
  192. ) ;
  193. GLOBAL void AMD_1
  194. (
  195. Int n,
  196. const Int Ap [ ],
  197. const Int Ai [ ],
  198. Int P [ ],
  199. Int Pinv [ ],
  200. Int Len [ ],
  201. Int slen,
  202. Int S [ ],
  203. double Control [ ],
  204. double Info [ ]
  205. ) ;
  206. GLOBAL void AMD_postorder
  207. (
  208. Int nn,
  209. Int Parent [ ],
  210. Int Npiv [ ],
  211. Int Fsize [ ],
  212. Int Order [ ],
  213. Int Child [ ],
  214. Int Sibling [ ],
  215. Int Stack [ ]
  216. ) ;
  217. GLOBAL Int AMD_post_tree
  218. (
  219. Int root,
  220. Int k,
  221. Int Child [ ],
  222. const Int Sibling [ ],
  223. Int Order [ ],
  224. Int Stack [ ]
  225. #ifndef NDEBUG
  226. , Int nn
  227. #endif
  228. ) ;
  229. GLOBAL void AMD_preprocess
  230. (
  231. Int n,
  232. const Int Ap [ ],
  233. const Int Ai [ ],
  234. Int Rp [ ],
  235. Int Ri [ ],
  236. Int W [ ],
  237. Int Flag [ ]
  238. ) ;
  239. /* ------------------------------------------------------------------------- */
  240. /* debugging definitions */
  241. /* ------------------------------------------------------------------------- */
  242. #ifndef NDEBUG
  243. /* from assert.h: assert macro */
  244. #include <assert.h>
  245. #ifndef EXTERN
  246. #define EXTERN extern
  247. #endif
  248. EXTERN Int AMD_debug ;
  249. GLOBAL void AMD_debug_init ( char *s ) ;
  250. GLOBAL void AMD_dump
  251. (
  252. Int n,
  253. Int Pe [ ],
  254. Int Iw [ ],
  255. Int Len [ ],
  256. Int iwlen,
  257. Int pfree,
  258. Int Nv [ ],
  259. Int Next [ ],
  260. Int Last [ ],
  261. Int Head [ ],
  262. Int Elen [ ],
  263. Int Degree [ ],
  264. Int W [ ],
  265. Int nel
  266. ) ;
  267. #ifdef ASSERT
  268. #undef ASSERT
  269. #endif
  270. /* Use mxAssert if AMD is compiled into a mexFunction */
  271. #ifdef MATLAB_MEX_FILE
  272. #define ASSERT(expression) (mxAssert ((expression), ""))
  273. #else
  274. #define ASSERT(expression) (assert (expression))
  275. #endif
  276. #define AMD_DEBUG0(params) { PRINTF (params) ; }
  277. #define AMD_DEBUG1(params) { if (AMD_debug >= 1) PRINTF (params) ; }
  278. #define AMD_DEBUG2(params) { if (AMD_debug >= 2) PRINTF (params) ; }
  279. #define AMD_DEBUG3(params) { if (AMD_debug >= 3) PRINTF (params) ; }
  280. #define AMD_DEBUG4(params) { if (AMD_debug >= 4) PRINTF (params) ; }
  281. #else
  282. /* no debugging */
  283. #define ASSERT(expression)
  284. #define AMD_DEBUG0(params)
  285. #define AMD_DEBUG1(params)
  286. #define AMD_DEBUG2(params)
  287. #define AMD_DEBUG3(params)
  288. #define AMD_DEBUG4(params)
  289. #endif