scs 0.2.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/README.md +11 -6
  4. data/lib/scs/ffi.rb +30 -13
  5. data/lib/scs/solver.rb +32 -9
  6. data/lib/scs/version.rb +1 -1
  7. data/vendor/scs/CITATION.cff +39 -0
  8. data/vendor/scs/CMakeLists.txt +7 -8
  9. data/vendor/scs/Makefile +24 -15
  10. data/vendor/scs/README.md +5 -263
  11. data/vendor/scs/include/aa.h +67 -23
  12. data/vendor/scs/include/cones.h +17 -17
  13. data/vendor/scs/include/glbopts.h +98 -32
  14. data/vendor/scs/include/linalg.h +2 -4
  15. data/vendor/scs/include/linsys.h +58 -44
  16. data/vendor/scs/include/normalize.h +3 -3
  17. data/vendor/scs/include/rw.h +8 -2
  18. data/vendor/scs/include/scs.h +293 -133
  19. data/vendor/scs/include/util.h +3 -15
  20. data/vendor/scs/linsys/cpu/direct/private.c +220 -224
  21. data/vendor/scs/linsys/cpu/direct/private.h +13 -7
  22. data/vendor/scs/linsys/cpu/direct/private.o +0 -0
  23. data/vendor/scs/linsys/cpu/indirect/private.c +177 -110
  24. data/vendor/scs/linsys/cpu/indirect/private.h +8 -4
  25. data/vendor/scs/linsys/cpu/indirect/private.o +0 -0
  26. data/vendor/scs/linsys/csparse.c +87 -0
  27. data/vendor/scs/linsys/csparse.h +34 -0
  28. data/vendor/scs/linsys/csparse.o +0 -0
  29. data/vendor/scs/linsys/external/amd/SuiteSparse_config.c +1 -1
  30. data/vendor/scs/linsys/external/amd/SuiteSparse_config.o +0 -0
  31. data/vendor/scs/linsys/external/amd/amd_1.o +0 -0
  32. data/vendor/scs/linsys/external/amd/amd_2.o +0 -0
  33. data/vendor/scs/linsys/external/amd/amd_aat.o +0 -0
  34. data/vendor/scs/linsys/external/amd/amd_control.o +0 -0
  35. data/vendor/scs/linsys/external/amd/amd_defaults.o +0 -0
  36. data/vendor/scs/linsys/external/amd/amd_dump.o +0 -0
  37. data/vendor/scs/linsys/external/amd/amd_global.o +0 -0
  38. data/vendor/scs/linsys/external/amd/amd_info.o +0 -0
  39. data/vendor/scs/linsys/external/amd/amd_internal.h +1 -1
  40. data/vendor/scs/linsys/external/amd/amd_order.o +0 -0
  41. data/vendor/scs/linsys/external/amd/amd_post_tree.o +0 -0
  42. data/vendor/scs/linsys/external/amd/amd_postorder.o +0 -0
  43. data/vendor/scs/linsys/external/amd/amd_preprocess.o +0 -0
  44. data/vendor/scs/linsys/external/amd/amd_valid.o +0 -0
  45. data/vendor/scs/linsys/external/qdldl/changes +2 -0
  46. data/vendor/scs/linsys/external/qdldl/qdldl.c +29 -46
  47. data/vendor/scs/linsys/external/qdldl/qdldl.h +33 -41
  48. data/vendor/scs/linsys/external/qdldl/qdldl.o +0 -0
  49. data/vendor/scs/linsys/external/qdldl/qdldl_types.h +11 -3
  50. data/vendor/scs/linsys/gpu/gpu.c +31 -33
  51. data/vendor/scs/linsys/gpu/gpu.h +48 -31
  52. data/vendor/scs/linsys/gpu/indirect/private.c +338 -232
  53. data/vendor/scs/linsys/gpu/indirect/private.h +23 -14
  54. data/vendor/scs/linsys/scs_matrix.c +498 -0
  55. data/vendor/scs/linsys/scs_matrix.h +70 -0
  56. data/vendor/scs/linsys/scs_matrix.o +0 -0
  57. data/vendor/scs/scs.mk +13 -9
  58. data/vendor/scs/src/aa.c +384 -109
  59. data/vendor/scs/src/aa.o +0 -0
  60. data/vendor/scs/src/cones.c +440 -353
  61. data/vendor/scs/src/cones.o +0 -0
  62. data/vendor/scs/src/ctrlc.c +15 -5
  63. data/vendor/scs/src/ctrlc.o +0 -0
  64. data/vendor/scs/src/linalg.c +84 -28
  65. data/vendor/scs/src/linalg.o +0 -0
  66. data/vendor/scs/src/normalize.c +22 -64
  67. data/vendor/scs/src/normalize.o +0 -0
  68. data/vendor/scs/src/rw.c +160 -21
  69. data/vendor/scs/src/rw.o +0 -0
  70. data/vendor/scs/src/scs.c +767 -563
  71. data/vendor/scs/src/scs.o +0 -0
  72. data/vendor/scs/src/scs_indir.o +0 -0
  73. data/vendor/scs/src/scs_version.c +9 -3
  74. data/vendor/scs/src/scs_version.o +0 -0
  75. data/vendor/scs/src/util.c +37 -106
  76. data/vendor/scs/src/util.o +0 -0
  77. data/vendor/scs/test/minunit.h +17 -8
  78. data/vendor/scs/test/problem_utils.h +176 -14
  79. data/vendor/scs/test/problems/degenerate.h +130 -0
  80. data/vendor/scs/test/problems/hs21_tiny_qp.h +124 -0
  81. data/vendor/scs/test/problems/hs21_tiny_qp_rw.h +116 -0
  82. data/vendor/scs/test/problems/infeasible_tiny_qp.h +100 -0
  83. data/vendor/scs/test/problems/qafiro_tiny_qp.h +199 -0
  84. data/vendor/scs/test/problems/random_prob +0 -0
  85. data/vendor/scs/test/problems/random_prob.h +45 -0
  86. data/vendor/scs/test/problems/rob_gauss_cov_est.h +188 -31
  87. data/vendor/scs/test/problems/small_lp.h +13 -14
  88. data/vendor/scs/test/problems/test_fails.h +43 -0
  89. data/vendor/scs/test/problems/unbounded_tiny_qp.h +82 -0
  90. data/vendor/scs/test/random_socp_prob.c +54 -53
  91. data/vendor/scs/test/rng.h +109 -0
  92. data/vendor/scs/test/run_from_file.c +19 -10
  93. data/vendor/scs/test/run_tests.c +27 -3
  94. metadata +20 -8
  95. data/vendor/scs/linsys/amatrix.c +0 -305
  96. data/vendor/scs/linsys/amatrix.h +0 -36
  97. data/vendor/scs/linsys/amatrix.o +0 -0
  98. data/vendor/scs/test/data/small_random_socp +0 -0
  99. data/vendor/scs/test/problems/small_random_socp.h +0 -33
  100. data/vendor/scs/test/run_tests +0 -2
