QPALM main
Proximal Augmented Lagrangian method for Quadratic Programs
Loading...
Searching...
No Matches
lin_alg.h
Go to the documentation of this file.
1/**
2 * @file lin_alg.h
3 * @author Ben Hermans
4 * @brief Linear algebra with vectors.
5 * @details Common operations, such as vector products, infinity norm, elementwise
6 * add/product/division/max etc. are included in this file.
7 */
8
9#ifndef LIN_ALG_H
10# define LIN_ALG_H
11
12
13# ifdef __cplusplus
14extern "C" {
15# endif
16
17# include "types.h"
19
20/**
21 * @name Vector functions
22 * @{
23 */
24
25/**
26 * Copy vector a into output.
27 * @warning This function uses malloc.
28 * @param a Vector
29 * @param n Vector length
30 * @return Copy of a
31 */
32c_float* vec_copy(const c_float *a,
33 size_t n);
34
35/**
36 * Copy vector a into preallocated vector b.
37 *
38 * @param a Input vector
39 * @param b Output vector
40 * @param n Vector length
41 */
42void prea_vec_copy(const c_float *a,
43 c_float *b,
44 size_t n);
45
46/**
47 * Copy integer vector a into preallocated vector b.
48 *
49 * @param a Input vector
50 * @param b Output vector
51 * @param n Vector length
52 */
53void prea_int_vec_copy(const c_int *a,
54 c_int *b,
55 size_t n);
56
57/**
58 * Fill float vector with a scalar value.
59 *
60 * @param a Vector
61 * @param sc Value
62 * @param n Vector length
63 */
65 c_float sc,
66 size_t n);
67
68/**
69 * Fill int vector with a scalar value.
70 *
71 * @param a Vector
72 * @param sc Value
73 * @param n Vector length
74 */
76 c_int sc,
77 size_t n);
78
79/**
80 * Mulitply vector with a constant scale factor.
81 *
82 * @param a Vector
83 * @param sc Value
84 * @param n Vector length
85 */
87 c_float sc,
88 size_t n);
89
90/**
91 * Mulitply vector with a constant scale factor and store in a different vector.
92 *
93 * @param a Input vector
94 * @param sc Value
95 * @param b Output vector
96 * @param n Vector length
97 */
98void vec_mult_scalar(const c_float *a,
99 c_float sc,
100 c_float *b,
101 size_t n);
102
103/**
104 * Inner product between two vectors, @f$a^T \cdot b@f$.
105 *
106 * @param a Vector
107 * @param b Vector
108 * @param n Vector length
109 * @return Result of the inner product
110 */
111c_float vec_prod(const c_float *a,
112 const c_float *b,
113 size_t n);
114
115/**
116 * 2-norm of a vector, @f$\|a\|_2@f$.
117 *
118 * @param a Vector
119 * @param n Vector length
120 * @return 2-norm of a
121 */
122c_float vec_norm_two( const c_float *a,
123 size_t n);
124
125/**
126 * Infinity norm of a vector, @f$\|a\|_\infty@f$
127 *
128 * @param a Vector
129 * @param n Vector length
130 * @return Infinity norm of a
131 */
133 size_t n);
134
135/**
136 * Scaled addition of one vector to another vector, @f$c_i = a_i + sc\cdot b_i@f$
137 *
138 * @param a Input vector
139 * @param b Input vector
140 * @param c Output vector
141 * @param sc Scaling value
142 * @param n Vector length
143 * */
144void vec_add_scaled(const c_float *a,
145 const c_float *b,
146 c_float *c,
147 c_float sc,
148 size_t n);
149
150/**
151 * Scaled addition of one vector to another vector, both being scaled, @f$a_i = sc1\cdot a_i + sc2\cdot b_i@f$
152 *
153 * @param a Input and Output vector
154 * @param b Input vector
155 * @param sc1 Scaling value for a
156 * @param sc2 Scaling value for b
157 * @param n Vector length
158 * */
160 const c_float *b,
161 c_float sc1,
162 c_float sc2,
163 size_t n);
164
165/**
166 * Elementwise reciprocal @f$b_i = 1/a_i@f$.
167 *
168 * This function is used in scaling.
169 *
170 * @param a Input vector
171 * @param b Output vector
172 * @param n Vector length
173 */
174void vec_ew_recipr(const c_float *a,
175 c_float *b,
176 size_t n);
177
178/**
179 * Elementwise maximum between vectors, @f$c_i = \textrm{max}(a_i, b_i)@f$.
180 *
181 * @param a Input vector
182 * @param b Input vector
183 * @param c Output vector
184 * @param n Vector length
185 */
186void vec_ew_max_vec(const c_float *a,
187 const c_float *b,
188 c_float *c,
189 size_t n);
190
191/**
192 * Elementwise minimum between vectors, @f$c_i = \textrm{min}(a_i, b_i)@f$.
193 *
194 * @param a Input vector
195 * @param b Input vector
196 * @param c Output vector
197 * @param n Vector length
198 */
199void vec_ew_min_vec(const c_float *a,
200 const c_float *b,
201 c_float *c,
202 size_t n);
203
204/**
205 * Elementwise mid between vectors, @f$c_i = \textrm{max}(b_{\textrm{min},i}, \textrm{min}(a_i, b_{\textrm{max},i}))@f$.
206 *
207 * @param a Input vector
208 * @param bmin Lower bounds
209 * @param bmax Upper bounds
210 * @param c Output vector
211 * @param n Vector length
212 */
213void vec_ew_mid_vec(const c_float *a,
214 const c_float *bmin,
215 const c_float *bmax,
216 c_float *c,
217 size_t n);
218
219/**
220 * Elementwise product, @f$c_i = a_i\cdot b_i@f$.
221 *
222 * @param a Input vector
223 * @param b Input vector
224 * @param c Output vector
225 * @param n Vector length
226 */
227void vec_ew_prod(const c_float *a,
228 const c_float *b,
229 c_float *c,
230 size_t n);
231
232/**
233 * Elementwise division, @f$c_i = a_i/b_i@f$.
234 *
235 * @param a Input vector
236 * @param b Input vector
237 * @param c Output vector
238 * @param n Vector length
239 */
240void vec_ew_div(const c_float *a,
241 const c_float *b,
242 c_float *c,
243 size_t n);
244
245/**
246 * Elementwise square root, @f$b_i = \sqrt{a_i}@f$
247 *
248 * @param a Input vector
249 * @param b Output vector
250 * @param n Vector length
251 */
252void vec_ew_sqrt(const c_float *a,
253 c_float *b,
254 size_t n);
255
256
257/**
258 * @}
259 */
260
261/* MATRIX FUNCTIONS ----------------------------------------------------------*/
262
263/* Moved to solver_interface.c*/
264
265
266# ifdef __cplusplus
267}
268# endif
269
270#endif // ifndef LIN_ALG_H
ladel_int c_int
type for integer numbers
Definition global_opts.h:42
ladel_double c_float
type for floating point numbers
Definition global_opts.h:41
void vec_add_scaled(const c_float *a, const c_float *b, c_float *c, c_float sc, size_t n)
Scaled addition of one vector to another vector, .
Definition lin_alg.c:110
c_float * vec_copy(const c_float *a, size_t n)
Copy vector a into output.
Definition lin_alg.c:11
void vec_ew_min_vec(const c_float *a, const c_float *b, c_float *c, size_t n)
Elementwise minimum between vectors, .
Definition lin_alg.c:192
void vec_mult_scalar(const c_float *a, c_float sc, c_float *b, size_t n)
Mulitply vector with a constant scale factor and store in a different vector.
Definition lin_alg.c:64
void vec_set_scalar(c_float *a, c_float sc, size_t n)
Fill float vector with a scalar value.
Definition lin_alg.c:40
void vec_ew_max_vec(const c_float *a, const c_float *b, c_float *c, size_t n)
Elementwise maximum between vectors, .
Definition lin_alg.c:184
void vec_ew_div(const c_float *a, const c_float *b, c_float *c, size_t n)
Elementwise division, .
Definition lin_alg.c:101
void vec_set_scalar_int(c_int *a, c_int sc, size_t n)
Fill int vector with a scalar value.
Definition lin_alg.c:48
void vec_mult_add_scaled(c_float *a, const c_float *b, c_float sc1, c_float sc2, size_t n)
Scaled addition of one vector to another vector, both being scaled, .
Definition lin_alg.c:118
void vec_self_mult_scalar(c_float *a, c_float sc, size_t n)
Mulitply vector with a constant scale factor.
Definition lin_alg.c:56
void vec_ew_mid_vec(const c_float *a, const c_float *bmin, const c_float *bmax, c_float *c, size_t n)
Elementwise mid between vectors, .
Definition lin_alg.c:200
void vec_ew_prod(const c_float *a, const c_float *b, c_float *c, size_t n)
Elementwise product, .
Definition lin_alg.c:92
c_float vec_prod(const c_float *a, const c_float *b, size_t n)
Inner product between two vectors, .
Definition lin_alg.c:72
c_float vec_norm_two(const c_float *a, size_t n)
2-norm of a vector, .
Definition lin_alg.c:88
void prea_vec_copy(const c_float *a, c_float *b, size_t n)
Copy vector a into preallocated vector b.
Definition lin_alg.c:24
c_float vec_norm_inf(const c_float *a, size_t n)
Infinity norm of a vector, .
Definition lin_alg.c:126
void prea_int_vec_copy(const c_int *a, c_int *b, size_t n)
Copy integer vector a into preallocated vector b.
Definition lin_alg.c:32
void vec_ew_recipr(const c_float *a, c_float *b, size_t n)
Elementwise reciprocal .
Definition lin_alg.c:176
void vec_ew_sqrt(const c_float *a, c_float *b, size_t n)
Elementwise square root, .
Definition lin_alg.c:208
Interface and wrapper to matrix/factorization (ladel) functions.
Internal data structures used in QPALM.