scs 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +12 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +98 -0
  5. data/ext/scs/extconf.rb +29 -0
  6. data/lib/scs.rb +17 -0
  7. data/lib/scs/ffi.rb +117 -0
  8. data/lib/scs/solver.rb +173 -0
  9. data/lib/scs/version.rb +3 -0
  10. data/vendor/scs/LICENSE.txt +21 -0
  11. data/vendor/scs/Makefile +164 -0
  12. data/vendor/scs/README.md +222 -0
  13. data/vendor/scs/include/aa.h +56 -0
  14. data/vendor/scs/include/cones.h +46 -0
  15. data/vendor/scs/include/ctrlc.h +33 -0
  16. data/vendor/scs/include/glbopts.h +177 -0
  17. data/vendor/scs/include/linalg.h +26 -0
  18. data/vendor/scs/include/linsys.h +64 -0
  19. data/vendor/scs/include/normalize.h +18 -0
  20. data/vendor/scs/include/rw.h +17 -0
  21. data/vendor/scs/include/scs.h +161 -0
  22. data/vendor/scs/include/scs_blas.h +51 -0
  23. data/vendor/scs/include/util.h +65 -0
  24. data/vendor/scs/linsys/amatrix.c +305 -0
  25. data/vendor/scs/linsys/amatrix.h +36 -0
  26. data/vendor/scs/linsys/amatrix.o +0 -0
  27. data/vendor/scs/linsys/cpu/direct/private.c +366 -0
  28. data/vendor/scs/linsys/cpu/direct/private.h +26 -0
  29. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  30. data/vendor/scs/linsys/cpu/indirect/private.c +256 -0
  31. data/vendor/scs/linsys/cpu/indirect/private.h +31 -0
  32. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  33. data/vendor/scs/linsys/external/amd/LICENSE.txt +934 -0
  34. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +469 -0
  35. data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +254 -0
  36. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  37. data/vendor/scs/linsys/external/amd/amd.h +400 -0
  38. data/vendor/scs/linsys/external/amd/amd_1.c +180 -0
  39. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  40. data/vendor/scs/linsys/external/amd/amd_2.c +1842 -0
  41. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  42. data/vendor/scs/linsys/external/amd/amd_aat.c +184 -0
  43. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  44. data/vendor/scs/linsys/external/amd/amd_control.c +64 -0
  45. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  46. data/vendor/scs/linsys/external/amd/amd_defaults.c +37 -0
  47. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  48. data/vendor/scs/linsys/external/amd/amd_dump.c +179 -0
  49. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  50. data/vendor/scs/linsys/external/amd/amd_global.c +16 -0
  51. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  52. data/vendor/scs/linsys/external/amd/amd_info.c +119 -0
  53. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  54. data/vendor/scs/linsys/external/amd/amd_internal.h +304 -0
  55. data/vendor/scs/linsys/external/amd/amd_order.c +199 -0
  56. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  57. data/vendor/scs/linsys/external/amd/amd_post_tree.c +120 -0
  58. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  59. data/vendor/scs/linsys/external/amd/amd_postorder.c +206 -0
  60. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  61. data/vendor/scs/linsys/external/amd/amd_preprocess.c +118 -0
  62. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  63. data/vendor/scs/linsys/external/amd/amd_valid.c +92 -0
  64. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  65. data/vendor/scs/linsys/external/amd/changes +11 -0
  66. data/vendor/scs/linsys/external/qdldl/LICENSE +201 -0
  67. data/vendor/scs/linsys/external/qdldl/README.md +120 -0
  68. data/vendor/scs/linsys/external/qdldl/changes +4 -0
  69. data/vendor/scs/linsys/external/qdldl/qdldl.c +298 -0
  70. data/vendor/scs/linsys/external/qdldl/qdldl.h +177 -0
  71. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  72. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +21 -0
  73. data/vendor/scs/linsys/gpu/gpu.c +41 -0
  74. data/vendor/scs/linsys/gpu/gpu.h +85 -0
  75. data/vendor/scs/linsys/gpu/indirect/private.c +304 -0
  76. data/vendor/scs/linsys/gpu/indirect/private.h +36 -0
  77. data/vendor/scs/scs.mk +181 -0
  78. data/vendor/scs/src/aa.c +224 -0
  79. data/vendor/scs/src/aa.o +0 -0
  80. data/vendor/scs/src/cones.c +802 -0
  81. data/vendor/scs/src/cones.o +0 -0
  82. data/vendor/scs/src/ctrlc.c +77 -0
  83. data/vendor/scs/src/ctrlc.o +0 -0
  84. data/vendor/scs/src/linalg.c +84 -0
  85. data/vendor/scs/src/linalg.o +0 -0
  86. data/vendor/scs/src/normalize.c +93 -0
  87. data/vendor/scs/src/normalize.o +0 -0
  88. data/vendor/scs/src/rw.c +167 -0
  89. data/vendor/scs/src/rw.o +0 -0
  90. data/vendor/scs/src/scs.c +978 -0
  91. data/vendor/scs/src/scs.o +0 -0
  92. data/vendor/scs/src/scs_version.c +5 -0
  93. data/vendor/scs/src/scs_version.o +0 -0
  94. data/vendor/scs/src/util.c +196 -0
  95. data/vendor/scs/src/util.o +0 -0
  96. data/vendor/scs/test/data/small_random_socp +0 -0
  97. data/vendor/scs/test/minunit.h +13 -0
  98. data/vendor/scs/test/problem_utils.h +93 -0
  99. data/vendor/scs/test/problems/rob_gauss_cov_est.h +85 -0
  100. data/vendor/scs/test/problems/small_lp.h +50 -0
  101. data/vendor/scs/test/problems/small_random_socp.h +33 -0
  102. data/vendor/scs/test/random_socp_prob.c +171 -0
  103. data/vendor/scs/test/run_from_file.c +69 -0
  104. data/vendor/scs/test/run_tests +2 -0
  105. data/vendor/scs/test/run_tests.c +32 -0
  106. metadata +203 -0