@@ -0,0 +1,109 @@
1
+ /* This program by D E Knuth is in the public domain and freely copyable
2
+ * AS LONG AS YOU MAKE ABSOLUTELY NO CHANGES!
3
+ * It is explained in Seminumerical Algorithms, 3rd edition, Section 3.6
4
+ * (or in the errata to the 2nd edition --- see
5
+ * http://www-cs-faculty.stanford.edu/~knuth/taocp.html
6
+ * in the changes to Volume 2 on pages 171 and following). */
7
+
8
+ /* N.B. The MODIFICATIONS introduced in the 9th printing (2002) are
9
+ included here; there's no backwards compatibility with the original. */
10
+
11
+ /* This version also adopts Brendan McKay's suggestion to
12
+ accommodate naive users who forget to call ran_start(seed). */
13
+
14
+ /* If you find any bugs, please report them immediately to
15
+ * taocp@cs.stanford.edu
16
+ * (and you will be rewarded if the bug is genuine). Thanks! */
17
+
18
+ /************ see the book for explanations and caveats! *******************/
19
+ /************ in particular, you need two's complement arithmetic **********/
20
+
21
+ #define KK 100 /* the long lag */
22
+ #define LL 37 /* the short lag */
23
+ #define MM (1L << 30) /* the modulus */
24
+ #define mod_diff(x, y) (((x) - (y)) & (MM - 1)) /* subtraction mod MM */
25
+
26
+ long ran_x[KK]; /* the generator state */
27
+
28
+ #ifdef __STDC__
29
+ void ran_array(long aa[], int n)
30
+ #else
31
+ void ran_array(aa, n) /* put n new random numbers in aa */
32
+ long *aa; /* destination */
33
+ int n; /* array length (must be at least KK) */
34
+ #endif
35
+ {
36
+ register int i, j;
37
+ for (j = 0; j < KK; j++)
38
+ aa[j] = ran_x[j];
39
+ for (; j < n; j++)
40
+ aa[j] = mod_diff(aa[j - KK], aa[j - LL]);
41
+ for (i = 0; i < LL; i++, j++)
42
+ ran_x[i] = mod_diff(aa[j - KK], aa[j - LL]);
43
+ for (; i < KK; i++, j++)
44
+ ran_x[i] = mod_diff(aa[j - KK], ran_x[i - LL]);
45
+ }
46
+
47
+ /* the following routines are from exercise 3.6--15 */
48
+ /* after calling ran_start, get new randoms by, e.g., "x=ran_arr_next()" */
49
+
50
+ #define QUALITY 1009 /* recommended quality level for high-res use */
51
+ long ran_arr_buf[QUALITY];
52
+ long ran_arr_dummy = -1, ran_arr_started = -1;
53
+ long *ran_arr_ptr = &ran_arr_dummy; /* the next random number, or -1 */
54
+
55
+ #define TT 70 /* guaranteed separation between streams */
56
+ #define is_odd(x) ((x)&1) /* units bit of x */
57
+
58
+ #ifdef __STDC__
59
+ void ran_start(long seed)
60
+ #else
61
+ void ran_start(seed) /* do this before using ran_array */
62
+ long seed; /* selector for different streams */
63
+ #endif
64
+ {
65
+ register int t, j;
66
+ long x[KK + KK - 1]; /* the preparation buffer */
67
+ register long ss = (seed + 2) & (MM - 2);
68
+ for (j = 0; j < KK; j++) {
69
+ x[j] = ss; /* bootstrap the buffer */
70
+ ss <<= 1;
71
+ if (ss >= MM)
72
+ ss -= MM - 2; /* cyclic shift 29 bits */
73
+ }
74
+ x[1]++; /* make x[1] (and only x[1]) odd */
75
+ for (ss = seed & (MM - 1), t = TT - 1; t;) {
76
+ for (j = KK - 1; j > 0; j--)
77
+ x[j + j] = x[j], x[j + j - 1] = 0; /* "square" */
78
+ for (j = KK + KK - 2; j >= KK; j--)
79
+ x[j - (KK - LL)] = mod_diff(x[j - (KK - LL)], x[j]),
80
+ x[j - KK] = mod_diff(x[j - KK], x[j]);
81
+ if (is_odd(ss)) { /* "multiply by z" */
82
+ for (j = KK; j > 0; j--)
83
+ x[j] = x[j - 1];
84
+ x[0] = x[KK]; /* shift the buffer cyclically */
85
+ x[LL] = mod_diff(x[LL], x[KK]);
86
+ }
87
+ if (ss)
88
+ ss >>= 1;
89
+ else
90
+ t--;
91
+ }
92
+ for (j = 0; j < LL; j++)
93
+ ran_x[j + KK - LL] = x[j];
94
+ for (; j < KK; j++)
95
+ ran_x[j - LL] = x[j];
96
+ for (j = 0; j < 10; j++)
97
+ ran_array(x, KK + KK - 1); /* warm things up */
98
+ ran_arr_ptr = &ran_arr_started;
99
+ }
100
+
101
+ #define ran_arr_next() (*ran_arr_ptr >= 0 ? *ran_arr_ptr++ : ran_arr_cycle())
102
+ long ran_arr_cycle(void) {
103
+ if (ran_arr_ptr == &ran_arr_dummy)
104
+ ran_start(314159L); /* the user forgot to initialize */
105
+ ran_array(ran_arr_buf, QUALITY);
106
+ ran_arr_buf[KK] = -1;
107
+ ran_arr_ptr = ran_arr_buf + 1;
108
+ return ran_arr_buf[0];
109
+ }
@@ -12,16 +12,24 @@ scs_int override_setting(ScsSettings *s, char *param, char *val) {
12
12
  s->rho_x = atof(val);
13
13
  } else if (strcmp(param, "max_iters") == 0) {
14
14
  s->max_iters = atoi(val);
15
- } else if (strcmp(param, "eps") == 0) {
16
- s->eps = atof(val);
15
+ } else if (strcmp(param, "eps_abs") == 0) {
16
+ s->eps_abs = atof(val);
17
+ } else if (strcmp(param, "eps_rel") == 0) {
18
+ s->eps_rel = atof(val);
19
+ } else if (strcmp(param, "eps_infeas") == 0) {
20
+ s->eps_infeas = atof(val);
17
21
  } else if (strcmp(param, "alpha") == 0) {
18
22
  s->alpha = atof(val);
19
- } else if (strcmp(param, "cg_rate") == 0) {
20
- s->cg_rate = atof(val);
21
23
  } else if (strcmp(param, "verbose") == 0) {
22
24
  s->verbose = atoi(val);
23
25
  } else if (strcmp(param, "acceleration_lookback") == 0) {
24
26
  s->acceleration_lookback = atoi(val);
27
+ } else if (strcmp(param, "acceleration_interval") == 0) {
28
+ s->acceleration_interval = atoi(val);
29
+ } else if (strcmp(param, "adaptive_scale") == 0) {
30
+ s->adaptive_scale = atoi(val);
31
+ } else if (strcmp(param, "log_csv_filename") == 0) {
32
+ s->log_csv_filename = val;
25
33
  } else {
26
34
  return -1;
27
35
  }
