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.
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
@@ -0,0 +1,120 @@
1
+ # QDLDL
2
+ A free LDL factorisation routine for quasi-definite linear systems: `Ax=b`
3
+
4
+ [![Build Status](https://travis-ci.org/oxfordcontrol/qdldl.svg?branch=master)](https://travis-ci.org/oxfordcontrol/qdldl)
5
+ [![Build status](https://ci.appveyor.com/api/projects/status/ns4br7v6y3i5stai/branch/master?svg=true)](https://ci.appveyor.com/project/bstellato/qdldl-8q1mv/branch/master)
6
+ [![Coverage Status](https://coveralls.io/repos/github/oxfordcontrol/qdldl/badge.svg)](https://coveralls.io/github/oxfordcontrol/qdldl)
7
+
8
+
9
+ ## Getting started
10
+ To start using QDLDL, first clone the repository
11
+
12
+ ```bash
13
+ git clone https://github.com/oxfordcontrol/qdldl.git
14
+ ```
15
+
16
+ ### Build
17
+
18
+ To build QDLDL, you need to install [cmake](https://cmake.org/) and run
19
+
20
+ ```bash
21
+ mkdir build
22
+ cd build
23
+ cmake ..
24
+ cmake --build .
25
+ ```
26
+
27
+ This will generate an `out/` folder with contents:
28
+
29
+ - `qdldl_example`: a **code example** from [`examples/c/example.c`](./examples/c/example.c)
30
+ - `libqdldl`: a static and a dynamic versions of the library.
31
+
32
+ You can include an addition option `-DUNITTESTS=ON` when calling `cmake`, which will result in an additional executable `qdldl_tester` being built in the `out/` folder to test QDLDL on a variety of problems, including those with rank deficient or otherwise ill-formatted inputs.
33
+
34
+ **N.B.** All files will have file extensions appropriate to your operating system.
35
+
36
+
37
+ ### Install/Uninstall
38
+
39
+ To install (uninstall) the libraries and headers you can simply run `make install` (`make uninstall`) after running the `cmake` command above.
40
+
41
+
42
+ ## Calling QDLDL
43
+
44
+ ### Main API
45
+
46
+ The QDLDL API consists of 5 functions documented in [`include/qdldl.h`](./include/qdldl.h).
47
+ For more details and a working example see [`examples/c/example.c`](./examples/c/example.c).
48
+
49
+ **N.B.** There is **no memory allocation** performed in these routines. The user is assumed to have the working vectors already allocated.
50
+
51
+ Here is a brief summary.
52
+
53
+ * `QDLDL_etree`: compute the elimination tree for the quasidefinite matrix factorization `A = LDL'`
54
+ * `QDLDL_factor`: return the factors `L`, `D` and `Dinv = 1./D`
55
+ * `QDLDL_solve`: solves the linear system `LDL'x = b`
56
+ * `QDLDL_Lsolve`: solves `Lx = b`
57
+ * `QDLDL_Ltsolve`: solves `L'x = b`
58
+
59
+ In the above function calls the matrices `A` and `L` are stored in compressed sparse column (CSC) format. The matrix `A` is assumed to be symmetric and only the upper triangular portion of A should be passed to the API. The factor `L` is lower triangular with implicit ones on the diagonal (i.e. the diagonal of L is not stored as part of the CSC formatted data.)
60
+
61
+ The matrices `D` and `Dinv` are both diagonal matrices, with the diagonal values stored in an array.
62
+
63
+ The matrix input `A` should be quasidefinite. The API provides some (non-comprehensive) error checking to protect against non-quasidefinite or non-upper triangular inputs.
64
+
65
+ ### Custom types for integer, floats and booleans
66
+ QDLDL uses its own internal types for integers, floats and booleans (`QDLDL_int, QDLDL_float, QDLDL_bool`. They can be specified using the cmake options:
67
+
68
+ - `DFLOAT` (default false): uses float numbers instead of doubles
69
+ - `DLONG` (default true): uses long integers for indexing (for large matrices)
70
+
71
+ The `QDLDL_bool` is internally defined as `unsigned char`.
72
+
73
+
74
+ ## Linking QDLDL
75
+
76
+ ### Basic Example
77
+ A basic example appears in [`examples/c/example.c`](./examples/c/example.c) and is compiled using cmake and the `CMakeLists.txt` file in the root folder.
78
+
79
+
80
+ ### Including in a cmake project
81
+
82
+ You can include QDLDL in a cmake project `foo` by adding the subdirectory as
83
+ ```
84
+ # Add project
85
+ add_subdirectory(qdldl)
86
+ ```
87
+
88
+ QDLDL can be linked using a static or dynamic linker
89
+ ```
90
+ # Link static library
91
+ target_link_libraries (foo qdldlstatic)
92
+
93
+ # Link shared library
94
+ target_link_libraries (foo qdldl)
95
+ ```
96
+ for dynamic linking the shared library should be available in your path.
97
+
98
+ There is also the option to include QDLDL as an object library in your project.
99
+ The current `CMakeLists.txt` file creates an object library called `qdldlobject`.
100
+ This can be added to your project by adding it after your sources.
101
+ For example, when creating a library `foo` you can add
102
+
103
+ ```
104
+ add_library(foo foo.c foo.h $<TARGET_OBJECTS:qdldlobject>)
105
+ ```
106
+ for more details see the [cmake documentation](https://cmake.org/cmake/help/latest/command/add_library.html#object-libraries).
107
+
108
+
109
+ ## The algorithm
110
+
111
+ The algorithm is an independent implementation of the elimination tree and factorisation procedures outlined in
112
+
113
+ > T. A Davis. [Algorithm 849: a concise sparse cholesky factorization package](https://dl.acm.org/citation.cfm?id=1114277). ACM Trans. Math. Softw., 31(4):587–591, 2005.
114
+
115
+
116
+ ## Credits
117
+
118
+ - [Paul Goulart](http://users.ox.ac.uk/~engs1373/): main development
119
+ - [Bartolomeo Stellato](https://stellato.io/): code refactoring and testing
120
+ - [Goran Banjac](http://control.ee.ethz.ch/~gbanjac/)
@@ -0,0 +1,4 @@
1
+ flatten into one dir
2
+ create qdldl_types.h from template file
3
+ add 'include "glbopts.h"' to qdldl_types.h
4
+ manually insert scs types into qdldl_types.h
@@ -0,0 +1,298 @@
1
+ #include "qdldl.h"
2
+ #include "ctrlc.h"
3
+
4
+ #define QDLDL_UNKNOWN (-1)
5
+ #define QDLDL_USED (1)
6
+ #define QDLDL_UNUSED (0)
7
+
8
+ // //DEBUG
9
+ // #include <stdio.h>
10
+ // void qdprint_arrayi(const QDLDL_int* data, QDLDL_int n,char* varName){
11
+
12
+ // QDLDL_int i;
13
+ // printf("%s = [",varName);
14
+ // for(i=0; i< n; i++){
15
+ // printf("%lli,",data[i]);
16
+ // }
17
+ // printf("]\n");
18
+
19
+ // }
20
+
21
+ // void qdprint_arrayf(const QDLDL_float* data, QDLDL_int n, char* varName){
22
+
23
+ // QDLDL_int i;
24
+ // printf("%s = [",varName);
25
+ // for(i=0; i< n; i++){
26
+ // printf("%.3g,",data[i]);
27
+ // }
28
+ // printf("]\n");
29
+
30
+ // }
31
+ // // END DEBUG
32
+
33
+ /* Compute the elimination tree for a quasidefinite matrix
34
+ in compressed sparse column form.
35
+ */
36
+
37
+ QDLDL_int QDLDL_etree(const QDLDL_int n,
38
+ const QDLDL_int* Ap,
39
+ const QDLDL_int* Ai,
40
+ QDLDL_int* work,
41
+ QDLDL_int* Lnz,
42
+ QDLDL_int* etree){
43
+
44
+ QDLDL_int sumLnz = 0;
45
+ QDLDL_int i,j,p;
46
+
47
+
48
+ for(i = 0; i < n; i++){
49
+ // zero out Lnz and work. Set all etree values to unknown
50
+ work[i] = 0;
51
+ Lnz[i] = 0;
52
+ etree[i] = QDLDL_UNKNOWN;
53
+
54
+ //Abort if A doesn't have at least one entry
55
+ //one entry in every column
56
+ if(Ap[i] == Ap[i+1]){
57
+ return -1;
58
+ }
59
+
60
+ }
61
+
62
+ for(j = 0; j < n; j++){
63
+ work[j] = j;
64
+ for(p = Ap[j]; p < Ap[j+1]; p++){
65
+ i = Ai[p];
66
+ if(i > j){return -1;}; //abort if entries on lower triangle
67
+ while(work[i] != j){
68
+ if(etree[i] == QDLDL_UNKNOWN){
69
+ etree[i] = j;
70
+ }
71
+ Lnz[i]++; //nonzeros in this column
72
+ work[i] = j;
73
+ i = etree[i];
74
+ }
75
+ }
76
+ }
77
+
78
+ //compute the total nonzeros in L. This much
79
+ //space is required to store Li and Lx
80
+ for(i = 0; i < n; i++){sumLnz += Lnz[i];}
81
+
82
+ return sumLnz;
83
+ }
84
+
85
+
86
+
87
+ QDLDL_int QDLDL_factor(const QDLDL_int n,
88
+ const QDLDL_int* Ap,
89
+ const QDLDL_int* Ai,
90
+ const QDLDL_float* Ax,
91
+ QDLDL_int* Lp,
92
+ QDLDL_int* Li,
93
+ QDLDL_float* Lx,
94
+ QDLDL_float* D,
95
+ QDLDL_float* Dinv,
96
+ const QDLDL_int* Lnz,
97
+ const QDLDL_int* etree,
98
+ QDLDL_bool* bwork,
99
+ QDLDL_int* iwork,
100
+ QDLDL_float* fwork){
101
+
102
+ QDLDL_int i,j,k,nnzY, bidx, cidx, nextIdx, nnzE, tmpIdx;
103
+ QDLDL_int *yIdx, *elimBuffer, *LNextSpaceInCol;
104
+ QDLDL_float *yVals;
105
+ QDLDL_float yVals_cidx;
106
+ QDLDL_bool *yMarkers;
107
+ QDLDL_int positiveValuesInD = 0;
108
+
109
+ //partition working memory into pieces
110
+ yMarkers = bwork;
111
+ yIdx = iwork;
112
+ elimBuffer = iwork + n;
113
+ LNextSpaceInCol = iwork + n*2;
114
+ yVals = fwork;
115
+
116
+
117
+ Lp[0] = 0; //first column starts at index zero
118
+
119
+ for(i = 0; i < n; i++){
120
+
121
+ //compute L column indices
122
+ Lp[i+1] = Lp[i] + Lnz[i]; //cumsum, total at the end
123
+
124
+ // set all Yidx to be 'unused' initially
125
+ //in each column of L, the next available space
126
+ //to start is just the first space in the column
127
+ yMarkers[i] = QDLDL_UNUSED;
128
+ yVals[i] = 0.0;
129
+ D[i] = 0.0;
130
+ LNextSpaceInCol[i] = Lp[i];
131
+ }
132
+
133
+ // First element of the diagonal D.
134
+ D[0] = Ax[0];
135
+ if(D[0] == 0.0){return -1;}
136
+ if(D[0] > 0.0){positiveValuesInD++;}
137
+ Dinv[0] = 1/D[0];
138
+
139
+ //Start from 1 here. The upper LH corner is trivially 0
140
+ //in L b/c we are only computing the subdiagonal elements
141
+ for(k = 1; k < n; k++){
142
+ if(scs_is_interrupted()) {
143
+ scs_printf("interrupt detected in factorization\n");
144
+ return -1;
145
+ }
146
+
147
+ //NB : For each k, we compute a solution to
148
+ //y = L(0:(k-1),0:k-1))\b, where b is the kth
149
+ //column of A that sits above the diagonal.
150
+ //The solution y is then the kth row of L,
151
+ //with an implied '1' at the diagonal entry.
152
+
153
+ //number of nonzeros in this row of L
154
+ nnzY = 0; //number of elements in this row
155
+
156
+ //This loop determines where nonzeros
157
+ //will go in the kth row of L, but doesn't
158
+ //compute the actual values
159
+ tmpIdx = Ap[k+1];
160
+
161
+ for(i = Ap[k]; i < tmpIdx; i++){
162
+
163
+ bidx = Ai[i]; // we are working on this element of b
164
+
165
+ //Initialize D[k] as the element of this column
166
+ //corresponding to the diagonal place. Don't use
167
+ //this element as part of the elimination step
168
+ //that computes the k^th row of L
169
+ if(bidx == k){
170
+ D[k] = Ax[i];
171
+ continue;
172
+ }
173
+
174
+ yVals[bidx] = Ax[i]; // initialise y(bidx) = b(bidx)
175
+
176
+ // use the forward elimination tree to figure
177
+ // out which elements must be eliminated after
178
+ // this element of b
179
+ nextIdx = bidx;
180
+
181
+ if(yMarkers[nextIdx] == QDLDL_UNUSED){ //this y term not already visited
182
+
183
+ yMarkers[nextIdx] = QDLDL_USED; //I touched this one
184
+ elimBuffer[0] = nextIdx; // It goes at the start of the current list
185
+ nnzE = 1; //length of unvisited elimination path from here
186
+
187
+ nextIdx = etree[bidx];
188
+
189
+ while(nextIdx != QDLDL_UNKNOWN && nextIdx < k){
190
+ if(yMarkers[nextIdx] == QDLDL_USED) break;
191
+
192
+ yMarkers[nextIdx] = QDLDL_USED; //I touched this one
193
+ elimBuffer[nnzE] = nextIdx; //It goes in the current list
194
+ nnzE++; //the list is one longer than before
195
+ nextIdx = etree[nextIdx]; //one step further along tree
196
+
197
+ } //end while
198
+
199
+ // now I put the buffered elimination list into
200
+ // my current ordering in reverse order
201
+ while(nnzE){
202
+ yIdx[nnzY++] = elimBuffer[--nnzE];
203
+ } //end while
204
+ } //end if
205
+
206
+ } //end for i
207
+
208
+ //This for loop places nonzeros values in the k^th row
209
+ for(i = (nnzY-1); i >=0; i--){
210
+
211
+ //which column are we working on?
212
+ cidx = yIdx[i];
213
+
214
+ // loop along the elements in this
215
+ // column of L and subtract to solve to y
216
+ tmpIdx = LNextSpaceInCol[cidx];
217
+ yVals_cidx = yVals[cidx];
218
+ for(j = Lp[cidx]; j < tmpIdx; j++){
219
+ yVals[Li[j]] -= Lx[j]*yVals_cidx;
220
+ }
221
+
222
+ //Now I have the cidx^th element of y = L\b.
223
+ //so compute the corresponding element of
224
+ //this row of L and put it into the right place
225
+ Li[tmpIdx] = k;
226
+ Lx[tmpIdx] = yVals_cidx *Dinv[cidx];
227
+
228
+ //D[k] -= yVals[cidx]*yVals[cidx]*Dinv[cidx];
229
+ D[k] -= yVals_cidx*Lx[tmpIdx];
230
+ LNextSpaceInCol[cidx]++;
231
+
232
+ //reset the yvalues and indices back to zero and QDLDL_UNUSED
233
+ //once I'm done with them
234
+ yVals[cidx] = 0.0;
235
+ yMarkers[cidx] = QDLDL_UNUSED;
236
+
237
+ } //end for i
238
+
239
+ //Maintain a count of the positive entries
240
+ //in D. If we hit a zero, we can't factor
241
+ //this matrix, so abort
242
+ if(D[k] == 0.0){return -1;}
243
+ if(D[k] > 0.0){positiveValuesInD++;}
244
+
245
+ //compute the inverse of the diagonal
246
+ Dinv[k]= 1/D[k];
247
+
248
+ } //end for k
249
+
250
+ return positiveValuesInD;
251
+
252
+ }
253
+
254
+ // Solves (L+I)x = b
255
+ void QDLDL_Lsolve(const QDLDL_int n,
256
+ const QDLDL_int* Lp,
257
+ const QDLDL_int* Li,
258
+ const QDLDL_float* Lx,
259
+ QDLDL_float* x){
260
+
261
+ QDLDL_int i,j;
262
+ for(i = 0; i < n; i++){
263
+ for(j = Lp[i]; j < Lp[i+1]; j++){
264
+ x[Li[j]] -= Lx[j]*x[i];
265
+ }
266
+ }
267
+ }
268
+
269
+ // Solves (L+I)'x = b
270
+ void QDLDL_Ltsolve(const QDLDL_int n,
271
+ const QDLDL_int* Lp,
272
+ const QDLDL_int* Li,
273
+ const QDLDL_float* Lx,
274
+ QDLDL_float* x){
275
+
276
+ QDLDL_int i,j;
277
+ for(i = n-1; i>=0; i--){
278
+ for(j = Lp[i]; j < Lp[i+1]; j++){
279
+ x[i] -= Lx[j]*x[Li[j]];
280
+ }
281
+ }
282
+ }
283
+
284
+ // Solves Ax = b where A has given LDL factors
285
+ void QDLDL_solve(const QDLDL_int n,
286
+ const QDLDL_int* Lp,
287
+ const QDLDL_int* Li,
288
+ const QDLDL_float* Lx,
289
+ const QDLDL_float* Dinv,
290
+ QDLDL_float* x){
291
+
292
+ QDLDL_int i;
293
+
294
+ QDLDL_Lsolve(n,Lp,Li,Lx,x);
295
+ for(i = 0; i < n; i++) x[i] *= Dinv[i];
296
+ QDLDL_Ltsolve(n,Lp,Li,Lx,x);
297
+
298
+ }
@@ -0,0 +1,177 @@
1
+ #ifndef QDLDL_H
2
+ #define QDLDL_H
3
+
4
+ // Include qdldl type options
5
+ #include "qdldl_types.h"
6
+
7
+ # ifdef __cplusplus
8
+ extern "C" {
9
+ # endif // ifdef __cplusplus
10
+
11
+ /**
12
+ * Compute the elimination tree for a quasidefinite matrix
13
+ * in compressed sparse column form, where the input matrix is
14
+ * assumed to contain data for the upper triangular part of A only,
15
+ * and there are no duplicate indices.
16
+ *
17
+ * Returns an elimination tree for the factorization A = LDL^T and a
18
+ * count of the nonzeros in each column of L that are strictly below the
19
+ * diagonal.
20
+ *
21
+ * Does not use MALLOC. It is assumed that the arrays work, Lnz, and
22
+ * etree will be allocated with a number of elements equal to n.
23
+ *
24
+ * The data in (n,Ap,Ai) are from a square matrix A in CSC format, and
25
+ * should include the upper triangular part of A only.
26
+ *
27
+ * This function is only intended for factorisation of QD matrices specified
28
+ * by their upper triangular part. An error is returned if any column has
29
+ * data below the diagonal or s completely empty.
30
+ *
31
+ * For matrices with a non-empty column but a zero on the corresponding diagonal,
32
+ * this function will *not* return an error, as it may still be possible to factor
33
+ * such a matrix in LDL form. No promises are made in this case though...
34
+ *
35
+ * @param n number of columns in CSC matrix A (assumed square)
36
+ * @param Ap column pointers (size n+1) for columns of A
37
+ * @param Ai row indices of A. Has Ap[n] elements
38
+ * @param work work vector (size n) (no meaning on return)
39
+ * @param Lnz count of nonzeros in each column of L (size n) below diagonal
40
+ * @param etree elimination tree (size n)
41
+ * @return total sum of Lnz (i.e. total nonzeros in L below diagonal). Returns
42
+ * -1 if the input does not have triu structure or has an empty
43
+ * column.
44
+ *
45
+ *
46
+ */
47
+
48
+ QDLDL_int QDLDL_etree(const QDLDL_int n,
49
+ const QDLDL_int* Ap,
50
+ const QDLDL_int* Ai,
51
+ QDLDL_int* work,
52
+ QDLDL_int* Lnz,
53
+ QDLDL_int* etree);
54
+
55
+ /**
56
+ * Compute an LDL decomposition for a quasidefinite matrix
57
+ * in compressed sparse column form, where the input matrix is
58
+ * assumed to contain data for the upper triangular part of A only,
59
+ * and there are no duplicate indices.
60
+ *
61
+ * Returns factors L, D and Dinv = 1./D.
62
+ *
63
+ * Does not use MALLOC. It is assumed that L will be a compressed
64
+ * sparse column matrix with data (Ln,Lp,Li) with sufficient space
65
+ * allocated, with a number of nonzeros equal to the count given
66
+ * as a return value by osqp_ldl_etree
67
+ *
68
+ * @param n number of columns in L and A (both square)
69
+ * @param Ap column pointers (size n+1) for columns of A
70
+ * @param Ai row indices of A. Has Ap[n] elements
71
+ * @param Ln number of columns in CSC matrix L
72
+ * @param Lp column pointers (size Ln+1) for columns of L
73
+ * @param Li row indices of L. Has Lp[Ln] elements
74
+ * @param D vectorized factor D. Length is n
75
+ * @param Dinv reciprocal of D. Length is n
76
+ * @param Lnz count of nonzeros in each column of L below diagonal,
77
+ * as given by osqp_ldl_etree (not modified)
78
+ * @param etree elimination tree as as given by osqp_ldl_etree (not modified)
79
+ * @param bwork working array of bools. Length is n
80
+ * @param iwork working array of integers. Length is 3*n
81
+ * @param fwork working array of floats. Length is n
82
+ * @return Returns a count of the number of positive elements
83
+ * in D. Returns -1 and exits immediately if any element
84
+ * of D evaluates exactly to zero (matrix is not quasidefinite
85
+ * or otherwise LDL factorisable)
86
+ *
87
+ */
88
+
89
+
90
+ QDLDL_int QDLDL_factor(const QDLDL_int n,
91
+ const QDLDL_int* Ap,
92
+ const QDLDL_int* Ai,
93
+ const QDLDL_float* Ax,
94
+ QDLDL_int* Lp,
95
+ QDLDL_int* Li,
96
+ QDLDL_float* Lx,
97
+ QDLDL_float* D,
98
+ QDLDL_float* Dinv,
99
+ const QDLDL_int* Lnz,
100
+ const QDLDL_int* etree,
101
+ QDLDL_bool* bwork,
102
+ QDLDL_int* iwork,
103
+ QDLDL_float* fwork);
104
+
105
+
106
+ /**
107
+ * Solves LDL'x = b
108
+ *
109
+ * It is assumed that L will be a compressed
110
+ * sparse column matrix with data (Ln,Lp,Li).
111
+ *
112
+ * @param n number of columns in L (both square)
113
+ * @param Ln number of columns in CSC matrix L
114
+ * @param Lp column pointers (size Ln+1) for columns of L
115
+ * @param Li row indices of L. Has Lp[Ln] elements
116
+ * @param Dinv reciprocal of D. Length is n
117
+ * @param x initialized to b. Equal to x on return
118
+ *
119
+ *
120
+ */
121
+ void QDLDL_solve(const QDLDL_int n,
122
+ const QDLDL_int* Lp,
123
+ const QDLDL_int* Li,
124
+ const QDLDL_float* Lx,
125
+ const QDLDL_float* Dinv,
126
+ QDLDL_float* x);
127
+
128
+
129
+ /**
130
+ * Solves (L+I)x = b
131
+ *
132
+ * It is assumed that L will be a compressed
133
+ * sparse column matrix with data (Ln,Lp,Li).
134
+ *
135
+ * @param n number of columns in L (both square)
136
+ * @param Ln number of columns in CSC matrix L
137
+ * @param Lp column pointers (size Ln+1) for columns of L
138
+ * @param Li row indices of L. Has Lp[Ln] elements
139
+ * @param Dinv reciprocal of D. Length is n
140
+ * @param x initialized to b. Equal to x on return
141
+ *
142
+ *
143
+ */
144
+
145
+ void QDLDL_Lsolve(const QDLDL_int n,
146
+ const QDLDL_int* Lp,
147
+ const QDLDL_int* Li,
148
+ const QDLDL_float* Lx,
149
+ QDLDL_float* x);
150
+
151
+ /**
152
+ * Solves (L+I)'x = b
153
+ *
154
+ * It is assumed that L will be a compressed
155
+ * sparse column matrix with data (Ln,Lp,Li).
156
+ *
157
+ * @param n number of columns in L (both square)
158
+ * @param Ln number of columns in CSC matrix L
159
+ * @param Lp column pointers (size Ln+1) for columns of L
160
+ * @param Li row indices of L. Has Lp[Ln] elements
161
+ * @param Dinv reciprocal of D. Length is n
162
+ * @param x initialized to b. Equal to x on return
163
+ *
164
+ *
165
+ */
166
+
167
+ void QDLDL_Ltsolve(const QDLDL_int n,
168
+ const QDLDL_int* Lp,
169
+ const QDLDL_int* Li,
170
+ const QDLDL_float* Lx,
171
+ QDLDL_float* x);
172
+
173
+ # ifdef __cplusplus
174
+ }
175
+ # endif // ifdef __cplusplus
176
+
177
+ #endif // ifndef QDLDL_H
@@ -0,0 +1,21 @@
1
+ #ifndef QDLDL_TYPES_H
2
+ # define QDLDL_TYPES_H
3
+
4
+ #include "glbopts.h"
5
+
6
+ # ifdef __cplusplus
7
+ extern "C" {
8
+ # endif /* ifdef __cplusplus */
9
+
10
+ // QDLDL integer and float types
11
+
12
+ #define QDLDL_int scs_int
13
+ #define QDLDL_float scs_float
14
+ #define QDLDL_bool scs_int
15
+
16
+ # ifdef __cplusplus
17
+ }
18
+ # endif /* ifdef __cplusplus */
19
+
20
+ #endif /* ifndef QDLDL_TYPES_H */
21
+
@@ -0,0 +1,41 @@
1
+ #include "gpu.h"
2
+
3
+ void SCS(_accum_by_atrans_gpu)(const ScsGpuMatrix *Ag, const scs_float *x,
4
+ scs_float *y, cusparseHandle_t cusparse_handle) {
5
+ /* y += A'*x
6
+ x and y MUST be on GPU already
7
+ */
8
+ const scs_float onef = 1.0;
9
+ CUSPARSE(csrmv)
10
+ (cusparse_handle, CUSPARSE_OPERATION_NON_TRANSPOSE, Ag->n, Ag->m, Ag->Annz,
11
+ &onef, Ag->descr, Ag->x, Ag->p, Ag->i, x, &onef, y);
12
+ }
13
+
14
+ void SCS(_accum_by_a_gpu)(const ScsGpuMatrix *Ag, const scs_float *x,
15
+ scs_float *y, cusparseHandle_t cusparse_handle) {
16
+ /* y += A*x
17
+ x and y MUST be on GPU already
18
+ */
19
+ const scs_float onef = 1.0;
20
+ /* The A matrix idx pointers must be ORDERED */
21
+ CUSPARSE(csrmv)
22
+ (cusparse_handle, CUSPARSE_OPERATION_TRANSPOSE, Ag->n, Ag->m, Ag->Annz, &onef,
23
+ Ag->descr, Ag->x, Ag->p, Ag->i, x, &onef, y);
24
+ }
25
+
26
+ void SCS(free_gpu_matrix)(ScsGpuMatrix *A) {
27
+ cudaFree(A->x);
28
+ cudaFree(A->i);
29
+ cudaFree(A->p);
30
+ cusparseDestroyMatDescr(A->descr);
31
+ }
32
+
33
+ void SCS(normalize_a)(ScsMatrix *A, const ScsSettings *stgs, const ScsCone *k,
34
+ ScsScaling *scal) {
35
+ SCS(_normalize_a)(A, stgs, k, scal);
36
+ }
37
+
38
+ void SCS(un_normalize_a)(ScsMatrix *A, const ScsSettings *stgs,
39
+ const ScsScaling *scal) {
40
+ SCS(_un_normalize_a)(A, stgs, scal);
41
+ }