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