scs 0.5.6 → 0.6.0

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 (95) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE.txt +1 -1
  4. data/lib/scs/ffi.rb +18 -0
  5. data/lib/scs/version.rb +1 -1
  6. data/vendor/scs/CITATION.cff +2 -3
  7. data/vendor/scs/CLAUDE.md +115 -0
  8. data/vendor/scs/CMakeLists.txt +330 -201
  9. data/vendor/scs/CONTRIBUTING.md +49 -0
  10. data/vendor/scs/Makefile +90 -43
  11. data/vendor/scs/README.md +96 -2
  12. data/vendor/scs/include/aa.h +59 -11
  13. data/vendor/scs/include/aa_stats.h +47 -0
  14. data/vendor/scs/include/cones.h +16 -7
  15. data/vendor/scs/include/glbopts.h +113 -26
  16. data/vendor/scs/include/linalg.h +5 -1
  17. data/vendor/scs/include/linsys.h +1 -2
  18. data/vendor/scs/include/normalize.h +6 -2
  19. data/vendor/scs/include/rw.h +9 -3
  20. data/vendor/scs/include/scs.h +17 -1
  21. data/vendor/scs/include/scs_blas.h +8 -0
  22. data/vendor/scs/include/scs_types.h +2 -2
  23. data/vendor/scs/include/scs_work.h +22 -1
  24. data/vendor/scs/include/util.h +3 -6
  25. data/vendor/scs/include/util_spectral_cones.h +3 -3
  26. data/vendor/scs/linsys/accelerate/direct/private.c +126 -0
  27. data/vendor/scs/linsys/accelerate/direct/private.h +34 -0
  28. data/vendor/scs/linsys/cpu/dense/private.c +250 -0
  29. data/vendor/scs/linsys/cpu/dense/private.h +31 -0
  30. data/vendor/scs/linsys/cpu/direct/private.c +86 -44
  31. data/vendor/scs/linsys/cpu/indirect/private.c +647 -113
  32. data/vendor/scs/linsys/cpu/indirect/private.h +28 -0
  33. data/vendor/scs/linsys/csparse.c +9 -3
  34. data/vendor/scs/linsys/csparse.h +4 -2
  35. data/vendor/scs/linsys/cudss/direct/private.c +77 -43
  36. data/vendor/scs/linsys/cudss/direct/private.h +33 -7
  37. data/vendor/scs/linsys/gpu/indirect/private.c +6 -2
  38. data/vendor/scs/linsys/mkl/direct/private.c +63 -31
  39. data/vendor/scs/linsys/mkl/direct/private.h +0 -1
  40. data/vendor/scs/linsys/scs_matrix.c +291 -165
  41. data/vendor/scs/linsys/scs_matrix.h +7 -9
  42. data/vendor/scs/scs.mk +35 -13
  43. data/vendor/scs/src/aa.c +673 -166
  44. data/vendor/scs/src/cones.c +545 -223
  45. data/vendor/scs/src/ctrlc.c +59 -16
  46. data/vendor/scs/src/exp_cone.c +70 -50
  47. data/vendor/scs/src/linalg.c +21 -2
  48. data/vendor/scs/src/normalize.c +24 -26
  49. data/vendor/scs/src/rw.c +596 -124
  50. data/vendor/scs/src/scs.c +990 -513
  51. data/vendor/scs/src/spectral_cones/logdeterminant/log_cone_IPM.c +240 -187
  52. data/vendor/scs/src/spectral_cones/logdeterminant/log_cone_Newton.c +108 -85
  53. data/vendor/scs/src/spectral_cones/logdeterminant/log_cone_wrapper.c +62 -63
  54. data/vendor/scs/src/spectral_cones/logdeterminant/logdet_cone.c +85 -78
  55. data/vendor/scs/src/spectral_cones/nuclear/ell1_cone.c +92 -97
  56. data/vendor/scs/src/spectral_cones/nuclear/nuclear_cone.c +39 -28
  57. data/vendor/scs/src/spectral_cones/sum-largest/sum_largest_cone.c +59 -40
  58. data/vendor/scs/src/spectral_cones/sum-largest/sum_largest_eval_cone.c +37 -29
  59. data/vendor/scs/src/spectral_cones/util_spectral_cones.c +12 -6
  60. data/vendor/scs/src/util.c +37 -7
  61. data/vendor/scs/test/mkl_interface_mismatch.c +97 -0
  62. data/vendor/scs/test/packaging/CMakeLists.txt +21 -0
  63. data/vendor/scs/test/packaging/consume.c +50 -0
  64. data/vendor/scs/test/problem_utils.h +9 -2
  65. data/vendor/scs/test/problems/dense_qp.h +64 -0
  66. data/vendor/scs/test/problems/hs21_tiny_qp.h +6 -2
  67. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +10 -2
  68. data/vendor/scs/test/problems/infeasible_lp.h +66 -0
  69. data/vendor/scs/test/problems/infeasible_socp.h +75 -0
  70. data/vendor/scs/test/problems/lp_update.h +110 -0
  71. data/vendor/scs/test/problems/qafiro_tiny_qp.h +3 -1
  72. data/vendor/scs/test/problems/rob_gauss_cov_est.h +6 -3
  73. data/vendor/scs/test/problems/small_qp.h +5 -0
  74. data/vendor/scs/test/problems/test_box_cone.h +92 -0
  75. data/vendor/scs/test/problems/test_dual_exp_cone.h +96 -0
  76. data/vendor/scs/test/problems/test_inaccurate.h +212 -0
  77. data/vendor/scs/test/problems/test_mixed_cones.h +113 -0
  78. data/vendor/scs/test/problems/test_normalize_roundtrip.h +279 -0
  79. data/vendor/scs/test/problems/test_power_cone.h +414 -0
  80. data/vendor/scs/test/problems/test_psd_metric.h +109 -0
  81. data/vendor/scs/test/problems/test_psd_n1.h +84 -0
  82. data/vendor/scs/test/problems/test_root_plus.h +191 -0
  83. data/vendor/scs/test/problems/test_rw_settings.h +112 -0
  84. data/vendor/scs/test/problems/test_soc_sizes.h +393 -0
  85. data/vendor/scs/test/problems/test_solver_options.h +558 -0
  86. data/vendor/scs/test/problems/test_validation.h +263 -24
  87. data/vendor/scs/test/problems/test_zero_cone.h +81 -0
  88. data/vendor/scs/test/problems/unbounded_lp.h +66 -0
  89. data/vendor/scs/test/problems/unbounded_socp.h +71 -0
  90. data/vendor/scs/test/run_from_file.c +6 -0
  91. data/vendor/scs/test/run_tests.c +71 -0
  92. data/vendor/scs/test/rw_settings.c +7 -0
  93. data/vendor/scs/test/spectral_cones_problems/test_ell1_and_nuc.h +128 -0
  94. data/vendor/scs/test/spectral_cones_problems/test_ell1_cone.h +115 -0
  95. metadata +35 -3