@@ -0,0 +1,16 @@
1
+ /* ========================================================================= */
2
+ /* === amd_global ========================================================== */
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
+ /* In prior versions of AMD, this file declared the amd_malloc, amd_free,
12
+ amd_realloc, amd_calloc, and amd_printf functions. They are now replaced
13
+ by functions defined in SuiteSparse_config/SuiteSparse_config.c.
14
+ */
15
+ /* Simply to suppress empty translation unit warnings. */
16
+ typedef int scs_amd_make_iso_compilers_happy;
@@ -0,0 +1,119 @@
1
+ /* ========================================================================= */
2
+ /* === AMD_info ============================================================ */
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
+ /* User-callable. Prints the output statistics for AMD. See amd.h
12
+ * for details. If the Info array is not present, nothing is printed.
13
+ */
14
+
15
+ #include "amd_internal.h"
16
+
17
+ #define PRI(format,x) { if (x >= 0) { SUITESPARSE_PRINTF ((format, x)) ; }}
18
+
19
+ GLOBAL void AMD_info
20
+ (
21
+ scs_float Info [ ]
22
+ )
23
+ {
24
+ scs_float n, ndiv, nmultsubs_ldl, nmultsubs_lu, lnz, lnzd ;
25
+
26
+ SUITESPARSE_PRINTF (("\nAMD version %d.%d.%d, %s, results:\n",
27
+ AMD_MAIN_VERSION, AMD_SUB_VERSION, AMD_SUBSUB_VERSION, AMD_DATE)) ;
28
+
29
+ if (!Info)
30
+ {
31
+ return ;
32
+ }
33
+
34
+ n = Info [AMD_N] ;
35
+ ndiv = Info [AMD_NDIV] ;
36
+ nmultsubs_ldl = Info [AMD_NMULTSUBS_LDL] ;
37
+ nmultsubs_lu = Info [AMD_NMULTSUBS_LU] ;
38
+ lnz = Info [AMD_LNZ] ;
39
+ lnzd = (n >= 0 && lnz >= 0) ? (n + lnz) : (-1) ;
40
+
41
+ /* AMD return status */
42
+ SUITESPARSE_PRINTF ((" status: ")) ;
43
+ if (Info [AMD_STATUS] == AMD_OK)
44
+ {
45
+ SUITESPARSE_PRINTF (("OK\n")) ;
46
+ }
47
+ else if (Info [AMD_STATUS] == AMD_OUT_OF_MEMORY)
48
+ {
49
+ SUITESPARSE_PRINTF (("out of memory\n")) ;
50
+ }
51
+ else if (Info [AMD_STATUS] == AMD_INVALID)
52
+ {
53
+ SUITESPARSE_PRINTF (("invalid matrix\n")) ;
54
+ }
55
+ else if (Info [AMD_STATUS] == AMD_OK_BUT_JUMBLED)
56
+ {
57
+ SUITESPARSE_PRINTF (("OK, but jumbled\n")) ;
58
+ }
59
+ else
60
+ {
61
+ SUITESPARSE_PRINTF (("unknown\n")) ;
62
+ }
63
+
64
+ /* statistics about the input matrix */
65
+ PRI (" n, dimension of A: %.20g\n", n);
66
+ PRI (" nz, number of nonzeros in A: %.20g\n",
67
+ Info [AMD_NZ]) ;
68
+ PRI (" symmetry of A: %.4f\n",
69
+ Info [AMD_SYMMETRY]) ;
70
+ PRI (" number of nonzeros on diagonal: %.20g\n",
71
+ Info [AMD_NZDIAG]) ;
72
+ PRI (" nonzeros in pattern of A+A' (excl. diagonal): %.20g\n",
73
+ Info [AMD_NZ_A_PLUS_AT]) ;
74
+ PRI (" # dense rows/columns of A+A': %.20g\n",
75
+ Info [AMD_NDENSE]) ;
76
+
77
+ /* statistics about AMD's behavior */
78
+ PRI (" memory used, in bytes: %.20g\n",
79
+ Info [AMD_MEMORY]) ;
80
+ PRI (" # of memory compactions: %.20g\n",
81
+ Info [AMD_NCMPA]) ;
82
+
83
+ /* statistics about the ordering quality */
84
+ SUITESPARSE_PRINTF (("\n"
85
+ " The following approximate statistics are for a subsequent\n"
86
+ " factorization of A(P,P) + A(P,P)'. They are slight upper\n"
87
+ " bounds if there are no dense rows/columns in A+A', and become\n"
88
+ " looser if dense rows/columns exist.\n\n")) ;
89
+
90
+ PRI (" nonzeros in L (excluding diagonal): %.20g\n",
91
+ lnz) ;
92
+ PRI (" nonzeros in L (including diagonal): %.20g\n",
93
+ lnzd) ;
94
+ PRI (" # divide operations for LDL' or LU: %.20g\n",
95
+ ndiv) ;
96
+ PRI (" # multiply-subtract operations for LDL': %.20g\n",
97
+ nmultsubs_ldl) ;
98
+ PRI (" # multiply-subtract operations for LU: %.20g\n",
99
+ nmultsubs_lu) ;
100
+ PRI (" max nz. in any column of L (incl. diagonal): %.20g\n",
101
+ Info [AMD_DMAX]) ;
102
+
103
+ /* total flop counts for various factorizations */
104
+
105
+ if (n >= 0 && ndiv >= 0 && nmultsubs_ldl >= 0 && nmultsubs_lu >= 0)
106
+ {
107
+ SUITESPARSE_PRINTF (("\n"
108
+ " chol flop count for real A, sqrt counted as 1 flop: %.20g\n"
109
+ " LDL' flop count for real A: %.20g\n"
110
+ " LDL' flop count for complex A: %.20g\n"
111
+ " LU flop count for real A (with no pivoting): %.20g\n"
112
+ " LU flop count for complex A (with no pivoting): %.20g\n\n",
113
+ n + ndiv + 2*nmultsubs_ldl,
114
+ ndiv + 2*nmultsubs_ldl,
115
+ 9*ndiv + 8*nmultsubs_ldl,
116
+ ndiv + 2*nmultsubs_lu,
117
+ 9*ndiv + 8*nmultsubs_lu)) ;
118
+ }
119
+ }
@@ -0,0 +1,304 @@
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
+
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 AMD 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 AMD library libamd.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
+ AMD 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
+ /* ANSI include files */
47
+ /* ------------------------------------------------------------------------- */
48
+
49
+ /* from stdlib.h: size_t, malloc, free, realloc, and calloc */
50
+ #include <stdlib.h>
51
+
52
+ #if !defined(NPRINT) || !defined(NDEBUG)
53
+ /* from stdio.h: printf. Not included if NPRINT is defined at compile time.
54
+ * fopen and fscanf are used when debugging. */
55
+ #include <stdio.h>
56
+ #endif
57
+
58
+ /* from limits.h: INT_MAX and LONG_MAX */
59
+ #include <limits.h>
60
+
61
+ /* from math.h: sqrt */
62
+ #include <math.h>
63
+
64
+ /* ------------------------------------------------------------------------- */
65
+ /* MATLAB include files (only if being used in or via MATLAB) */
66
+ /* ------------------------------------------------------------------------- */
67
+
68
+ #ifdef MATLAB_MEX_FILE
69
+ #include "matrix.h"
70
+ #include "mex.h"
71
+ #endif
72
+
73
+ /* ------------------------------------------------------------------------- */
74
+ /* basic definitions */
75
+ /* ------------------------------------------------------------------------- */
76
+
77
+ #ifdef FLIP
78
+ #undef FLIP
79
+ #endif
80
+
81
+ #ifdef MAX
82
+ #undef MAX
83
+ #endif
84
+
85
+ #ifdef MIN
86
+ #undef MIN
87
+ #endif
88
+
89
+ #ifdef EMPTY
90
+ #undef EMPTY
91
+ #endif
92
+
93
+ #ifdef GLOBAL
94
+ #undef GLOBAL
95
+ #endif
96
+
97
+ #ifdef PRIVATE
98
+ #undef PRIVATE
99
+ #endif
100
+
101
+ /* FLIP is a "negation about -1", and is used to mark an integer i that is
102
+ * normally non-negative. FLIP (EMPTY) is EMPTY. FLIP of a number > EMPTY
103
+ * is negative, and FLIP of a number < EMTPY is positive. FLIP (FLIP (i)) = i
104
+ * for all integers i. UNFLIP (i) is >= EMPTY. */
105
+ #define EMPTY (-1)
106
+ #define FLIP(i) (-(i)-2)
107
+ #define UNFLIP(i) ((i < EMPTY) ? FLIP (i) : (i))
108
+
109
+ /* for integer MAX/MIN, or for scs_floats when we don't care how NaN's behave: */
110
+ #define MAX(a,b) (((a) > (b)) ? (a) : (b))
111
+ #define MIN(a,b) (((a) < (b)) ? (a) : (b))
112
+
113
+ /* logical expression of p implies q: */
114
+ #define IMPLIES(p,q) (!(p) || (q))
115
+
116
+ /* Note that the IBM RS 6000 xlc predefines TRUE and FALSE in <types.h>. */
117
+ /* The Compaq Alpha also predefines TRUE and FALSE. */
118
+ #ifdef TRUE
119
+ #undef TRUE
120
+ #endif
121
+ #ifdef FALSE
122
+ #undef FALSE
123
+ #endif
124
+
125
+ #define TRUE (1)
126
+ #define FALSE (0)
127
+ #define PRIVATE static
128
+ #define GLOBAL
129
+ #define EMPTY (-1)
130
+
131
+ /* Note that Linux's gcc 2.96 defines NULL as ((void *) 0), but other */
132
+ /* compilers (even gcc 2.95.2 on Solaris) define NULL as 0 or (0). We */
133
+ /* need to use the ANSI standard value of 0. */
134
+ #ifdef NULL
135
+ #undef NULL
136
+ #endif
137
+
138
+ #define NULL 0
139
+
140
+ /* largest value of size_t */
141
+ #ifndef SIZE_T_MAX
142
+ #ifdef SIZE_MAX
143
+ /* C99 only */
144
+ #define SIZE_T_MAX SIZE_MAX
145
+ #else
146
+ #define SIZE_T_MAX ((size_t) (-1))
147
+ #endif
148
+ #endif
149
+
150
+ /* ------------------------------------------------------------------------- */
151
+ /* integer type for AMD: int or SuiteSparse_long */
152
+ /* ------------------------------------------------------------------------- */
153
+
154
+ #include "amd.h"
155
+
156
+ #include <stdint.h>
157
+
158
+ #define Int scs_int
159
+ #define uInt uint64_t
160
+ #define ID "%d"
161
+ #define Int_MAX INT_MAX
162
+
163
+ #define AMD_order amd_order
164
+ #define AMD_defaults amd_defaults
165
+ #define AMD_control amd_control
166
+ #define AMD_info amd_info
167
+ #define AMD_1 amd_1
168
+ #define AMD_2 amd_2
169
+ #define AMD_valid amd_valid
170
+ #define AMD_aat amd_aat
171
+ #define AMD_postorder amd_postorder
172
+ #define AMD_post_tree amd_post_tree
173
+ #define AMD_dump amd_dump
174
+ #define AMD_debug amd_debug
175
+ #define AMD_debug_init amd_debug_init
176
+ #define AMD_preprocess amd_preprocess
177
+
178
+ /* ------------------------------------------------------------------------- */
179
+ /* AMD routine definitions (not user-callable) */
180
+ /* ------------------------------------------------------------------------- */
181
+
182
+ GLOBAL size_t AMD_aat
183
+ (
184
+ Int n,
185
+ const Int Ap [ ],
186
+ const Int Ai [ ],
187
+ Int Len [ ],
188
+ Int Tp [ ],
189
+ scs_float Info [ ]
190
+ ) ;
191
+
192
+ GLOBAL void AMD_1
193
+ (
194
+ Int n,
195
+ const Int Ap [ ],
196
+ const Int Ai [ ],
197
+ Int P [ ],
198
+ Int Pinv [ ],
199
+ Int Len [ ],
200
+ Int slen,
201
+ Int S [ ],
202
+ scs_float Control [ ],
203
+ scs_float Info [ ]
204
+ ) ;
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
+
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
+
231
+ GLOBAL void AMD_preprocess
232
+ (
233
+ Int n,
234
+ const Int Ap [ ],
235
+ const Int Ai [ ],
236
+ Int Rp [ ],
237
+ Int Ri [ ],
238
+ Int W [ ],
239
+ Int Flag [ ]
240
+ ) ;
241
+
242
+ /* ------------------------------------------------------------------------- */
243
+ /* debugging definitions */
244
+ /* ------------------------------------------------------------------------- */
245
+
246
+ #ifndef NDEBUG
247
+
248
+ /* from assert.h: assert macro */
249
+ #include <assert.h>
250
+
251
+ #ifndef EXTERN
252
+ #define EXTERN extern
253
+ #endif
254
+
255
+ EXTERN Int AMD_debug ;
256
+
257
+ GLOBAL void AMD_debug_init ( char *s ) ;
258
+
259
+ GLOBAL void AMD_dump
260
+ (
261
+ Int n,
262
+ Int Pe [ ],
263
+ Int Iw [ ],
264
+ Int Len [ ],
265
+ Int iwlen,
266
+ Int pfree,
267
+ Int Nv [ ],
268
+ Int Next [ ],
269
+ Int Last [ ],
270
+ Int Head [ ],
271
+ Int Elen [ ],
272
+ Int Degree [ ],
273
+ Int W [ ],
274
+ Int nel
275
+ ) ;
276
+
277
+ #ifdef ASSERT
278
+ #undef ASSERT
279
+ #endif
280
+
281
+ /* Use mxAssert if AMD is compiled into a mexFunction */
282
+ #ifdef MATLAB_MEX_FILE
283
+ #define ASSERT(expression) (mxAssert ((expression), ""))
284
+ #else
285
+ #define ASSERT(expression) (assert (expression))
286
+ #endif
287
+
288
+ #define AMD_DEBUG0(params) { SUITESPARSE_PRINTF (params) ; }
289
+ #define AMD_DEBUG1(params) { if (AMD_debug >= 1) SUITESPARSE_PRINTF (params) ; }
290
+ #define AMD_DEBUG2(params) { if (AMD_debug >= 2) SUITESPARSE_PRINTF (params) ; }
291
+ #define AMD_DEBUG3(params) { if (AMD_debug >= 3) SUITESPARSE_PRINTF (params) ; }
292
+ #define AMD_DEBUG4(params) { if (AMD_debug >= 4) SUITESPARSE_PRINTF (params) ; }
293
+
294
+ #else
295
+
296
+ /* no debugging */
297
+ #define ASSERT(expression)
298
+ #define AMD_DEBUG0(params)
299
+ #define AMD_DEBUG1(params)
300
+ #define AMD_DEBUG2(params)
301
+ #define AMD_DEBUG3(params)
302
+ #define AMD_DEBUG4(params)
303
+
304
+ #endif
@@ -0,0 +1,199 @@
1
+ /* ========================================================================= */
2
+ /* === AMD_order =========================================================== */
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
+ /* User-callable AMD minimum degree ordering routine. See amd.h for
12
+ * documentation.
13
+ */
14
+
15
+ #include "amd_internal.h"
16
+
17
+ /* ========================================================================= */
18
+ /* === AMD_order =========================================================== */
19
+ /* ========================================================================= */
20
+
21
+ GLOBAL Int AMD_order
22
+ (
23
+ Int n,
24
+ const Int Ap [ ],
25
+ const Int Ai [ ],
26
+ Int P [ ],
27
+ scs_float Control [ ],
28
+ scs_float Info [ ]
29
+ )
30
+ {
31
+ Int *Len, *S, nz, i, *Pinv, info, status, *Rp, *Ri, *Cp, *Ci, ok ;
32
+ size_t nzaat, slen ;
33
+ scs_float mem = 0 ;
34
+
35
+ #ifndef NDEBUG
36
+ AMD_debug_init ("amd") ;
37
+ #endif
38
+
39
+ /* clear the Info array, if it exists */
40
+ info = Info != (scs_float *) NULL ;
41
+ if (info)
42
+ {
43
+ for (i = 0 ; i < AMD_INFO ; i++)
44
+ {
45
+ Info [i] = EMPTY ;
46
+ }
47
+ Info [AMD_N] = n ;
48
+ Info [AMD_STATUS] = AMD_OK ;
49
+ }
50
+
51
+ /* make sure inputs exist and n is >= 0 */
52
+ if (Ai == (Int *) NULL || Ap == (Int *) NULL || P == (Int *) NULL || n < 0)
53
+ {
54
+ if (info) Info [AMD_STATUS] = AMD_INVALID ;
55
+ return (AMD_INVALID) ; /* arguments are invalid */
56
+ }
57
+
58
+ if (n == 0)
59
+ {
60
+ return (AMD_OK) ; /* n is 0 so there's nothing to do */
61
+ }
62
+
63
+ nz = Ap [n] ;
64
+ if (info)
65
+ {
66
+ Info [AMD_NZ] = nz ;
67
+ }
68
+ if (nz < 0)
69
+ {
70
+ if (info) Info [AMD_STATUS] = AMD_INVALID ;
71
+ return (AMD_INVALID) ;
72
+ }
73
+
74
+ /* check if n or nz will cause size_t overflow */
75
+ if (((size_t) n) >= SIZE_T_MAX / sizeof (Int)
76
+ || ((size_t) nz) >= SIZE_T_MAX / sizeof (Int))
77
+ {
78
+ if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
79
+ return (AMD_OUT_OF_MEMORY) ; /* problem too large */
80
+ }
81
+
82
+ /* check the input matrix: AMD_OK, AMD_INVALID, or AMD_OK_BUT_JUMBLED */
83
+ status = AMD_valid (n, n, Ap, Ai) ;
84
+
85
+ if (status == AMD_INVALID)
86
+ {
87
+ if (info) Info [AMD_STATUS] = AMD_INVALID ;
88
+ return (AMD_INVALID) ; /* matrix is invalid */
89
+ }
90
+
91
+ /* allocate two size-n integer workspaces */
92
+ Len = SuiteSparse_malloc (n, sizeof (Int)) ;
93
+ Pinv = SuiteSparse_malloc (n, sizeof (Int)) ;
94
+ mem += n ;
95
+ mem += n ;
96
+ if (!Len || !Pinv)
97
+ {
98
+ /* :: out of memory :: */
99
+ SuiteSparse_free (Len) ;
100
+ SuiteSparse_free (Pinv) ;
101
+ if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
102
+ return (AMD_OUT_OF_MEMORY) ;
103
+ }
104
+
105
+ if (status == AMD_OK_BUT_JUMBLED)
106
+ {
107
+ /* sort the input matrix and remove duplicate entries */
108
+ AMD_DEBUG1 (("Matrix is jumbled\n")) ;
109
+ Rp = SuiteSparse_malloc (n+1, sizeof (Int)) ;
110
+ Ri = SuiteSparse_malloc (nz, sizeof (Int)) ;
111
+ mem += (n+1) ;
112
+ mem += MAX (nz,1) ;
113
+ if (!Rp || !Ri)
114
+ {
115
+ /* :: out of memory :: */
116
+ SuiteSparse_free (Rp) ;
117
+ SuiteSparse_free (Ri) ;
118
+ SuiteSparse_free (Len) ;
119
+ SuiteSparse_free (Pinv) ;
120
+ if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
121
+ return (AMD_OUT_OF_MEMORY) ;
122
+ }
123
+ /* use Len and Pinv as workspace to create R = A' */
124
+ AMD_preprocess (n, Ap, Ai, Rp, Ri, Len, Pinv) ;
125
+ Cp = Rp ;
126
+ Ci = Ri ;
127
+ }
128
+ else
129
+ {
130
+ /* order the input matrix as-is. No need to compute R = A' first */
131
+ Rp = NULL ;
132
+ Ri = NULL ;
133
+ Cp = (Int *) Ap ;
134
+ Ci = (Int *) Ai ;
135
+ }
136
+
137
+ /* --------------------------------------------------------------------- */
138
+ /* determine the symmetry and count off-diagonal nonzeros in A+A' */
139
+ /* --------------------------------------------------------------------- */
140
+
141
+ nzaat = AMD_aat (n, Cp, Ci, Len, P, Info) ;
142
+ AMD_DEBUG1 (("nzaat: %g\n", (scs_float) nzaat)) ;
143
+ ASSERT ((MAX (nz-n, 0) <= nzaat) && (nzaat <= 2 * (size_t) nz)) ;
144
+
145
+ /* --------------------------------------------------------------------- */
146
+ /* allocate workspace for matrix, elbow room, and 6 size-n vectors */
147
+ /* --------------------------------------------------------------------- */
148
+
149
+ S = NULL ;
150
+ slen = nzaat ; /* space for matrix */
151
+ ok = ((slen + nzaat/5) >= slen) ; /* check for size_t overflow */
152
+ slen += nzaat/5 ; /* add elbow room */
153
+ for (i = 0 ; ok && i < 7 ; i++)
154
+ {
155
+ ok = ((slen + n) > slen) ; /* check for size_t overflow */
156
+ slen += n ; /* size-n elbow room, 6 size-n work */
157
+ }
158
+ mem += slen ;
159
+ ok = ok && (slen < SIZE_T_MAX / sizeof (Int)) ; /* check for overflow */
160
+ ok = ok && (slen < Int_MAX) ; /* S[i] for Int i must be OK */
161
+ if (ok)
162
+ {
163
+ S = SuiteSparse_malloc (slen, sizeof (Int)) ;
164
+ }
165
+ AMD_DEBUG1 (("slen %g\n", (scs_float) slen)) ;
166
+ if (!S)
167
+ {
168
+ /* :: out of memory :: (or problem too large) */
169
+ SuiteSparse_free (Rp) ;
170
+ SuiteSparse_free (Ri) ;
171
+ SuiteSparse_free (Len) ;
172
+ SuiteSparse_free (Pinv) ;
173
+ if (info) Info [AMD_STATUS] = AMD_OUT_OF_MEMORY ;
174
+ return (AMD_OUT_OF_MEMORY) ;
175
+ }
176
+ if (info)
177
+ {
178
+ /* memory usage, in bytes. */
179
+ Info [AMD_MEMORY] = mem * sizeof (Int) ;
180
+ }
181
+
182
+ /* --------------------------------------------------------------------- */
183
+ /* order the matrix */
184
+ /* --------------------------------------------------------------------- */
185
+
186
+ AMD_1 (n, Cp, Ci, P, Pinv, Len, slen, S, Control, Info) ;
187
+
188
+ /* --------------------------------------------------------------------- */
189
+ /* free the workspace */
190
+ /* --------------------------------------------------------------------- */
191
+
192
+ SuiteSparse_free (Rp) ;
193
+ SuiteSparse_free (Ri) ;
194
+ SuiteSparse_free (Len) ;
195
+ SuiteSparse_free (Pinv) ;
196
+ SuiteSparse_free (S) ;
197
+ if (info) Info [AMD_STATUS] = status ;
198
+ return (status) ; /* successful ordering */
199
+ }