-
Notifications
You must be signed in to change notification settings - Fork 344
/
algebra_vector.h
295 lines (216 loc) · 9.99 KB
/
algebra_vector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
#ifndef ALGEBRA_VECTOR_H
#define ALGEBRA_VECTOR_H
# ifdef __cplusplus
extern "C" {
# endif /* ifdef __cplusplus */
#include "glob_opts.h"
/*
* OSQPVector[fi] types. Not defined here since it
* is implementation specific
*/
/* integer valued vectors */
typedef struct OSQPVectori_ OSQPVectori;
/* float valued vectors*/
typedef struct OSQPVectorf_ OSQPVectorf;
/* VECTOR FUNCTIONS ----------------------------------------------------------*/
# ifndef EMBEDDED
/* malloc/calloc for floats and ints (USES MALLOC/CALLOC) */
OSQPVectorf* OSQPVectorf_malloc(c_int length);
OSQPVectorf* OSQPVectorf_calloc(c_int length);
OSQPVectori* OSQPVectori_malloc(c_int length);
OSQPVectori* OSQPVectori_calloc(c_int length);
/* Return a float vector using a raw array as input (Uses MALLOC) */
OSQPVectorf* OSQPVectorf_new(const c_float *a, c_int length);
/* Return an in vector using a raw array as input (Uses MALLOC) */
OSQPVectori* OSQPVectori_new(const c_int *a, c_int length);
/* Return a copy of a float vector a as output (Uses MALLOC) */
OSQPVectorf* OSQPVectorf_copy_new(const OSQPVectorf *a);
/* Return a copy of an int vector a as output (Uses MALLOC) */
OSQPVectori* OSQPVectori_copy_new(const OSQPVectori *a);
/* Free a float vector */
void OSQPVectorf_free(OSQPVectorf *a);
/* Free an int vector */
void OSQPVectori_free(OSQPVectori *a);
/* Create subview of a larger vector. Internal data should not be freed.
* Behavior is otherwise identical to OSQPVectorf (Uses MALLOC)
*/
OSQPVectorf* OSQPVectorf_view(const OSQPVectorf *a, c_int head, c_int length);
/* Free a view of a float vector */
void OSQPVectorf_view_free(OSQPVectorf *a);
# endif /* ifndef EMBEDDED */
/* Length of the vector (floats) */
c_int OSQPVectorf_length(const OSQPVectorf *a);
/* Length of the vector (ints) */
c_int OSQPVectori_length(const OSQPVectori *a);
/* Pointer to vector data (floats) */
c_float* OSQPVectorf_data(const OSQPVectorf *a);
/* Pointer to vector data (ints) */
c_int* OSQPVectori_data(const OSQPVectori *a);
/* Copy a float vector a into another vector b (pre-allocated) */
void OSQPVectorf_copy(OSQPVectorf *b, const OSQPVectorf *a);
/* Copy an int vector a into another vector b (pre-allocated) */
void OSQPVectori_copy(OSQPVectori *b, const OSQPVectori *a);
/* Copy an array of floats into a into a vector b (pre-allocated) */
void OSQPVectorf_from_raw(OSQPVectorf *b, const c_float *a);
/* copy an array of ints into a into a vector b (pre-allocated) */
void OSQPVectori_from_raw(OSQPVectori *b, const c_int *a);
/* copy a vector into an array of floats (pre-allocated) */
void OSQPVectorf_to_raw(c_float *bv, const OSQPVectorf *a);
/* copy a vector into an array of ints (pre-allocated) */
void OSQPVectori_to_raw(c_int *bv, const OSQPVectori *a);
/* set float vector to scalar */
void OSQPVectorf_set_scalar(OSQPVectorf *a, c_float sc);
/* Set float vector to one of three scalars based on sign of vector of ints.
*/
void OSQPVectorf_set_scalar_conditional(OSQPVectorf *a,
OSQPVectori *test,
c_float val_if_neg,
c_float val_if_zero,
c_float val_if_pos);
/* set int vector to scalar */
void OSQPVectori_set_scalar(OSQPVectori *a, c_int sc);
/* add scalar to float vector */
void OSQPVectorf_add_scalar(OSQPVectorf *a, c_float sc);
/* add scalar to int vector */
void OSQPVectori_add_scalar(OSQPVectori *a, c_int sc);
/* multiply float vector by float */
void OSQPVectorf_mult_scalar(OSQPVectorf *a, c_float sc);
/* change sign */
void OSQPVectorf_negate(OSQPVectorf *a);
/* x = a + b. Set x == a for x += b. */
void OSQPVectorf_plus(OSQPVectorf *x,
const OSQPVectorf *a,
const OSQPVectorf *b);
/* x = a - b. Set x == a for x -= b. */
void OSQPVectorf_minus(OSQPVectorf *x,
const OSQPVectorf *a,
const OSQPVectorf *b);
/* x = sca*a + scb*b. Set (x == a, sca==1.) for x += scb*b. */
void OSQPVectorf_add_scaled(OSQPVectorf *x,
c_float sca,
const OSQPVectorf *a,
c_float scb,
const OSQPVectorf *b);
/* x = sca*a + scb*b + scc*c. Set (x == a, sca==1.) for x += scb*b scc*c. */
void OSQPVectorf_add_scaled3(OSQPVectorf *x,
c_float sca,
const OSQPVectorf *a,
c_float scb,
const OSQPVectorf *b,
c_float scc,
const OSQPVectorf *c);
/* ||v||_inf */
c_float OSQPVectorf_norm_inf(const OSQPVectorf *v);
/* ||v||_1 */
c_float OSQPVectorf_norm_1(const OSQPVectorf *v);
/* ||Sv||_inf */
c_float OSQPVectorf_scaled_norm_inf(const OSQPVectorf *S, const OSQPVectorf *v);
/* ||Sv||_1 */
c_float OSQPVectorf_scaled_norm_1(const OSQPVectorf *S, const OSQPVectorf *v);
/* ||a - b||_inf */
c_float OSQPVectorf_norm_inf_diff(const OSQPVectorf *a,
const OSQPVectorf *b);
/* sum of vector elements */
c_float OSQPVectorf_sum(const OSQPVectorf *a);
/* mean of vector elements */
c_float OSQPVectorf_mean(const OSQPVectorf *a);
/* Inner product a'b */
c_float OSQPVectorf_dot_prod(const OSQPVectorf *a,
const OSQPVectorf *b);
/* Inner product a'b, but using only the positive or negative
* terms in b. Use sign = 1 for positive terms, sign = -1 for
* negative terms. Setting any other value for sign will return
* the normal dot product
*/
c_float OSQPVectorf_dot_prod_signed(const OSQPVectorf *a,
const OSQPVectorf *b,
c_int sign);
/* elementwise product a.*b stored in c. Set c==a for c *= b*/
void OSQPVectorf_ew_prod(OSQPVectorf *c,
const OSQPVectorf *a,
const OSQPVectorf *b);
/* check l <= u elementwise. Returns 1 if inequality is true
* for every element pair in both vectors
*/
c_int OSQPVectorf_all_leq(OSQPVectorf *l, OSQPVectorf* u);
/* Elementwise bounding vectors x = min(max(z,l),u)
* It is acceptable to assign x = z in this call, so
* that x = min(max(x,l),u) is allowed
*/
void OSQPVectorf_ew_bound_vec(OSQPVectorf *x,
OSQPVectorf *z,
const OSQPVectorf *l,
const OSQPVectorf *u);
/* Elementwise projection of y onto the polar recession cone
of the set [l u]. Values of +/- infval or larger are
treated as infinite
*/
void OSQPVectorf_project_polar_reccone(OSQPVectorf *y,
const OSQPVectorf *l,
const OSQPVectorf *u,
c_float infval);
/* Elementwise test of whether y is in the polar recession
cone of the set [l u]. Values of +/- infval or larger are
treated as infinite. Values in y within tol of zero are treated
as zero.
*/
c_int OSQPVectorf_in_polar_reccone(const OSQPVectorf *y,
const OSQPVectorf *l,
const OSQPVectorf *u,
c_float infval,
c_float tol);
/* vector permutation x[:] = b(p[:]) */
void OSQPVectorf_permute(OSQPVectorf *x, const OSQPVectorf *b, const OSQPVectori *p);
void OSQPVectori_permute(OSQPVectori *x, const OSQPVectori *b, const OSQPVectori *p);
/* vector inverse permutation x(p[:]) = b */
void OSQPVectorf_ipermute(OSQPVectorf *x, const OSQPVectorf *b, const OSQPVectori *p);
void OSQPVectori_ipermute(OSQPVectori *x, const OSQPVectori *b, const OSQPVectori *p);
# if EMBEDDED != 1
/* Vector mean value*/
c_float OSQPVectorf_mean(const OSQPVectorf *a);
/* Vector elementwise reciprocal b = 1./a (needed for scaling)*/
void OSQPVectorf_ew_reciprocal( OSQPVectorf *b, const OSQPVectorf *a);
/* elementwise sqrt of the vector elements */
void OSQPVectorf_ew_sqrt(OSQPVectorf *a);
/* Elementwise maximum between vector and scalar c = max(a, sc) */
void OSQPVectorf_ew_max(OSQPVectorf *c, const OSQPVectorf *a, c_float sc);
/* Elementwise minimum between vector and scalar c = min(a, sc) */
void OSQPVectorf_ew_min(OSQPVectorf *c, const OSQPVectorf *a, c_float sc);
/* Elementwise maximum between vectors c = max(a, b) */
void OSQPVectorf_ew_max_vec(OSQPVectorf *c,
const OSQPVectorf *a,
const OSQPVectorf *b);
/* Elementwise minimum between vectors c = min(a, b) */
void OSQPVectorf_ew_min_vec(OSQPVectorf *c,
const OSQPVectorf *a,
const OSQPVectorf *b);
/* Elementwise check for constraint type.
if u[i] - l[i] < tol, iseq[i] = 1 otherwise iseq[i] = 0,
unless values exceed +/- infval, in which case marked
as iseq[i] = -1.
Returns 1 if any value in iseq has been modified. O otherwise.
*/
c_int OSQPVectorf_ew_bounds_type(OSQPVectori* iseq,
const OSQPVectorf* l,
const OSQPVectorf* u,
c_float tol,
c_float infval);
/* Elementwise replacement based on lt comparison.
x[i] = z[i] < testval ? newval : z[i];
*/
void OSQPVectorf_set_scalar_if_lt(OSQPVectorf *x,
const OSQPVectorf *z,
c_float testval,
c_float newval);
/* Elementwise replacement based on gt comparison.
* x[i] = z[i] > testval ? newval : z[i];
*/
void OSQPVectorf_set_scalar_if_gt(OSQPVectorf *x,
const OSQPVectorf *z,
c_float testval,
c_float newval);
# endif /* if EMBEDDED != 1 */
# ifdef __cplusplus
}
# endif /* ifdef __cplusplus */
#endif /* ifndef ALGEBRA_VECTOR_H */