@@ -1,3 +1,12 @@
1
+ /*
2
+ * Global options, default parameter values, and platform-specific macros.
3
+ *
4
+ * Defines printing/memory allocation macros (adapts to MATLAB, Python, R),
5
+ * math precision macros (float vs double), default solver constants, and
6
+ * internal algorithm tuning parameters. This is an internal header; the
7
+ * public API is in scs.h.
8
+ */
9
+
1
10
  #ifndef GLB_H_GUARD
2
11
  #define GLB_H_GUARD
3
12
 
@@ -14,7 +23,7 @@ extern "C" {
14
23
 
15
24
  /* SCS VERSION NUMBER ---------------------------------------------- */
16
25
  /* string literals automatically null-terminated */
17
- #define SCS_VERSION ("3.2.11")
26
+ #define SCS_VERSION ("3.3.1")
18
27
 
19
28
  /* verbosity level */
20
29
  #ifndef VERBOSITY
@@ -34,13 +43,18 @@ extern "C" {
34
43
  #define NORMALIZE (1)
35
44
  #define WARM_START (0)
36
45
  #define ACCELERATION_LOOKBACK (10)
37
- #define ACCELERATION_INTERVAL (10)
46
+ #define ACCELERATION_INTERVAL (5)
38
47
  #define ADAPTIVE_SCALE (1)
48
+ #define ADAPTIVE_DIAG_SCALE (1)
39
49
  #define WRITE_DATA_FILENAME (0)
40
50
  #define LOG_CSV_FILENAME (0)
41
51
  #define TIME_LIMIT_SECS (0.)
42
52
  /* Tolerance to check negativity condition for infeasibility */
43
53
  #define INFEAS_NEGATIVITY_TOL (1e-9)
54
+ /* Number of consecutive residual checks an infeasibility/unboundedness
55
+ * certificate must pass before SCS declares it. Guards against transient
56
+ * iterates (e.g. from acceleration) that momentarily pass a one-shot test. */
57
+ #define CERT_PERSISTENCE_CHECKS (2)
44
58
  /* redefine printfs as needed */
45
59
  #if NO_PRINTING > 0 /* Disable all printing */
46
60
  #define scs_printf(...) /* No-op */
@@ -74,10 +88,27 @@ extern "C" {
74
88
  /* redefine memory allocators as needed */
75
89
  #ifdef MATLAB_MEX_FILE
76
90
  #include "mex.h"
91
+ /* Use mexMakeMemoryPersistent so allocations survive across MEX calls.
92
+ * Required for the workspace API (scs_init/scs_solve/scs_finish). */
93
+ static inline void *_scs_mex_malloc(size_t n) {
94
+ void *p = mxMalloc(n);
95
+ if (p) mexMakeMemoryPersistent(p);
96
+ return p;
97
+ }
98
+ static inline void *_scs_mex_calloc(size_t count, size_t size) {
99
+ void *p = mxCalloc(count, size);
100
+ if (p) mexMakeMemoryPersistent(p);
101
+ return p;
102
+ }
103
+ static inline void *_scs_mex_realloc(void *ptr, size_t n) {
104
+ void *p = mxRealloc(ptr, n);
105
+ if (p) mexMakeMemoryPersistent(p);
106
+ return p;
107
+ }
77
108
  #define scs_free mxFree
78
- #define scs_malloc mxMalloc
79
- #define scs_calloc mxCalloc
80
- #define scs_realloc mxRealloc
109
+ #define scs_malloc _scs_mex_malloc
110
+ #define scs_calloc _scs_mex_calloc
111
+ #define scs_realloc _scs_mex_realloc
81
112
  #elif defined PYTHON
82
113
  #include <Python.h>
83
114
  #if PY_MAJOR_VERSION >= 3
@@ -113,17 +144,17 @@ static inline void *scs_calloc(size_t count, size_t size) {
113
144
 
114
145
  #ifndef SFLOAT
115
146
  #ifndef NAN
116
- #define NAN ((scs_float)0x7ff8000000000000)
147
+ #define NAN (HUGE_VAL - HUGE_VAL)
117
148
  #endif
118
149
  #ifndef INFINITY
119
- #define INFINITY NAN
150
+ #define INFINITY HUGE_VAL
120
151
  #endif
121
152
  #else
122
153
  #ifndef NAN
123
- #define NAN ((float)0x7fc00000)
154
+ #define NAN ((float)(HUGE_VAL - HUGE_VAL))
124
155
  #endif
125
156
  #ifndef INFINITY
126
- #define INFINITY NAN
157
+ #define INFINITY ((float)HUGE_VAL)
127
158
  #endif
128
159
  #endif
129
160
 
@@ -155,12 +186,14 @@ static inline void *scs_calloc(size_t count, size_t size) {
155
186
  #define IABS abs
156
187
  #endif
157
188
 
158
- /* Force SCS to treat the problem as (non-homogeneous) feasible for this many */
159
- /* iters. This acts like a warm-start that biases towards feasibility, which */
160
- /* is the most common use-case */
189
+ /* Force SCS to treat the problem as (non-homogeneous) feasible for this many
190
+ * iterations. Acts like an implicit warm-start biased towards feasibility,
191
+ * which is the most common use-case. During these iterations tau is fixed
192
+ * at 1 and kappa is fixed at 0. */
161
193
  #define FEASIBLE_ITERS (1)
162
194
 
163
- /* how many iterations between heuristic residual rescaling */
195
+ /* Minimum iterations between heuristic scale updates. Prevents scale
196
+ * from changing too frequently before the iterates have stabilized. */
164
197
  #define RESCALING_MIN_ITERS (100)
165
198
 
166
199
  #define _DIV_EPS_TOL (1E-18)
@@ -185,38 +218,92 @@ static inline void *scs_calloc(size_t count, size_t size) {
185
218
  /* #define NORM SCS(norm_2) */
186
219
  #define NORM SCS(norm_inf)
187
220
 
188
- /* Factor which is scales tau in the linear system update */
189
- /* Larger factors prevent tau from moving as much */
221
+ /* Factor which scales the tau diagonal entry in the linear system.
222
+ * Larger values stabilize tau but slow convergence. 10 is a good balance
223
+ * for most problems. */
190
224
  #define TAU_FACTOR (10.)
191
225
 
192
- /* Anderson acceleration parameters: */
226
+ /* --- Anderson Acceleration (AA) parameters --- */
227
+ /* Default AA type: 1 = type-I (better empirical performance, default),
228
+ * 0 = type-II (more numerically stable but typically slower). */
229
+ #define ACCELERATION_TYPE_1 (1)
230
+ /* Default Tikhonov regularization for the AA least-squares solve. Tuned
231
+ * for type-I; type-II tolerates much smaller (e.g. 1e-12). Users picking
232
+ * type-II will typically lower this. */
233
+ #define AA_REGULARIZATION (1e-8)
193
234
  #define AA_RELAXATION (1.0)
194
- #define AA_REGULARIZATION_TYPE_1 (1e-6)
195
- #define AA_REGULARIZATION_TYPE_2 (1e-10)
196
- /* Safeguarding norm factor at which we reject AA steps */
235
+ /* Reject AA steps when the output norm exceeds this multiple of the input
236
+ * norm. 1.0 means the AA step must not increase the iterate norm. */
197
237
  #define AA_SAFEGUARD_FACTOR (1.)
198
- /* Max allowable AA weight norm */
238
+ /* Reject AA steps whose weight vector exceeds this norm (prevents
239
+ * numerically unstable extrapolation). */
199
240
  #define AA_MAX_WEIGHT_NORM (1e10)
241
+ /* Max iterative-refinement passes on the γ solve. 0 disables IR; the loop
242
+ * auto-stops once the correction no longer contracts, so this is an upper
243
+ * bound rather than a fixed iteration count. */
244
+ #define AA_IR_MAX_STEPS (5)
200
245
 
201
246
  /* (Dual) Scale updating parameters */
202
247
  #define MAX_SCALE_VALUE (1e6)
203
248
  #define MIN_SCALE_VALUE (1e-6)
204
249
  #define SCALE_NORM NORM /* what norm to use when computing the scale factor */
205
250
 
206
- /* CG == Conjugate gradient */
207
- /* Linear system tolerances, only used with indirect */
251
+ /* Dynamic diagonal rescaling (stgs->adaptive_diag_scale). Row multipliers
252
+ * move by at most (profile ratio)^DIAG_SCALE_DAMP per update and live in
253
+ * [DIAG_SCALE_MULT_MIN, DIAG_SCALE_MULT_MAX] around the scalar scale. An
254
+ * update fires when the scalar scale updates, or when some damped
255
+ * *clamped* step alone exceeds sqrt(10) (a railed scalar must not freeze
256
+ * the diagonal; a railed multiplier must not keep triggering updates it
257
+ * cannot take). */
258
+ #define DIAG_SCALE_DAMP (0.25)
259
+ #define DIAG_SCALE_MULT_MIN (1e-3)
260
+ #define DIAG_SCALE_MULT_MAX (1e3)
261
+ /* Floor on the row-profile denominators, as a fraction of the block's
262
+ * rms denominator (see row_rel_res). Swept over 1e-4..1e-1: every value
263
+ * improves on no floor, 1e-3 is the best on solve count. */
264
+ #define DEN_FLOOR_FRAC (1e-3)
265
+
266
+ /* --- Conjugate gradient (CG) parameters, only used with indirect solver --- */
208
267
  #define CG_BEST_TOL (1e-12)
209
- /* This scales the current residuals to get the tolerance we solve the
210
- * linear system to at each iteration. Lower factors require more CG steps
211
- * but give better accuracy */
268
+ /* Each CG solve targets tol = CG_TOL_FACTOR * current_residual. Smaller
269
+ * values give more accurate CG solves at the cost of more CG iterations.
270
+ * With deflation making inner accuracy cheap, 0.03 measured optimal on a
271
+ * netlib / Maros-Meszaros / SOC suite (bracketed on both sides: 0.02
272
+ * starts flipping problems, 0.01 pays more CG for no outer-iteration
273
+ * gain); together with CG_RATE 2.0 it buys roughly 30% fewer outer
274
+ * iterations for roughly 8% more matvecs, which is wall-clock neutral
275
+ * on matvec-dominated problems and favorable on cone-dominated ones.
276
+ * The retuned values target accuracies below the single-precision noise
277
+ * floor, so single-precision builds keep the previous calibration. */
278
+ #ifdef SFLOAT
212
279
  #define CG_TOL_FACTOR (0.2)
280
+ #else
281
+ #define CG_TOL_FACTOR (0.03)
282
+ #endif
213
283
 
214
284
  /* norm to use when deciding CG convergence */
215
285
  #ifndef CG_NORM
216
286
  #define CG_NORM SCS(norm_inf)
217
287
  #endif
218
- /* cg tol ~ O(1/k^(CG_RATE)) */
288
+ /* cg tol ~ O(1/k^(CG_RATE)); forcing accuracy faster with the iteration
289
+ * count is consumed by the outer loop (Anderson acceleration
290
+ * especially) as fewer iterations. 2.0 is safely interior: 2.25 starts
291
+ * flipping problems. Single precision keeps the previous rate for the
292
+ * same reason as CG_TOL_FACTOR above. */
293
+ #ifdef SFLOAT
219
294
  #define CG_RATE (1.5)
295
+ #else
296
+ #define CG_RATE (2.0)
297
+ #endif
298
+ /* Number of approximate small eigenvectors of the preconditioned
299
+ * reduced operator harvested from each cold solve for g = K^{-1}h and
300
+ * used to deflate the warm solves until the next metric change (eigCG,
301
+ * Stathopoulos & Orginos 2010). Costs 2 * DEFLATE_VECTORS * n floats
302
+ * persistent plus a transient Lanczos window during the deep solve;
303
+ * needs USE_LAPACK and is compiled out without it. 0 disables. The
304
+ * environment variables SCS_DEFLATE and SCS_EIGCG_WIN override the
305
+ * count and the window size at runtime. */
306
+ #define DEFLATE_VECTORS (30)
220
307
 
221
308
  #ifdef __cplusplus
222
309
  }
@@ -1,3 +1,8 @@
1
+ /*
2
+ * Basic dense linear algebra operations used throughout SCS.
3
+ * All operate on raw arrays of scs_float.
4
+ */
5
+
1
6
  #ifndef LINALG_H_GUARD
2
7
  #define LINALG_H_GUARD
3
8
 
@@ -6,7 +11,6 @@ extern "C" {
6
11
  #endif
7
12
 
8
13
  #include "glbopts.h"
9
- #include <math.h>
10
14
 
11
15
  void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len);
12
16
  scs_float SCS(dot)(const scs_float *x, const scs_float *y, scs_int len);
@@ -6,7 +6,6 @@ extern "C" {
6
6
  #endif
7
7
 
8
8
  #include "glbopts.h"
9
- #include "scs.h"
10
9
 
11
10
  /* This is the API that any new linear system solver must implement */
12
11
 
@@ -62,7 +61,7 @@ scs_int scs_solve_lin_sys(ScsLinSysWork *w, scs_float *b, const scs_float *s,
62
61
  * @param new_diag_r Updated `diag_r`, diagonal entries of R.
63
62
  *
64
63
  */
65
- void scs_update_lin_sys_diag_r(ScsLinSysWork *w, const scs_float *new_diag_r);
64
+ scs_int scs_update_lin_sys_diag_r(ScsLinSysWork *w, const scs_float *new_diag_r);
66
65
 
67
66
  /**
68
67
  * Name of the linear solver.
@@ -1,3 +1,9 @@
1
+ /*
2
+ * Problem data normalization (equilibration) routines.
3
+ * Applied before solving to improve numerical conditioning; undone
4
+ * after solving to return the solution in the original scale.
5
+ */
6
+
1
7
  #ifndef NORMALIZE_H_GUARD
2
8
  #define NORMALIZE_H_GUARD
3
9
 
@@ -11,8 +17,6 @@ extern "C" {
11
17
  void SCS(normalize_b_c)(ScsScaling *scal, scs_float *b, scs_float *c);
12
18
  void SCS(normalize_sol)(ScsScaling *scal, ScsSolution *sol);
13
19
  void SCS(un_normalize_sol)(ScsScaling *scal, ScsSolution *sol);
14
- void SCS(un_normalize_primal)(ScsScaling *scal, scs_float *r);
15
- void SCS(un_normalize_dual)(ScsScaling *scal, scs_float *r);
16
20
 
17
21
  #ifdef __cplusplus
18
22
  }
@@ -1,3 +1,9 @@
1
+ /*
2
+ * Read/write utilities for serializing SCS problem data to binary files
3
+ * and logging solve progress to CSV. Disabled when compiled with
4
+ * NO_READ_WRITE=1.
5
+ */
6
+
1
7
  #ifndef RW_H_GUARD
2
8
  #define RW_H_GUARD
3
9
 
@@ -6,15 +12,15 @@ extern "C" {
6
12
  #endif
7
13
 
8
14
  #include "glbopts.h"
9
- #include "scs.h"
10
15
  #include "util.h"
11
16
 
12
17
  void SCS(write_data)(const ScsData *d, const ScsCone *k,
13
18
  const ScsSettings *stgs);
14
19
  scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k,
15
20
  ScsSettings **stgs);
16
- void SCS(log_data_to_csv)(const ScsCone *k, const ScsSettings *stgs,
17
- const ScsWork *w, scs_int iter,
21
+ scs_int SCS(open_csv_log_file)(ScsWork *w);
22
+ void SCS(close_csv_log_file)(ScsWork *w);
23
+ void SCS(log_data_to_csv)(const ScsCone *k, const ScsWork *w, scs_int iter,
18
24
  SCS(timer) * solve_timer);
19
25
 
20
26
  #ifdef __cplusplus
@@ -14,6 +14,7 @@ extern "C" {
14
14
 
15
15
  /* Contains definitions of primitive types `scs_int` and `scs_float`. */
16
16
  #include "scs_types.h"
17
+ #include "aa_stats.h"
17
18
 
18
19
  #define SCS_NULL 0 /* NULL type */
19
20
 
@@ -64,6 +65,12 @@ typedef struct {
64
65
  scs_float scale;
65
66
  /** Whether to adaptively update `scale`. */
66
67
  scs_int adaptive_scale;
68
+ /** Dynamic diagonal rescaling from residual profiles: 0 = off,
69
+ * 1 = per-row (rescales the R_y diagonal from the row-wise primal
70
+ * residual profile; uniform within non-polyhedral cone blocks; the
71
+ * default). Requires `adaptive_scale` (silently disabled without
72
+ * it). */
73
+ scs_int adaptive_diag_scale;
67
74
  /** Primal constraint scaling factor. */
68
75
  scs_float rho_x;
69
76
  /** Maximum iterations to take. */
@@ -82,10 +89,17 @@ typedef struct {
82
89
  scs_int verbose;
83
90
  /** Whether to use warm start (put initial guess in ScsSolution struct). */
84
91
  scs_int warm_start;
85
- /** Memory for acceleration. */
92
+ /** Memory for acceleration. Set to 0 to disable AA. Must be nonnegative. */
86
93
  scs_int acceleration_lookback;
87
94
  /** Interval to apply acceleration. */
88
95
  scs_int acceleration_interval;
96
+ /** Whether AA uses type-I (1) or type-II (0). */
97
+ scs_int acceleration_type_1;
98
+ /** Tikhonov regularization for the AA least-squares solve.
99
+ * See `aa_init` in include/aa.h for the sign-encoded modes. */
100
+ scs_float acceleration_regularization;
101
+ /** AA relaxation factor in [0, 2]. 1.0 recovers vanilla AA. */
102
+ scs_float acceleration_relaxation;
89
103
  /** String, if set will dump raw prob data to this file. */
90
104
  const char *write_data_filename;
91
105
  /** String, if set will log data to this csv file (makes SCS very slow). */
@@ -218,6 +232,8 @@ typedef struct {
218
232
  scs_int rejected_accel_steps;
219
233
  /** Number of accepted AA steps. */
220
234
  scs_int accepted_accel_steps;
235
+ /** Detailed Anderson acceleration diagnostics. */
236
+ AaStats aa_stats;
221
237
  /** Total time (milliseconds) spent in the linear system solver. */
222
238
  scs_float lin_sys_time;
223
239
  /** Total time (milliseconds) spent in the cone projection. */
@@ -1,3 +1,10 @@
1
+ /*
2
+ * BLAS/LAPACK function name mangling macros.
3
+ * Handles single/double precision prefixes (s/d) and platform-specific
4
+ * suffixes (underscore, no suffix, etc.) for linking against various
5
+ * BLAS libraries. Only active when USE_LAPACK is defined.
6
+ */
7
+
1
8
  #ifndef SCS_BLAS_H_GUARD
2
9
  #define SCS_BLAS_H_GUARD
3
10
 
@@ -42,6 +49,7 @@ extern "C" {
42
49
  #endif
43
50
 
44
51
  #ifdef MATLAB_MEX_FILE
52
+ #include <stddef.h> /* ptrdiff_t */
45
53
  typedef ptrdiff_t blas_int;
46
54
  #elif defined BLAS64
47
55
  #include <stdint.h>
@@ -26,10 +26,10 @@ typedef int scs_int;
26
26
 
27
27
  #ifndef SFLOAT
28
28
  typedef double scs_float;
29
- typedef double scs_complex_float[2]; // [real, imaginary]
29
+ typedef double scs_complex_float[2]; /* [real, imaginary] */
30
30
  #else
31
31
  typedef float scs_float;
32
- typedef float scs_complex_float[2]; // [real, imaginary]
32
+ typedef float scs_complex_float[2]; /* [real, imaginary] */
33
33
  #endif
34
34
 
35
35
  #ifdef __cplusplus
@@ -1,10 +1,19 @@
1
1
  /*
2
- * Define ScsWork and related internal-only structs (not part of external API).
2
+ * Internal workspace structs used during the solve.
3
+ *
4
+ * ScsWork holds all mutable state for one solve: ADMM iterates, residuals,
5
+ * normalization data, and pointers to the linear system and cone workspaces.
6
+ * ScsScaling holds the diagonal matrices from Ruiz equilibration.
7
+ * ScsResiduals tracks primal/dual residuals and infeasibility certificates.
8
+ *
9
+ * These are internal to SCS -- the public API is in scs.h.
3
10
  */
4
11
 
5
12
  #ifndef SCS_WORK_H_GUARD
6
13
  #define SCS_WORK_H_GUARD
7
14
 
15
+ #include <stdio.h>
16
+
8
17
  #ifdef __cplusplus
9
18
  extern "C" {
10
19
  #endif
@@ -17,6 +26,9 @@ typedef struct {
17
26
  scs_int m; /* Length of D */
18
27
  scs_int n; /* Length of E */
19
28
  scs_float primal_scale, dual_scale;
29
+ /* accumulated tau-slot scaling from the stacked-operator equilibration;
30
+ * becomes the sigma applied to b, c in normalize_b_c */
31
+ scs_float tau_scale;
20
32
  } ScsScaling;
21
33
 
22
34
  /** Holds residual information. */
@@ -56,10 +68,14 @@ struct SCS_WORK {
56
68
  scs_float *diag_r; /* vector of R matrix diagonals (affects cone proj) */
57
69
  scs_float *b_orig, *c_orig; /* original unnormalized b and c vectors */
58
70
  scs_float nm_b_orig, nm_c_orig; /* unnormalized NORM(b), NORM(c) */
71
+ scs_float nm_a_orig; /* unnormalized max abs entry of A */
72
+ /* consecutive checks the infeas/unbdd certificate has passed */
73
+ scs_int infeas_cert_streak, unbdd_cert_streak;
59
74
  AaWork *accel; /* struct for acceleration workspace */
60
75
  ScsData *d; /* Problem data deep copy NORMALIZED */
61
76
  ScsCone *k; /* Problem cone deep copy */
62
77
  ScsSettings *stgs; /* contains solver settings specified by user */
78
+ FILE *log_csv_fout; /* open CSV log stream for current solve */
63
79
  ScsLinSysWork *p; /* struct populated by linear system solver */
64
80
  ScsScaling *scal; /* contains the re-scaling data */
65
81
  ScsConeWork *cone_work; /* workspace for the cone projection step */
@@ -70,6 +86,11 @@ struct SCS_WORK {
70
86
  /* Scale updating workspace */
71
87
  scs_float sum_log_scale_factor;
72
88
  scs_int last_scale_update_iter, n_log_scale_factor, scale_updates;
89
+ /* per-row scale multipliers on R_y, size m (adaptive_diag_scale >= 1) */
90
+ scs_float *scale_mults;
91
+ /* floor on the row-profile denominators, see row_rel_res */
92
+ scs_float den_floor;
93
+ /* per-column multipliers on rho_x, size n (adaptive_diag_scale >= 2) */
73
94
  /* AA stats */
74
95
  scs_float aa_norm;
75
96
  scs_int rejected_accel_steps, accepted_accel_steps;
@@ -5,11 +5,8 @@
5
5
  extern "C" {
6
6
  #endif
7
7
 
8
- #include "cones.h"
9
8
  #include "scs.h"
10
- #include <stdio.h>
11
- #include <stdlib.h>
12
- #include <string.h>
9
+ #include "glbopts.h"
13
10
 
14
11
  /* timing code courtesy of A. Domahidi */
15
12
  #if (defined NO_TIMER)
@@ -46,8 +43,8 @@ typedef struct SCS(timer) {
46
43
  void SCS(tic)(SCS(timer) * t);
47
44
  scs_float SCS(tocq)(SCS(timer) * t);
48
45
  void SCS(free_sol)(ScsSolution *sol);
49
- void SCS(deep_copy_data)(ScsData *dest, const ScsData *src);
50
- void SCS(deep_copy_stgs)(ScsSettings *dest, const ScsSettings *src);
46
+ scs_int SCS(deep_copy_data)(ScsData *dest, const ScsData *src);
47
+ scs_int SCS(deep_copy_stgs)(ScsSettings *dest, const ScsSettings *src);
51
48
  void SCS(free_data)(ScsData *d);
52
49
 
53
50
  #ifdef __cplusplus
@@ -23,7 +23,7 @@ void non_neg_proj(const scs_float *src, scs_float *dst, scs_int n);
23
23
  scs_float sum_log(const scs_float *x, scs_int n);
24
24
  scs_float min_vec(const scs_float *vec, scs_int n);
25
25
 
26
- // used for sorting in ell1-norm cone and sum of largest cone.
26
+ /* used for sorting in ell1-norm cone and sum of largest cone. */
27
27
  typedef struct {
28
28
  scs_float value;
29
29
  int index;
@@ -32,10 +32,10 @@ typedef struct {
32
32
  typedef struct {
33
33
  int iter;
34
34
 
35
- // if plain Newton computed the projection or if an IPM was used
35
+ /* if plain Newton computed the projection or if an IPM was used */
36
36
  int newton_success;
37
37
 
38
- // dual_res, pri_res, complementarity for the projection problem
38
+ /* dual_res, pri_res, complementarity for the projection problem */
39
39
  scs_float residuals[3];
40
40
  } Newton_stats;
41
41
 
@@ -0,0 +1,126 @@
1
+ #include "private.h"
2
+
3
+ #ifdef DLONG
4
+ #error "Apple Accelerate backend does not support DLONG (64-bit integers)"
5
+ #endif
6
+
7
+ const char *scs_get_lin_sys_method(void) {
8
+ return "sparse-direct-apple-accelerate";
9
+ }
10
+
11
+ ScsLinSysWork *scs_init_lin_sys_work(const ScsMatrix *A, const ScsMatrix *P,
12
+ const scs_float *diag_r) {
13
+ scs_int i, n_plus_m;
14
+ ScsLinSysWork *p = (ScsLinSysWork *)scs_calloc(1, sizeof(ScsLinSysWork));
15
+ if (!p) {
16
+ return SCS_NULL;
17
+ }
18
+
19
+ n_plus_m = A->n + A->m;
20
+ p->m = A->m;
21
+ p->n = A->n;
22
+
23
+ p->diag_p = (scs_float *)scs_calloc(A->n, sizeof(scs_float));
24
+ p->diag_r_idxs = (scs_int *)scs_calloc(n_plus_m, sizeof(scs_int));
25
+ if (!p->diag_p || !p->diag_r_idxs) {
26
+ scs_free_lin_sys_work(p);
27
+ return SCS_NULL;
28
+ }
29
+
30
+ /* Form upper triangular KKT matrix in CSC format */
31
+ p->kkt = SCS(form_kkt)(A, P, p->diag_p, diag_r, p->diag_r_idxs, 1);
32
+ if (!p->kkt) {
33
+ scs_printf("Error in forming KKT matrix.\n");
34
+ scs_free_lin_sys_work(p);
35
+ return SCS_NULL;
36
+ }
37
+
38
+ /* Convert column starts from scs_int (int) to long for Accelerate API */
39
+ p->col_starts = (long *)scs_calloc(n_plus_m + 1, sizeof(long));
40
+ if (!p->col_starts) {
41
+ scs_free_lin_sys_work(p);
42
+ return SCS_NULL;
43
+ }
44
+ for (i = 0; i <= n_plus_m; i++) {
45
+ p->col_starts[i] = (long)p->kkt->p[i];
46
+ }
47
+
48
+ /* Set up Accelerate sparse matrix wrapper pointing to KKT data */
49
+ #ifdef SFLOAT
50
+ p->accel_mat = (SparseMatrix_Float){
51
+ #else
52
+ p->accel_mat = (SparseMatrix_Double){
53
+ #endif
54
+ .structure = {.rowCount = n_plus_m,
55
+ .columnCount = n_plus_m,
56
+ .columnStarts = p->col_starts,
57
+ .rowIndices = p->kkt->i,
58
+ .attributes =
59
+ {
60
+ .kind = SparseSymmetric,
61
+ .triangle = SparseUpperTriangle,
62
+ },
63
+ .blockSize = 1},
64
+ .data = p->kkt->x};
65
+
66
+ /* Perform symbolic and numeric factorization */
67
+ p->factorization =
68
+ SparseFactor(SparseFactorizationLDLTUnpivoted, p->accel_mat);
69
+ if (p->factorization.status != SparseStatusOK) {
70
+ scs_printf("Error in Apple Accelerate LDLt factorization: %d\n",
71
+ (int)p->factorization.status);
72
+ SparseCleanup(p->factorization);
73
+ scs_free_lin_sys_work(p);
74
+ return SCS_NULL;
75
+ }
76
+ p->factorizations++;
77
+
78
+ return p;
79
+ }
80
+
81
+ scs_int scs_solve_lin_sys(ScsLinSysWork *p, scs_float *b, const scs_float *s,
82
+ scs_float tol) {
83
+ scs_int n_plus_m = p->n + p->m;
84
+ #ifdef SFLOAT
85
+ DenseVector_Float bvec = {.count = n_plus_m, .data = b};
86
+ #else
87
+ DenseVector_Double bvec = {.count = n_plus_m, .data = b};
88
+ #endif
89
+ SparseSolve(p->factorization, bvec);
90
+ return 0;
91
+ }
92
+
93
+ scs_int scs_update_lin_sys_diag_r(ScsLinSysWork *p, const scs_float *diag_r) {
94
+ scs_int i;
95
+ for (i = 0; i < p->n; ++i) {
96
+ /* top left is R_x + P, bottom right is -R_y */
97
+ p->kkt->x[p->diag_r_idxs[i]] = p->diag_p[i] + diag_r[i];
98
+ }
99
+ for (i = p->n; i < p->n + p->m; ++i) {
100
+ /* top left is R_x + P, bottom right is -R_y */
101
+ p->kkt->x[p->diag_r_idxs[i]] = -diag_r[i];
102
+ }
103
+
104
+ /* Refactor with updated values (reuses symbolic factorization) */
105
+ SparseRefactor(p->accel_mat, &(p->factorization));
106
+ if (p->factorization.status != SparseStatusOK) {
107
+ scs_printf("Error in Apple Accelerate LDLt refactorization: %d\n",
108
+ (int)p->factorization.status);
109
+ return -1;
110
+ }
111
+ p->factorizations++;
112
+ return 0;
113
+ }
114
+
115
+ void scs_free_lin_sys_work(ScsLinSysWork *p) {
116
+ if (p) {
117
+ if (p->factorizations > 0) {
118
+ SparseCleanup(p->factorization);
119
+ }
120
+ SCS(cs_spfree)(p->kkt);
121
+ scs_free(p->diag_p);
122
+ scs_free(p->diag_r_idxs);
123
+ scs_free(p->col_starts);
124
+ scs_free(p);
125
+ }
126
+ }
@@ -0,0 +1,34 @@
1
+ #ifndef PRIV_H_GUARD
2
+ #define PRIV_H_GUARD
3
+
4
+ #include <Accelerate/Accelerate.h>
5
+
6
+ #ifdef __cplusplus
7
+ extern "C" {
8
+ #endif
9
+
10
+ #include "csparse.h"
11
+ #include "glbopts.h"
12
+ #include "linsys.h"
13
+ #include "scs_matrix.h"
14
+
15
+ struct SCS_LIN_SYS_WORK {
16
+ scs_int m, n;
17
+ ScsMatrix *kkt; /* Upper triangular KKT matrix (CSC format) */
18
+ scs_int *diag_r_idxs; /* Indices where R appears in kkt->x */
19
+ scs_float *diag_p; /* Diagonal values of P */
20
+ long *col_starts; /* Column starts converted to long for Accelerate */
21
+ #ifdef SFLOAT
22
+ SparseMatrix_Float accel_mat;
23
+ SparseOpaqueFactorization_Float factorization;
24
+ #else
25
+ SparseMatrix_Double accel_mat;
26
+ SparseOpaqueFactorization_Double factorization;
27
+ #endif
28
+ scs_int factorizations; /* Number of successful factorizations */
29
+ };
30
+
31
+ #ifdef __cplusplus
32
+ }
33
+ #endif
34
+ #endif