amd_internal.h 8.9 KB

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