scs 0.2.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.
- checksums.yaml +7 -0
- data/CHANGELOG.md +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +84 -0
- data/ext/scs/Rakefile +11 -0
- data/lib/scs/ffi.rb +117 -0
- data/lib/scs/solver.rb +178 -0
- data/lib/scs/version.rb +3 -0
- data/lib/scs.rb +17 -0
- data/vendor/scs/LICENSE.txt +21 -0
- data/vendor/scs/Makefile +164 -0
- data/vendor/scs/README.md +220 -0
- data/vendor/scs/include/aa.h +56 -0
- data/vendor/scs/include/cones.h +46 -0
- data/vendor/scs/include/ctrlc.h +33 -0
- data/vendor/scs/include/glbopts.h +177 -0
- data/vendor/scs/include/linalg.h +26 -0
- data/vendor/scs/include/linsys.h +64 -0
- data/vendor/scs/include/normalize.h +18 -0
- data/vendor/scs/include/rw.h +17 -0
- data/vendor/scs/include/scs.h +161 -0
- data/vendor/scs/include/scs_blas.h +51 -0
- data/vendor/scs/include/util.h +65 -0
- data/vendor/scs/linsys/amatrix.c +305 -0
- data/vendor/scs/linsys/amatrix.h +36 -0
- data/vendor/scs/linsys/amatrix.o +0 -0
- data/vendor/scs/linsys/cpu/direct/private.c +366 -0
- data/vendor/scs/linsys/cpu/direct/private.h +26 -0
- data/vendor/scs/linsys/cpu/direct/private.o +0 -0
- data/vendor/scs/linsys/cpu/indirect/private.c +256 -0
- data/vendor/scs/linsys/cpu/indirect/private.h +31 -0
- data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
- data/vendor/scs/linsys/external/amd/LICENSE.txt +934 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +469 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.h +254 -0
- data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
- data/vendor/scs/linsys/external/amd/amd.h +400 -0
- data/vendor/scs/linsys/external/amd/amd_1.c +180 -0
- data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_2.c +1842 -0
- data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_aat.c +184 -0
- data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_control.c +64 -0
- data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_defaults.c +37 -0
- data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_dump.c +179 -0
- data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_global.c +16 -0
- data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_info.c +119 -0
- data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_internal.h +304 -0
- data/vendor/scs/linsys/external/amd/amd_order.c +199 -0
- data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_post_tree.c +120 -0
- data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_postorder.c +206 -0
- data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_preprocess.c +118 -0
- data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
- data/vendor/scs/linsys/external/amd/amd_valid.c +92 -0
- data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
- data/vendor/scs/linsys/external/amd/changes +11 -0
- data/vendor/scs/linsys/external/qdldl/LICENSE +201 -0
- data/vendor/scs/linsys/external/qdldl/README.md +120 -0
- data/vendor/scs/linsys/external/qdldl/changes +4 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.c +298 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.h +177 -0
- data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
- data/vendor/scs/linsys/external/qdldl/qdldl_types.h +21 -0
- data/vendor/scs/linsys/gpu/gpu.c +41 -0
- data/vendor/scs/linsys/gpu/gpu.h +85 -0
- data/vendor/scs/linsys/gpu/indirect/private.c +304 -0
- data/vendor/scs/linsys/gpu/indirect/private.h +36 -0
- data/vendor/scs/scs.mk +181 -0
- data/vendor/scs/src/aa.c +224 -0
- data/vendor/scs/src/aa.o +0 -0
- data/vendor/scs/src/cones.c +802 -0
- data/vendor/scs/src/cones.o +0 -0
- data/vendor/scs/src/ctrlc.c +77 -0
- data/vendor/scs/src/ctrlc.o +0 -0
- data/vendor/scs/src/linalg.c +84 -0
- data/vendor/scs/src/linalg.o +0 -0
- data/vendor/scs/src/normalize.c +93 -0
- data/vendor/scs/src/normalize.o +0 -0
- data/vendor/scs/src/rw.c +167 -0
- data/vendor/scs/src/rw.o +0 -0
- data/vendor/scs/src/scs.c +975 -0
- data/vendor/scs/src/scs.o +0 -0
- data/vendor/scs/src/scs_version.c +5 -0
- data/vendor/scs/src/scs_version.o +0 -0
- data/vendor/scs/src/util.c +196 -0
- data/vendor/scs/src/util.o +0 -0
- data/vendor/scs/test/data/small_random_socp +0 -0
- data/vendor/scs/test/minunit.h +13 -0
- data/vendor/scs/test/problem_utils.h +93 -0
- data/vendor/scs/test/problems/rob_gauss_cov_est.h +85 -0
- data/vendor/scs/test/problems/small_lp.h +50 -0
- data/vendor/scs/test/problems/small_random_socp.h +33 -0
- data/vendor/scs/test/random_socp_prob.c +171 -0
- data/vendor/scs/test/run_from_file.c +69 -0
- data/vendor/scs/test/run_tests +2 -0
- data/vendor/scs/test/run_tests.c +32 -0
- metadata +203 -0
data/vendor/scs/src/aa.c
ADDED
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
#include "aa.h"
|
|
2
|
+
#include "scs_blas.h"
|
|
3
|
+
|
|
4
|
+
/* This file uses Anderson acceleration to improve the convergence of
|
|
5
|
+
* a fixed point mapping.
|
|
6
|
+
* At each iteration we need to solve a (small) linear system, we
|
|
7
|
+
* do this using LAPACK ?gesv.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
#ifndef USE_LAPACK
|
|
11
|
+
|
|
12
|
+
typedef void * ACCEL_WORK;
|
|
13
|
+
|
|
14
|
+
AaWork *aa_init(aa_int dim, aa_int aa_mem, aa_int type1) { return SCS_NULL; }
|
|
15
|
+
aa_int aa_apply(aa_float *f, const aa_float *x, AaWork *a) { return 0; }
|
|
16
|
+
void aa_finish(AaWork *a) {}
|
|
17
|
+
|
|
18
|
+
#else
|
|
19
|
+
|
|
20
|
+
/* contains the necessary parameters to perform aa at each step */
|
|
21
|
+
struct ACCEL_WORK {
|
|
22
|
+
aa_int type1; /* bool, if true type 1 aa otherwise type 2 */
|
|
23
|
+
aa_int k; /* aa memory */
|
|
24
|
+
aa_int l; /* variable dimension */
|
|
25
|
+
aa_int iter; /* current iteration */
|
|
26
|
+
|
|
27
|
+
aa_float *x; /* x input to map*/
|
|
28
|
+
aa_float *f; /* f(x) output of map */
|
|
29
|
+
aa_float *g; /* x - f(x) */
|
|
30
|
+
|
|
31
|
+
/* from previous iteration */
|
|
32
|
+
aa_float *g_prev; /* x - f(x) */
|
|
33
|
+
|
|
34
|
+
aa_float *y; /* g - g_prev */
|
|
35
|
+
aa_float *s; /* x - x_prev */
|
|
36
|
+
aa_float *d; /* f - f_prev */
|
|
37
|
+
|
|
38
|
+
aa_float *Y; /* matrix of stacked y values */
|
|
39
|
+
aa_float *S; /* matrix of stacked s values */
|
|
40
|
+
aa_float *D; /* matrix of stacked d values = (S-Y) */
|
|
41
|
+
aa_float *M; /* S'Y or Y'Y depending on type of aa */
|
|
42
|
+
|
|
43
|
+
/* workspace variables */
|
|
44
|
+
aa_float *work;
|
|
45
|
+
blas_int *ipiv;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
/* BLAS functions used */
|
|
49
|
+
aa_float BLAS(nrm2)(blas_int *n, aa_float *x, blas_int *incx);
|
|
50
|
+
void BLAS(axpy)(blas_int *n, aa_float *a, const aa_float *x, blas_int *incx,
|
|
51
|
+
aa_float *y, blas_int *incy);
|
|
52
|
+
void BLAS(gemv)(const char *trans, const blas_int *m, const blas_int *n,
|
|
53
|
+
const aa_float *alpha, const aa_float *a, const blas_int *lda,
|
|
54
|
+
const aa_float *x, const blas_int *incx, const aa_float *beta,
|
|
55
|
+
aa_float *y, const blas_int *incy);
|
|
56
|
+
void BLAS(gesv)(blas_int *n, blas_int *nrhs, aa_float *a, blas_int *lda,
|
|
57
|
+
blas_int *ipiv, aa_float *b, blas_int *ldb, blas_int *info);
|
|
58
|
+
void BLAS(gemm)(const char *transa, const char *transb, blas_int *m,
|
|
59
|
+
blas_int *n, blas_int *k, aa_float *alpha, aa_float *a,
|
|
60
|
+
blas_int *lda, aa_float *b, blas_int *ldb, aa_float *beta,
|
|
61
|
+
aa_float *c, blas_int *ldc);
|
|
62
|
+
|
|
63
|
+
/* sets a->M to S'Y or Y'Y depending on type of aa used */
|
|
64
|
+
static void set_m(AaWork *a) {
|
|
65
|
+
blas_int bl = (blas_int)(a->l), bk = (blas_int)a->k;
|
|
66
|
+
aa_float onef = 1.0, zerof = 0.0;
|
|
67
|
+
BLAS(gemm)
|
|
68
|
+
("Trans", "No", &bk, &bk, &bl, &onef, a->type1 ? a->S : a->Y, &bl, a->Y, &bl,
|
|
69
|
+
&zerof, a->M, &bk);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/* updates the workspace parameters for aa for this iteration */
|
|
73
|
+
static void update_accel_params(const aa_float *x, const aa_float *f,
|
|
74
|
+
AaWork *a) {
|
|
75
|
+
/* at the start a->x = x_prev and a->f = f_prev */
|
|
76
|
+
aa_int idx = a->iter % a->k;
|
|
77
|
+
aa_int l = a->l;
|
|
78
|
+
|
|
79
|
+
blas_int one = 1;
|
|
80
|
+
blas_int bl = (blas_int)l;
|
|
81
|
+
aa_float neg_onef = -1.0;
|
|
82
|
+
|
|
83
|
+
/* g = x */
|
|
84
|
+
memcpy(a->g, x, sizeof(aa_float) * l);
|
|
85
|
+
/* s = x */
|
|
86
|
+
memcpy(a->s, x, sizeof(aa_float) * l);
|
|
87
|
+
/* d = f */
|
|
88
|
+
memcpy(a->d, f, sizeof(aa_float) * l);
|
|
89
|
+
/* g -= f */
|
|
90
|
+
BLAS(axpy)(&bl, &neg_onef, f, &one, a->g, &one);
|
|
91
|
+
/* s -= x_prev */
|
|
92
|
+
BLAS(axpy)(&bl, &neg_onef, a->x, &one, a->s, &one);
|
|
93
|
+
/* d -= f_prev */
|
|
94
|
+
BLAS(axpy)(&bl, &neg_onef, a->f, &one, a->d, &one);
|
|
95
|
+
|
|
96
|
+
/* g, s, d correct here */
|
|
97
|
+
|
|
98
|
+
/* y = g */
|
|
99
|
+
memcpy(a->y, a->g, sizeof(aa_float) * l);
|
|
100
|
+
/* y -= g_prev */
|
|
101
|
+
BLAS(axpy)(&bl, &neg_onef, a->g_prev, &one, a->y, &one);
|
|
102
|
+
|
|
103
|
+
/* y correct here */
|
|
104
|
+
|
|
105
|
+
/* copy y into idx col of Y */
|
|
106
|
+
memcpy(&(a->Y[idx * l]), a->y, sizeof(aa_float) * l);
|
|
107
|
+
/* copy s into idx col of S */
|
|
108
|
+
memcpy(&(a->S[idx * l]), a->s, sizeof(aa_float) * l);
|
|
109
|
+
/* copy d into idx col of D */
|
|
110
|
+
memcpy(&(a->D[idx * l]), a->d, sizeof(aa_float) * l);
|
|
111
|
+
|
|
112
|
+
/* Y, S,D correct here */
|
|
113
|
+
|
|
114
|
+
memcpy(a->f, f, sizeof(aa_float) * l);
|
|
115
|
+
memcpy(a->x, x, sizeof(aa_float) * l);
|
|
116
|
+
|
|
117
|
+
/* x, f correct here */
|
|
118
|
+
|
|
119
|
+
/* set M = S'*Y */
|
|
120
|
+
set_m(a);
|
|
121
|
+
|
|
122
|
+
/* M correct here */
|
|
123
|
+
|
|
124
|
+
memcpy(a->g_prev, a->g, sizeof(aa_float) * l);
|
|
125
|
+
|
|
126
|
+
/* g_prev set for next iter here */
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/* solves the system of equations to perform the aa update
|
|
130
|
+
* at the end f contains the next iterate to be returned
|
|
131
|
+
*/
|
|
132
|
+
static aa_int solve(aa_float *f, AaWork *a, aa_int len) {
|
|
133
|
+
blas_int info = -1, bl = (blas_int)(a->l), one = 1, blen = (blas_int)len,
|
|
134
|
+
bk = (blas_int)a->k;
|
|
135
|
+
aa_float neg_onef = -1.0, onef = 1.0, zerof = 0.0, nrm;
|
|
136
|
+
/* work = S'g or Y'g */
|
|
137
|
+
BLAS(gemv)
|
|
138
|
+
("Trans", &bl, &blen, &onef, a->type1 ? a->S : a->Y, &bl, a->g, &one, &zerof,
|
|
139
|
+
a->work, &one);
|
|
140
|
+
/* work = M \ work, where M = S'Y or M = Y'Y */
|
|
141
|
+
BLAS(gesv)(&blen, &one, a->M, &bk, a->ipiv, a->work, &blen, &info);
|
|
142
|
+
nrm = BLAS(nrm2)(&bk, a->work, &one);
|
|
143
|
+
if (info < 0 || nrm >= MAX_AA_NRM) {
|
|
144
|
+
#if EXTRA_VERBOSE > 0
|
|
145
|
+
scs_printf("Error in AA type %i, iter: %i, info: %i, norm %1.2e\n",
|
|
146
|
+
a->type1 ? 1 : 2, (int)a->iter, (int)info, nrm);
|
|
147
|
+
#endif
|
|
148
|
+
return -1;
|
|
149
|
+
}
|
|
150
|
+
/* if solve was successful then set f -= D * work */
|
|
151
|
+
BLAS(gemv)
|
|
152
|
+
("NoTrans", &bl, &blen, &neg_onef, a->D, &bl, a->work, &one, &onef, f, &one);
|
|
153
|
+
return (aa_int)info;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/*
|
|
157
|
+
* API functions below this line, see aa.h for descriptions.
|
|
158
|
+
*/
|
|
159
|
+
AaWork *aa_init(aa_int l, aa_int aa_mem, aa_int type1) {
|
|
160
|
+
AaWork *a = (AaWork *)calloc(1, sizeof(AaWork));
|
|
161
|
+
if (!a) {
|
|
162
|
+
scs_printf("Failed to allocate memory for AA.\n");
|
|
163
|
+
return (void *)0;
|
|
164
|
+
}
|
|
165
|
+
a->type1 = type1;
|
|
166
|
+
a->iter = 0;
|
|
167
|
+
a->l = l;
|
|
168
|
+
a->k = aa_mem;
|
|
169
|
+
if (a->k <= 0) {
|
|
170
|
+
return a;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
a->x = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
174
|
+
a->f = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
175
|
+
a->g = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
176
|
+
|
|
177
|
+
a->g_prev = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
178
|
+
|
|
179
|
+
a->y = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
180
|
+
a->s = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
181
|
+
a->d = (aa_float *)calloc(a->l, sizeof(aa_float));
|
|
182
|
+
|
|
183
|
+
a->Y = (aa_float *)calloc(a->l * a->k, sizeof(aa_float));
|
|
184
|
+
a->S = (aa_float *)calloc(a->l * a->k, sizeof(aa_float));
|
|
185
|
+
a->D = (aa_float *)calloc(a->l * a->k, sizeof(aa_float));
|
|
186
|
+
|
|
187
|
+
a->M = (aa_float *)calloc(a->k * a->k, sizeof(aa_float));
|
|
188
|
+
a->work = (aa_float *)calloc(a->k, sizeof(aa_float));
|
|
189
|
+
a->ipiv = (blas_int *)calloc(a->k, sizeof(blas_int));
|
|
190
|
+
return a;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
aa_int aa_apply(aa_float *f, const aa_float *x, AaWork *a) {
|
|
194
|
+
if (a->k <= 0) {
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
update_accel_params(x, f, a);
|
|
198
|
+
if (a->iter++ == 0) {
|
|
199
|
+
return 0;
|
|
200
|
+
}
|
|
201
|
+
/* solve linear system, new point overwrites f if successful */
|
|
202
|
+
return solve(f, a, MIN(a->iter - 1, a->k));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
void aa_finish(AaWork *a) {
|
|
206
|
+
if (a) {
|
|
207
|
+
free(a->x);
|
|
208
|
+
free(a->f);
|
|
209
|
+
free(a->g);
|
|
210
|
+
free(a->g_prev);
|
|
211
|
+
free(a->y);
|
|
212
|
+
free(a->s);
|
|
213
|
+
free(a->d);
|
|
214
|
+
free(a->Y);
|
|
215
|
+
free(a->S);
|
|
216
|
+
free(a->D);
|
|
217
|
+
free(a->M);
|
|
218
|
+
free(a->work);
|
|
219
|
+
free(a->ipiv);
|
|
220
|
+
free(a);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#endif
|
data/vendor/scs/src/aa.o
ADDED
|
Binary file
|