scs 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (106) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +3 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +84 -0
  5. data/ext/scs/Rakefile +11 -0
  6. data/lib/scs/ffi.rb +117 -0
  7. data/lib/scs/solver.rb +178 -0
  8. data/lib/scs/version.rb +3 -0
  9. data/lib/scs.rb +17 -0
  10. data/vendor/scs/LICENSE.txt +21 -0
  11. data/vendor/scs/Makefile +164 -0
  12. data/vendor/scs/README.md +220 -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 +975 -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
Binary file
@@ -0,0 +1,77 @@
1
+ /*
2
+ * Implements signal handling (ctrl-c) for SCS.
3
+ *
4
+ * Under Windows, we use SetConsoleCtrlHandler.
5
+ * Under Unix systems, we use sigaction.
6
+ * For Mex files, we use utSetInterruptEnabled/utIsInterruptPending.
7
+ *
8
+ */
9
+
10
+ #include "ctrlc.h"
11
+
12
+ #if CTRLC > 0
13
+
14
+ #ifdef MATLAB_MEX_FILE
15
+ #include <stdbool.h>
16
+
17
+ extern bool utIsInterruptPending(void);
18
+ extern bool utSetInterruptEnabled(bool);
19
+
20
+ static int istate;
21
+ void scs_start_interrupt_listener(void) {
22
+ istate = (int)utSetInterruptEnabled(true);
23
+ }
24
+
25
+ void scs_end_interrupt_listener(void) { utSetInterruptEnabled((bool)istate); }
26
+
27
+ int scs_is_interrupted(void) { return (int)utIsInterruptPending(); }
28
+
29
+ #elif (defined _WIN32 || _WIN64 || defined _WINDLL)
30
+ #include <windows.h>
31
+
32
+ static int int_detected;
33
+ static BOOL WINAPI scs_handle_ctrlc(DWORD dwCtrlType) {
34
+ if (dwCtrlType != CTRL_C_EVENT) {
35
+ return FALSE;
36
+ }
37
+ int_detected = 1;
38
+ return TRUE;
39
+ }
40
+
41
+ void scs_start_interrupt_listener(void) {
42
+ int_detected = 0;
43
+ SetConsoleCtrlHandler(scs_handle_ctrlc, TRUE);
44
+ }
45
+
46
+ void scs_end_interrupt_listener(void) {
47
+ SetConsoleCtrlHandler(scs_handle_ctrlc, FALSE);
48
+ }
49
+
50
+ int scs_is_interrupted(void) { return int_detected; }
51
+
52
+ #else /* Unix */
53
+
54
+ #include <signal.h>
55
+ static int int_detected;
56
+ struct sigaction oact;
57
+ static void scs_handle_ctrlc(int dummy) { int_detected = dummy ? dummy : -1; }
58
+
59
+ void scs_start_interrupt_listener(void) {
60
+ struct sigaction act;
61
+ int_detected = 0;
62
+ act.sa_flags = 0;
63
+ sigemptyset(&act.sa_mask);
64
+ act.sa_handler = scs_handle_ctrlc;
65
+ sigaction(SIGINT, &act, &oact);
66
+ }
67
+
68
+ void scs_end_interrupt_listener(void) {
69
+ struct sigaction act;
70
+ sigaction(SIGINT, &oact, &act);
71
+ }
72
+
73
+ int scs_is_interrupted(void) { return int_detected; }
74
+
75
+ #endif /* END IF MATLAB_MEX_FILE / WIN32 */
76
+
77
+ #endif /* END IF CTRLC > 0 */
Binary file
@@ -0,0 +1,84 @@
1
+ #include "linalg.h"
2
+ #include <math.h>
3
+
4
+ /* x = b*a */
5
+ void SCS(set_as_scaled_array)(scs_float *x, const scs_float *a,
6
+ const scs_float b, scs_int len) {
7
+ scs_int i;
8
+ for (i = 0; i < len; ++i) x[i] = b * a[i];
9
+ }
10
+
11
+ /* a *= b */
12
+ void SCS(scale_array)(scs_float *a, const scs_float b, scs_int len) {
13
+ scs_int i;
14
+ for (i = 0; i < len; ++i) a[i] *= b;
15
+ }
16
+
17
+ /* x'*y */
18
+ scs_float SCS(dot)(const scs_float *x, const scs_float *y, scs_int len) {
19
+ scs_int i;
20
+ scs_float ip = 0.0;
21
+ for (i = 0; i < len; ++i) {
22
+ ip += x[i] * y[i];
23
+ }
24
+ return ip;
25
+ }
26
+
27
+ /* ||v||_2^2 */
28
+ scs_float SCS(norm_sq)(const scs_float *v, scs_int len) {
29
+ scs_int i;
30
+ scs_float nmsq = 0.0;
31
+ for (i = 0; i < len; ++i) {
32
+ nmsq += v[i] * v[i];
33
+ }
34
+ return nmsq;
35
+ }
36
+
37
+ /* ||v||_2 */
38
+ scs_float SCS(norm)(const scs_float *v, scs_int len) {
39
+ return SQRTF(SCS(norm_sq)(v, len));
40
+ }
41
+
42
+ scs_float SCS(norm_inf)(const scs_float *a, scs_int l) {
43
+ scs_float tmp, max = 0.0;
44
+ scs_int i;
45
+ for (i = 0; i < l; ++i) {
46
+ tmp = ABS(a[i]);
47
+ if (tmp > max) {
48
+ max = tmp;
49
+ }
50
+ }
51
+ return max;
52
+ }
53
+
54
+ /* saxpy a += sc*b */
55
+ void SCS(add_scaled_array)(scs_float *a, const scs_float *b, scs_int n,
56
+ const scs_float sc) {
57
+ scs_int i;
58
+ for (i = 0; i < n; ++i) {
59
+ a[i] += sc * b[i];
60
+ }
61
+ }
62
+
63
+ scs_float SCS(norm_diff)(const scs_float *a, const scs_float *b, scs_int l) {
64
+ scs_float nm_diff = 0.0, tmp;
65
+ scs_int i;
66
+ for (i = 0; i < l; ++i) {
67
+ tmp = (a[i] - b[i]);
68
+ nm_diff += tmp * tmp;
69
+ }
70
+ return SQRTF(nm_diff);
71
+ }
72
+
73
+ scs_float SCS(norm_inf_diff)(const scs_float *a, const scs_float *b,
74
+ scs_int l) {
75
+ scs_float tmp, max = 0.0;
76
+ scs_int i;
77
+ for (i = 0; i < l; ++i) {
78
+ tmp = ABS(a[i] - b[i]);
79
+ if (tmp > max) {
80
+ max = tmp;
81
+ }
82
+ }
83
+ return max;
84
+ }
Binary file
@@ -0,0 +1,93 @@
1
+ #include "normalize.h"
2
+ #include "linalg.h"
3
+ #include "scs.h"
4
+
5
+ #define MIN_SCALE (1e-6)
6
+
7
+ void SCS(normalize_b_c)(ScsWork *w) {
8
+ scs_int i;
9
+ scs_float nm, *D = w->scal->D, *E = w->scal->E, *b = w->b, *c = w->c;
10
+ /* scale b */
11
+ for (i = 0; i < w->m; ++i) {
12
+ b[i] /= D[i];
13
+ }
14
+ nm = SCS(norm)(b, w->m);
15
+ w->sc_b = w->scal->mean_norm_col_a / MAX(nm, MIN_SCALE);
16
+ /* scale c */
17
+ for (i = 0; i < w->n; ++i) {
18
+ c[i] /= E[i];
19
+ }
20
+ nm = SCS(norm)(c, w->n);
21
+ w->sc_c = w->scal->mean_norm_row_a / MAX(nm, MIN_SCALE);
22
+ SCS(scale_array)(b, w->sc_b * w->stgs->scale, w->m);
23
+ SCS(scale_array)(c, w->sc_c * w->stgs->scale, w->n);
24
+ }
25
+
26
+ void SCS(calc_scaled_resids)(ScsWork *w, ScsResiduals *r) {
27
+ scs_float *D = w->scal->D;
28
+ scs_float *E = w->scal->E;
29
+ scs_float *u = w->u;
30
+ scs_float *u_t = w->u_t;
31
+ scs_float *u_prev = w->u_prev;
32
+ scs_float tmp;
33
+ scs_int i, n = w->n, m = w->m;
34
+
35
+ r->res_pri = 0;
36
+ for (i = 0; i < n; ++i) {
37
+ tmp = (u[i] - u_t[i]) / (E[i] * w->sc_b);
38
+ r->res_pri += tmp * tmp;
39
+ }
40
+ for (i = 0; i < m; ++i) {
41
+ tmp = (u[i + n] - u_t[i + n]) / (D[i] * w->sc_c);
42
+ r->res_pri += tmp * tmp;
43
+ }
44
+ tmp = u[n + m] - u_t[n + m];
45
+ r->res_pri += tmp * tmp;
46
+ r->res_pri = sqrt(r->res_pri);
47
+
48
+ r->res_dual = 0;
49
+ for (i = 0; i < n; ++i) {
50
+ tmp = (u[i] - u_prev[i]) * E[i] / w->sc_b;
51
+ r->res_dual += tmp * tmp;
52
+ }
53
+ for (i = 0; i < m; ++i) {
54
+ tmp = (u[i + n] - u_prev[i + n]) * D[i] / w->sc_c;
55
+ r->res_dual += tmp * tmp;
56
+ }
57
+ tmp = u[n + m] - u_t[n + m];
58
+ r->res_dual += tmp * tmp;
59
+ r->res_dual = sqrt(r->res_dual);
60
+ }
61
+
62
+ void SCS(normalize_warm_start)(ScsWork *w) {
63
+ scs_int i;
64
+ scs_float *D = w->scal->D;
65
+ scs_float *E = w->scal->E;
66
+ scs_float *x = w->u;
67
+ scs_float *y = &(w->u[w->n]);
68
+ scs_float *s = &(w->v[w->n]);
69
+ for (i = 0; i < w->n; ++i) {
70
+ x[i] *= (E[i] * w->sc_b);
71
+ }
72
+ for (i = 0; i < w->m; ++i) {
73
+ y[i] *= (D[i] * w->sc_c);
74
+ }
75
+ for (i = 0; i < w->m; ++i) {
76
+ s[i] /= (D[i] / (w->sc_b * w->stgs->scale));
77
+ }
78
+ }
79
+
80
+ void SCS(un_normalize_sol)(ScsWork *w, ScsSolution *sol) {
81
+ scs_int i;
82
+ scs_float *D = w->scal->D;
83
+ scs_float *E = w->scal->E;
84
+ for (i = 0; i < w->n; ++i) {
85
+ sol->x[i] /= (E[i] * w->sc_b);
86
+ }
87
+ for (i = 0; i < w->m; ++i) {
88
+ sol->y[i] /= (D[i] * w->sc_c);
89
+ }
90
+ for (i = 0; i < w->m; ++i) {
91
+ sol->s[i] *= D[i] / (w->sc_b * w->stgs->scale);
92
+ }
93
+ }
Binary file
@@ -0,0 +1,167 @@
1
+ #include "rw.h"
2
+
3
+ #include <stdint.h>
4
+ #include <stdio.h>
5
+ #include <stdlib.h>
6
+
7
+ #include "amatrix.h"
8
+ #include "scs.h"
9
+ #include "util.h"
10
+
11
+ /* writes/reads problem data to/from filename */
12
+ /* This is a VERY naive implementation, doesn't care about portability etc */
13
+
14
+ static void write_scs_cone(const ScsCone *k, FILE *fout) {
15
+ fwrite(&(k->f), sizeof(scs_int), 1, fout);
16
+ fwrite(&(k->l), sizeof(scs_int), 1, fout);
17
+ fwrite(&(k->qsize), sizeof(scs_int), 1, fout);
18
+ fwrite(k->q, sizeof(scs_int), k->qsize, fout);
19
+ fwrite(&(k->ssize), sizeof(scs_int), 1, fout);
20
+ fwrite(k->s, sizeof(scs_int), k->ssize, fout);
21
+ fwrite(&(k->ep), sizeof(scs_int), 1, fout);
22
+ fwrite(&(k->ed), sizeof(scs_int), 1, fout);
23
+ fwrite(&(k->psize), sizeof(scs_int), 1, fout);
24
+ fwrite(k->p, sizeof(scs_float), k->psize, fout);
25
+ }
26
+
27
+ static ScsCone *read_scs_cone(FILE *fin) {
28
+ ScsCone *k = (ScsCone *)scs_calloc(1, sizeof(ScsCone));
29
+ fread(&(k->f), sizeof(scs_int), 1, fin);
30
+ fread(&(k->l), sizeof(scs_int), 1, fin);
31
+ fread(&(k->qsize), sizeof(scs_int), 1, fin);
32
+ k->q = scs_calloc(k->qsize, sizeof(scs_int));
33
+ fread(k->q, sizeof(scs_int), k->qsize, fin);
34
+ fread(&(k->ssize), sizeof(scs_int), 1, fin);
35
+ k->s = scs_calloc(k->ssize, sizeof(scs_int));
36
+ fread(k->s, sizeof(scs_int), k->ssize, fin);
37
+ fread(&(k->ep), sizeof(scs_int), 1, fin);
38
+ fread(&(k->ed), sizeof(scs_int), 1, fin);
39
+ fread(&(k->psize), sizeof(scs_int), 1, fin);
40
+ k->p = scs_calloc(k->psize, sizeof(scs_int));
41
+ fread(k->p, sizeof(scs_float), k->psize, fin);
42
+ return k;
43
+ }
44
+
45
+ static void write_scs_stgs(const ScsSettings *s, FILE *fout) {
46
+ /* Warm start to false for now */
47
+ scs_int warm_start = 0;
48
+ fwrite(&(s->normalize), sizeof(scs_int), 1, fout);
49
+ fwrite(&(s->scale), sizeof(scs_float), 1, fout);
50
+ fwrite(&(s->rho_x), sizeof(scs_float), 1, fout);
51
+ fwrite(&(s->max_iters), sizeof(scs_int), 1, fout);
52
+ fwrite(&(s->eps), sizeof(scs_float), 1, fout);
53
+ fwrite(&(s->alpha), sizeof(scs_float), 1, fout);
54
+ fwrite(&(s->cg_rate), sizeof(scs_float), 1, fout);
55
+ fwrite(&(s->verbose), sizeof(scs_int), 1, fout);
56
+ fwrite(&warm_start, sizeof(scs_int), 1, fout);
57
+ fwrite(&(s->acceleration_lookback), sizeof(scs_int), 1, fout);
58
+ /* Do not write the write_data_filename */
59
+ }
60
+
61
+ static ScsSettings *read_scs_stgs(FILE *fin) {
62
+ ScsSettings *s = (ScsSettings *)scs_calloc(1, sizeof(ScsSettings));
63
+ fread(&(s->normalize), sizeof(scs_int), 1, fin);
64
+ fread(&(s->scale), sizeof(scs_float), 1, fin);
65
+ fread(&(s->rho_x), sizeof(scs_float), 1, fin);
66
+ fread(&(s->max_iters), sizeof(scs_int), 1, fin);
67
+ fread(&(s->eps), sizeof(scs_float), 1, fin);
68
+ fread(&(s->alpha), sizeof(scs_float), 1, fin);
69
+ fread(&(s->cg_rate), sizeof(scs_float), 1, fin);
70
+ fread(&(s->verbose), sizeof(scs_int), 1, fin);
71
+ fread(&(s->warm_start), sizeof(scs_int), 1, fin);
72
+ fread(&(s->acceleration_lookback), sizeof(scs_int), 1, fin);
73
+ return s;
74
+ }
75
+
76
+ static void write_amatrix(const ScsMatrix *A, FILE *fout) {
77
+ scs_int Anz = A->p[A->n];
78
+ fwrite(&(A->m), sizeof(scs_int), 1, fout);
79
+ fwrite(&(A->n), sizeof(scs_int), 1, fout);
80
+ fwrite(A->p, sizeof(scs_int), A->n + 1, fout);
81
+ fwrite(A->x, sizeof(scs_float), Anz, fout);
82
+ fwrite(A->i, sizeof(scs_int), Anz, fout);
83
+ }
84
+
85
+ static ScsMatrix *read_amatrix(FILE *fin) {
86
+ scs_int Anz;
87
+ ScsMatrix *A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
88
+ fread(&(A->m), sizeof(scs_int), 1, fin);
89
+ fread(&(A->n), sizeof(scs_int), 1, fin);
90
+ A->p = scs_calloc(A->n + 1, sizeof(scs_int));
91
+ fread(A->p, sizeof(scs_int), A->n + 1, fin);
92
+ Anz = A->p[A->n];
93
+ A->x = scs_calloc(Anz, sizeof(scs_float));
94
+ A->i = scs_calloc(Anz, sizeof(scs_int));
95
+ fread(A->x, sizeof(scs_float), Anz, fin);
96
+ fread(A->i, sizeof(scs_int), Anz, fin);
97
+ return A;
98
+ }
99
+
100
+ static void write_scs_data(const ScsData *d, FILE *fout) {
101
+ fwrite(&(d->m), sizeof(scs_int), 1, fout);
102
+ fwrite(&(d->n), sizeof(scs_int), 1, fout);
103
+ fwrite(d->b, sizeof(scs_float), d->m, fout);
104
+ fwrite(d->c, sizeof(scs_float), d->n, fout);
105
+ write_scs_stgs(d->stgs, fout);
106
+ write_amatrix(d->A, fout);
107
+ }
108
+
109
+ static ScsData *read_scs_data(FILE *fin) {
110
+ ScsData *d = (ScsData *)scs_calloc(1, sizeof(ScsData));
111
+ fread(&(d->m), sizeof(scs_int), 1, fin);
112
+ fread(&(d->n), sizeof(scs_int), 1, fin);
113
+ d->b = scs_calloc(d->m, sizeof(scs_float));
114
+ d->c = scs_calloc(d->n, sizeof(scs_float));
115
+ fread(d->b, sizeof(scs_float), d->m, fin);
116
+ fread(d->c, sizeof(scs_float), d->n, fin);
117
+ d->stgs = read_scs_stgs(fin);
118
+ d->A = read_amatrix(fin);
119
+ return d;
120
+ }
121
+
122
+ void SCS(write_data)(const ScsData *d, const ScsCone *k) {
123
+ FILE *fout = fopen(d->stgs->write_data_filename, "wb");
124
+ uint32_t scs_int_sz = (uint32_t)sizeof(scs_int);
125
+ uint32_t scs_float_sz = (uint32_t)sizeof(scs_float);
126
+ scs_printf("writing data to %s\n", d->stgs->write_data_filename);
127
+ fwrite(&(scs_int_sz), sizeof(uint32_t), 1, fout);
128
+ fwrite(&(scs_float_sz), sizeof(uint32_t), 1, fout);
129
+ write_scs_cone(k, fout);
130
+ write_scs_data(d, fout);
131
+ fclose(fout);
132
+ }
133
+
134
+ scs_int SCS(read_data)(const char *filename, ScsData **d, ScsCone **k) {
135
+ uint32_t file_int_sz;
136
+ uint32_t file_float_sz;
137
+ FILE *fin = fopen(filename, "rb");
138
+ if (!fin) {
139
+ scs_printf("Error reading file %s\n", filename);
140
+ return -1;
141
+ }
142
+ scs_printf("Reading data from %s\n", filename);
143
+ fread(&(file_int_sz), sizeof(uint32_t), 1, fin);
144
+ fread(&(file_float_sz), sizeof(uint32_t), 1, fin);
145
+
146
+ if (file_int_sz != (uint32_t)sizeof(scs_int)) {
147
+ scs_printf(
148
+ "Error, sizeof(file int) is %lu, but scs expects sizeof(int) "
149
+ "%lu, scs should be recompiled with correct flags.\n",
150
+ (unsigned long)file_int_sz, (unsigned long)sizeof(scs_int));
151
+ fclose(fin);
152
+ return -1;
153
+ }
154
+ if (file_float_sz != (uint32_t)sizeof(scs_float)) {
155
+ scs_printf(
156
+ "Error, sizeof(file float) is %lu, but scs expects "
157
+ "sizeof(float) %lu, scs should be recompiled with the correct flags.\n",
158
+ (unsigned long)file_float_sz, (unsigned long)sizeof(scs_float));
159
+ fclose(fin);
160
+ return -1;
161
+ }
162
+
163
+ *k = read_scs_cone(fin);
164
+ *d = read_scs_data(fin);
165
+ fclose(fin);
166
+ return 0;
167
+ }
Binary file