@@ -36,6 +44,7 @@ int main(int argc, char **argv) {
36
44
  scs_int read_status;
37
45
  ScsData *d;
38
46
  ScsCone *k;
47
+ ScsSettings *stgs;
39
48
  ScsSolution *sol;
40
49
  ScsInfo info = {0};
41
50
  scs_int i;
@@ -44,7 +53,7 @@ int main(int argc, char **argv) {
44
53
  return -1;
45
54
  }
46
55
  filename = argv[1];
47
- read_status = SCS(read_data)(filename, &d, &k);
56
+ read_status = SCS(read_data)(filename, &d, &k, &stgs);
48
57
  if (read_status < 0) {
49
58
  scs_printf("Data read failure, exit.\n");
50
59
  return -1;
@@ -52,18 +61,18 @@ int main(int argc, char **argv) {
52
61
  for (i = 2; i < argc; i += 2) {
53
62
  if (argc < i + 2) {
54
63
  scs_printf("Incorrect number of arguments supplied\n.");
55
- SCS(free_data)(d, k);
64
+ SCS(free_data)(d, k, stgs);
56
65
  return -1;
57
66
  }
58
- if (override_setting(d->stgs, argv[i], argv[i + 1]) < 0) {
67
+ if (override_setting(stgs, argv[i], argv[i + 1]) < 0) {
59
68
  scs_printf("Unrecognized setting %s\n", argv[i]);
60
- SCS(free_data)(d, k);
69
+ SCS(free_data)(d, k, stgs);
61
70
  return -1;
62
71
  }
63
72
  }
64
73
  sol = scs_calloc(1, sizeof(ScsSolution));
65
- scs(d, k, sol, &info);
66
- SCS(free_data)(d, k);
74
+ scs(d, k, stgs, sol, &info);
75
+ SCS(free_data)(d, k, stgs);
67
76
  SCS(free_sol)(sol);
68
77
  return 0;
69
78
  }
@@ -6,16 +6,40 @@
6
6
  #include "scs.h"
7
7
 
8
8
  /* Include Tests */
9
- #include "problems/small_lp.h"
9
+ #include "problems/degenerate.h"
10
+ #include "problems/hs21_tiny_qp.h"
11
+ #include "problems/hs21_tiny_qp_rw.h"
12
+ #include "problems/infeasible_tiny_qp.h"
13
+ #include "problems/qafiro_tiny_qp.h"
14
+ #include "problems/random_prob.h"
10
15
  #include "problems/rob_gauss_cov_est.h"
11
- #include "problems/small_random_socp.h"
16
+ #include "problems/small_lp.h"
17
+ #include "problems/test_fails.h"
18
+ #include "problems/unbounded_tiny_qp.h"
12
19
 
13
20
  int tests_run = 0;
14
21
 
15
22
  static const char *all_tests(void) {
23
+ scs_printf("test_fails\n");
24
+ mu_run_test(test_fails);
25
+ scs_printf("degenerate\n");
26
+ mu_run_test(degenerate);
27
+ scs_printf("small_lp\n");
16
28
  mu_run_test(small_lp);
29
+ scs_printf("rob_gauss_cov_est\n");
17
30
  mu_run_test(rob_gauss_cov_est);
18
- mu_run_test(small_random_socp);
31
+ scs_printf("hs21_tiny_qp\n");
32
+ mu_run_test(hs21_tiny_qp);
33
+ scs_printf("hs21_tiny_qp_rw\n");
34
+ mu_run_test(hs21_tiny_qp_rw);
35
+ scs_printf("qafiro_tiny_qp\n");
36
+ mu_run_test(qafiro_tiny_qp);
37
+ scs_printf("infeasible_tiny_qp\n");
38
+ mu_run_test(infeasible_tiny_qp);
39
+ scs_printf("unbounded_tiny_qp\n");
40
+ mu_run_test(unbounded_tiny_qp);
41
+ scs_printf("random_prob\n");
42
+ mu_run_test(random_prob);
19
43
  return 0;
20
44
  }
21
45
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Kane
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-09 00:00:00.000000000 Z
11
+ date: 2021-10-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email: andrew@ankane.org
@@ -25,6 +25,7 @@ files:
25
25
  - lib/scs/ffi.rb
26
26
  - lib/scs/solver.rb
27
27
  - lib/scs/version.rb
28
+ - vendor/scs/CITATION.cff
28
29
  - vendor/scs/CMakeLists.txt
29
30
  - vendor/scs/LICENSE.txt
30
31
  - vendor/scs/Makefile
@@ -40,15 +41,15 @@ files:
40
41
  - vendor/scs/include/scs.h
41
42
  - vendor/scs/include/scs_blas.h
42
43
  - vendor/scs/include/util.h
43
- - vendor/scs/linsys/amatrix.c
44
- - vendor/scs/linsys/amatrix.h
45
- - vendor/scs/linsys/amatrix.o
46
44
  - vendor/scs/linsys/cpu/direct/private.c
47
45
  - vendor/scs/linsys/cpu/direct/private.h
48
46
  - vendor/scs/linsys/cpu/direct/private.o
49
47
  - vendor/scs/linsys/cpu/indirect/private.c
50
48
  - vendor/scs/linsys/cpu/indirect/private.h
51
49
  - vendor/scs/linsys/cpu/indirect/private.o
50
+ - vendor/scs/linsys/csparse.c
51
+ - vendor/scs/linsys/csparse.h
52
+ - vendor/scs/linsys/csparse.o
52
53
  - vendor/scs/linsys/external/amd/LICENSE.txt
53
54
  - vendor/scs/linsys/external/amd/SuiteSparse_config.c
54
55
  - vendor/scs/linsys/external/amd/SuiteSparse_config.h
@@ -93,6 +94,9 @@ files:
93
94
  - vendor/scs/linsys/gpu/gpu.h
94
95
  - vendor/scs/linsys/gpu/indirect/private.c
95
96
  - vendor/scs/linsys/gpu/indirect/private.h
97
+ - vendor/scs/linsys/scs_matrix.c
98
+ - vendor/scs/linsys/scs_matrix.h
99
+ - vendor/scs/linsys/scs_matrix.o
96
100
  - vendor/scs/scs.mk
97
101
  - vendor/scs/src/aa.c
98
102
  - vendor/scs/src/aa.o
@@ -108,19 +112,27 @@ files:
108
112
  - vendor/scs/src/rw.o
109
113
  - vendor/scs/src/scs.c
110
114
  - vendor/scs/src/scs.o
115
+ - vendor/scs/src/scs_indir.o
111
116
  - vendor/scs/src/scs_version.c
112
117
  - vendor/scs/src/scs_version.o
113
118
  - vendor/scs/src/util.c
114
119
  - vendor/scs/src/util.o
115
- - vendor/scs/test/data/small_random_socp
116
120
  - vendor/scs/test/minunit.h
117
121
  - vendor/scs/test/problem_utils.h
122
+ - vendor/scs/test/problems/degenerate.h
123
+ - vendor/scs/test/problems/hs21_tiny_qp.h
124
+ - vendor/scs/test/problems/hs21_tiny_qp_rw.h
125
+ - vendor/scs/test/problems/infeasible_tiny_qp.h
126
+ - vendor/scs/test/problems/qafiro_tiny_qp.h
127
+ - vendor/scs/test/problems/random_prob
128
+ - vendor/scs/test/problems/random_prob.h
118
129
  - vendor/scs/test/problems/rob_gauss_cov_est.h
119
130
  - vendor/scs/test/problems/small_lp.h
120
- - vendor/scs/test/problems/small_random_socp.h
131
+ - vendor/scs/test/problems/test_fails.h
132
+ - vendor/scs/test/problems/unbounded_tiny_qp.h
121
133
  - vendor/scs/test/random_socp_prob.c
134
+ - vendor/scs/test/rng.h
122
135
  - vendor/scs/test/run_from_file.c
123
- - vendor/scs/test/run_tests
124
136
  - vendor/scs/test/run_tests.c
125
137
  homepage: https://github.com/ankane/scs
126
138
  licenses:
@@ -1,305 +0,0 @@
1
- /* contains routines common to direct and indirect sparse solvers */
2
- #include "amatrix.h"
3
-
4
- #include "linsys.h"
5
-
6
- #define MIN_SCALE (1e-4)
7
- #define MAX_SCALE (1e4)
8
- #define NUM_SCALE_PASSES 10 /* additional passes don't help much */
9
-
10
- scs_int SCS(copy_a_matrix)(ScsMatrix **dstp, const ScsMatrix *src) {
11
- scs_int Anz = src->p[src->n];
12
- ScsMatrix *A = (ScsMatrix *)scs_calloc(1, sizeof(ScsMatrix));
13
- if (!A) {
14
- return 0;
15
- }
16
- A->n = src->n;
17
- A->m = src->m;
18
- A->x = (scs_float *)scs_malloc(sizeof(scs_float) *
19
- Anz); /* A values, size: NNZ A */
20
- A->i = (scs_int *)scs_malloc(sizeof(scs_int) *
21
- Anz); /* A row index, size: NNZ A */
22
- A->p = (scs_int *)scs_malloc(sizeof(scs_int) *
23
- (src->n + 1)); /* A column pointer, size: n+1 */
24
- if (!A->x || !A->i || !A->p) {
25
- return 0;
26
- }
27
- memcpy(A->x, src->x, sizeof(scs_float) * Anz);
28
- memcpy(A->i, src->i, sizeof(scs_int) * Anz);
29
- memcpy(A->p, src->p, sizeof(scs_int) * (src->n + 1));
30
- *dstp = A;
31
- return 1;
32
- }
33
-
34
- scs_int SCS(validate_lin_sys)(const ScsMatrix *A) {
35
- scs_int i, r_max, Anz;
36
- if (!A->x || !A->i || !A->p) {
37
- scs_printf("data incompletely specified\n");
38
- return -1;
39
- }
40
- /* detects some errors in A col ptrs: */
41
- Anz = A->p[A->n];
42
- if (Anz > 0) {
43
- for (i = 0; i < A->n; ++i) {
44
- if (A->p[i] == A->p[i + 1]) {
45
- scs_printf(
46
- "WARN: A->p (column pointers) not strictly increasing, "
47
- "column %li empty\n",
48
- (long)i);
49
- } else if (A->p[i] > A->p[i + 1]) {
50
- scs_printf("ERROR: A->p (column pointers) decreasing\n");
51
- return -1;
52
- }
53
- }
54
- }
55
- if (((scs_float)Anz / A->m > A->n) || (Anz < 0)) {
56
- scs_printf("Anz (nonzeros in A) = %li, outside of valid range\n",
57
- (long)Anz);
58
- return -1;
59
- }
60
- r_max = 0;
61
- for (i = 0; i < Anz; ++i) {
62
- if (A->i[i] > r_max) {
63
- r_max = A->i[i];
64
- }
65
- }
66
- if (r_max > A->m - 1) {
67
- scs_printf("number of rows in A inconsistent with input dimension\n");
68
- return -1;
69
- }
70
- return 0;
71
- }
72
-
73
- void SCS(free_a_matrix)(ScsMatrix *A) {
74
- if (A) {
75
- scs_free(A->x);
76
- scs_free(A->i);
77
- scs_free(A->p);
78
- scs_free(A);
79
- }
80
- }
81
-
82
- #if EXTRA_VERBOSE > 0
83
- static void print_a_matrix(const ScsMatrix *A) {
84
- scs_int i, j;
85
- /* TODO: this is to prevent clogging stdout */
86
- if (A->p[A->n] < 2500) {
87
- scs_printf("\n");
88
- for (i = 0; i < A->n; ++i) {
89
- scs_printf("Col %li: ", (long)i);
90
- for (j = A->p[i]; j < A->p[i + 1]; j++) {
91
- scs_printf("A[%li,%li] = %4f, ", (long)A->i[j], (long)i, A->x[j]);
92
- }
93
- scs_printf("norm col = %4f\n",
94
- SCS(norm)(&(A->x[A->p[i]]), A->p[i + 1] - A->p[i]));
95
- }
96
- scs_printf("norm A = %4f\n", SCS(norm)(A->x, A->p[A->n]));
97
- }
98
- }
99
- #endif
100
-
101
- void SCS(_normalize_a)(ScsMatrix *A, const ScsSettings *stgs, const ScsCone *k,
102
- ScsScaling *scal) {
103
- scs_float *D = (scs_float *)scs_malloc(A->m * sizeof(scs_float));
104
- scs_float *E = (scs_float *)scs_malloc(A->n * sizeof(scs_float));
105
- scs_float *Dt = (scs_float *)scs_malloc(A->m * sizeof(scs_float));
106
- scs_float *Et = (scs_float *)scs_malloc(A->n * sizeof(scs_float));
107
- scs_float *nms = (scs_float *)scs_calloc(A->m, sizeof(scs_float));
108
- scs_int i, j, l, count, delta, *boundaries;
109
- scs_int num_boundaries = SCS(get_cone_boundaries)(k, &boundaries);
110
- scs_float wrk;
111
-
112
- #if EXTRA_VERBOSE > 0
113
- SCS(timer) normalize_timer;
114
- SCS(tic)(&normalize_timer);
115
- scs_printf("normalizing A\n");
116
- print_a_matrix(A);
117
- #endif
118
-
119
- for (l = 0; l < NUM_SCALE_PASSES; ++l) {
120
- memset(D, 0, A->m * sizeof(scs_float));
121
- memset(E, 0, A->n * sizeof(scs_float));
122
- /* calculate row norms */
123
- for (i = 0; i < A->n; ++i) {
124
- for (j = A->p[i]; j < A->p[i + 1]; ++j) {
125
- D[A->i[j]] = MAX(D[A->i[j]], ABS(A->x[j]));
126
- }
127
- }
128
- for (i = 0; i < A->m; ++i) {
129
- D[i] = SQRTF(D[i]);
130
- D[i] = D[i] < MIN_SCALE ? 1.0 : D[i];
131
- D[i] = D[i] > MAX_SCALE ? MAX_SCALE : D[i];
132
- }
133
- /* calculate col norms, E */
134
- for (i = 0; i < A->n; ++i) {
135
- E[i] = SCS(norm_inf)(&(A->x[A->p[i]]), A->p[i + 1] - A->p[i]);
136
- E[i] = SQRTF(E[i]);
137
- E[i] = E[i] < MIN_SCALE ? 1.0 : E[i];
138
- E[i] = E[i] > MAX_SCALE ? MAX_SCALE : E[i];
139
- }
140
-
141
- /* mean of D across each cone */
142
- count = boundaries[0];
143
- for (i = 1; i < num_boundaries; ++i) {
144
- wrk = 0;
145
- delta = boundaries[i];
146
- for (j = count; j < count + delta; ++j) {
147
- wrk += D[j];
148
- }
149
- wrk /= delta;
150
- for (j = count; j < count + delta; ++j) {
151
- D[j] = wrk;
152
- }
153
- count += delta;
154
- }
155
-
156
- /* scale the rows with D */
157
- for (i = 0; i < A->n; ++i) {
158
- for (j = A->p[i]; j < A->p[i + 1]; ++j) {
159
- A->x[j] /= D[A->i[j]];
160
- }
161
- }
162
-
163
- /* scale the cols with E */
164
- for (i = 0; i < A->n; ++i) {
165
- SCS(scale_array)(&(A->x[A->p[i]]), 1.0 / E[i], A->p[i + 1] - A->p[i]);
166
- }
167
-
168
- /* Accumulate scaling */
169
- for (i = 0; i < A->m; ++i) {
170
- Dt[i] = (l == 0) ? D[i] : Dt[i] * D[i];
171
- }
172
- for (i = 0; i < A->n; ++i) {
173
- Et[i] = (l == 0) ? E[i] : Et[i] * E[i];
174
- }
175
- }
176
- scs_free(boundaries);
177
- scs_free(D);
178
- scs_free(E);
179
-
180
- /* calculate mean of row norms of A */
181
- for (i = 0; i < A->n; ++i) {
182
- for (j = A->p[i]; j < A->p[i + 1]; ++j) {
183
- wrk = A->x[j];
184
- nms[A->i[j]] += wrk * wrk;
185
- }
186
- }
187
- scal->mean_norm_row_a = 0.0;
188
- for (i = 0; i < A->m; ++i) {
189
- scal->mean_norm_row_a += SQRTF(nms[i]) / A->m;
190
- }
191
- scs_free(nms);
192
-
193
- /* calculate mean of col norms of A */
194
- scal->mean_norm_col_a = 0.0;
195
- for (i = 0; i < A->n; ++i) {
196
- scal->mean_norm_col_a +=
197
- SCS(norm)(&(A->x[A->p[i]]), A->p[i + 1] - A->p[i]) / A->n;
198
- }
199
-
200
- /* scale up by d->SCALE if not equal to 1 */
201
- if (stgs->scale != 1) {
202
- SCS(scale_array)(A->x, stgs->scale, A->p[A->n]);
203
- }
204
-
205
- scal->D = Dt;
206
- scal->E = Et;
207
-
208
- #if EXTRA_VERBOSE > 0
209
- scs_printf("finished normalizing A, time: %1.2es\n",
210
- SCS(tocq)(&normalize_timer) / 1e3);
211
- print_a_matrix(A);
212
- #endif
213
- }
214
-
215
- void SCS(_un_normalize_a)(ScsMatrix *A, const ScsSettings *stgs,
216
- const ScsScaling *scal) {
217
- scs_int i, j;
218
- scs_float *D = scal->D;
219
- scs_float *E = scal->E;
220
- for (i = 0; i < A->n; ++i) {
221
- SCS(scale_array)
222
- (&(A->x[A->p[i]]), E[i] / stgs->scale, A->p[i + 1] - A->p[i]);
223
- }
224
- for (i = 0; i < A->n; ++i) {
225
- for (j = A->p[i]; j < A->p[i + 1]; ++j) {
226
- A->x[j] *= D[A->i[j]];
227
- }
228
- }
229
- }
230
-
231
- void SCS(_accum_by_atrans)(scs_int n, scs_float *Ax, scs_int *Ai, scs_int *Ap,
232
- const scs_float *x, scs_float *y) {
233
- /* y += A'*x
234
- A in column compressed format
235
- parallelizes over columns (rows of A')
236
- */
237
- scs_int p, j;
238
- scs_int c1, c2;
239
- scs_float yj;
240
- #if EXTRA_VERBOSE > 0
241
- SCS(timer) mult_by_atrans_timer;
242
- SCS(tic)(&mult_by_atrans_timer);
243
- #endif
244
- #ifdef _OPENMP
245
- #pragma omp parallel for private(p, c1, c2, yj)
246
- #endif
247
- for (j = 0; j < n; j++) {
248
- yj = y[j];
249
- c1 = Ap[j];
250
- c2 = Ap[j + 1];
251
- for (p = c1; p < c2; p++) {
252
- yj += Ax[p] * x[Ai[p]];
253
- }
254
- y[j] = yj;
255
- }
256
- #if EXTRA_VERBOSE > 0
257
- scs_printf("mult By A trans time: %1.2es\n",
258
- SCS(tocq)(&mult_by_atrans_timer) / 1e3);
259
- #endif
260
- }
261
-
262
- scs_float SCS(cumsum)(scs_int *p, scs_int *c, scs_int n) {
263
- scs_int i, nz = 0;
264
- scs_float nz2 = 0;
265
- if (!p || !c) {
266
- return (-1);
267
- } /* check inputs */
268
- for (i = 0; i < n; i++) {
269
- p[i] = nz;
270
- nz += c[i];
271
- nz2 += c[i]; /* also in scs_float to avoid scs_int overflow */
272
- c[i] = p[i]; /* also copy p[0..n-1] back into c[0..n-1]*/
273
- }
274
- p[n] = nz;
275
- return nz2; /* return sum (c [0..n-1]) */
276
- }
277
-
278
- void SCS(_accum_by_a)(scs_int n, scs_float *Ax, scs_int *Ai, scs_int *Ap,
279
- const scs_float *x, scs_float *y) {
280
- /*y += A*x
281
- A in column compressed format
282
- this parallelizes over columns and uses
283
- pragma atomic to prevent concurrent writes to y
284
- */
285
- scs_int p, j;
286
- scs_int c1, c2;
287
- scs_float xj;
288
- #if EXTRA_VERBOSE > 0
289
- SCS(timer) mult_by_a_timer;
290
- SCS(tic)(&mult_by_a_timer);
291
- #endif
292
- /*#pragma omp parallel for private(p,c1,c2,xj) */
293
- for (j = 0; j < n; j++) {
294
- xj = x[j];
295
- c1 = Ap[j];
296
- c2 = Ap[j + 1];
297
- for (p = c1; p < c2; p++) {
298
- /*#pragma omp atomic */
299
- y[Ai[p]] += Ax[p] * xj;
300
- }
301
- }
302
- #if EXTRA_VERBOSE > 0
303
- scs_printf("mult By A time: %1.2es\n", SCS(tocq)(&mult_by_a_timer) / 1e3);
304
- #endif
305
- }
@@ -1,36 +0,0 @@
1
- #ifndef AMATRIX_H_GUARD
2
- #define AMATRIX_H_GUARD
3
-
4
- #ifdef __cplusplus
5
- extern "C" {
6
- #endif
7
-
8
- #include "glbopts.h"
9
- #include "linalg.h"
10
- #include "linsys.h"
11
- #include "scs.h"
12
- #include "util.h"
13
-
14
- /* this struct defines the data matrix A */
15
- struct SCS_A_DATA_MATRIX {
16
- /* A is supplied in column compressed format */
17
- scs_float *x; /* A values, size: NNZ A */
18
- scs_int *i; /* A row index, size: NNZ A */
19
- scs_int *p; /* A column pointer, size: n+1 */
20
- scs_int m, n; /* m rows, n cols */
21
- };
22
-
23
- void SCS(_accum_by_atrans)(scs_int n, scs_float *Ax, scs_int *Ai, scs_int *Ap,
24
- const scs_float *x, scs_float *y);
25
- void SCS(_accum_by_a)(scs_int n, scs_float *Ax, scs_int *Ai, scs_int *Ap,
26
- const scs_float *x, scs_float *y);
27
- void SCS(_normalize_a)(ScsMatrix *A, const ScsSettings *stgs, const ScsCone *k,
28
- ScsScaling *scal);
29
- void SCS(_un_normalize_a)(ScsMatrix *A, const ScsSettings *stgs,
30
- const ScsScaling *scal);
31
- scs_float SCS(cumsum)(scs_int *p, scs_int *c, scs_int n);
32
-
33
- #ifdef __cplusplus
34
- }
35
- #endif
36
- #endif
Binary file
Binary file
@@ -1,33 +0,0 @@
1
- #include "rw.h"
2
- #include "scs.h"
3
- #include "util.h"
4
-
5
- #define OPT (1.530897)
6
-
7
- static const char *small_random_socp(void) {
8
- ScsData *d;
9
- ScsCone *k;
10
- ScsSolution *sol;
11
- ScsInfo info = {0};
12
- scs_int exitflag, success;
13
- scs_float perr, derr;
14
- const char *filename = "test/data/small_random_socp";
15
-
16
- SCS(read_data)(filename, &d, &k);
17
- sol = scs_calloc(1, sizeof(ScsSolution));
18
- exitflag = scs(d, k, sol, &info);
19
-
20
- perr = SCS(dot)(d->c, sol->x, d->n) - OPT;
21
- derr = -SCS(dot)(d->b, sol->y, d->m) - OPT;
22
-
23
- scs_printf("primal obj error %4e\n", perr);
24
- scs_printf("dual obj error %4e\n", derr);
25
-
26
- success = ABS(perr) < 1e-4 && ABS(derr) < 1e-4 && exitflag == SCS_SOLVED;
27
-
28
- SCS(free_data)(d, k);
29
- SCS(free_sol)(sol);
30
- mu_assert("small_random_socp: SCS failed to produce outputflag SCS_SOLVED",
31
- success);
32
- return 0;
33
- }
@@ -1,2 +0,0 @@
1
- out/run_tests_indirect
2
- out/run_tests_direct