Mercurial > hg > smallbox
comparison solvers/SMALL_ompGabor/myblas.h @ 140:31d2864dfdd4 ivand_dev
Audio Impainting additional constraints with cvx added
author | Ivan Damnjanovic lnx <ivan.damnjanovic@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 17:27:05 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
139:4bd6856a7128 | 140:31d2864dfdd4 |
---|---|
1 /************************************************************************** | |
2 * | |
3 * File name: myblas.h | |
4 * | |
5 * Ron Rubinstein | |
6 * Computer Science Department | |
7 * Technion, Haifa 32000 Israel | |
8 * ronrubin@cs | |
9 * | |
10 * Version: 1.1 | |
11 * Last updated: 17.8.2009 | |
12 * | |
13 * A collection of basic linear algebra functions, in the spirit of the | |
14 * BLAS/LAPACK libraries. | |
15 * | |
16 *************************************************************************/ | |
17 | |
18 | |
19 | |
20 #ifndef __MY_BLAS_H__ | |
21 #define __MY_BLAS_H__ | |
22 | |
23 | |
24 #include "mex.h" | |
25 #include <math.h> | |
26 | |
27 | |
28 | |
29 /************************************************************************** | |
30 * Squared value. | |
31 **************************************************************************/ | |
32 #define SQR(X) ((X)*(X)) | |
33 | |
34 | |
35 | |
36 /************************************************************************** | |
37 * Matrix-vector multiplication. | |
38 * | |
39 * Computes an operation of the form: | |
40 * | |
41 * y := alpha*A*x | |
42 * | |
43 * Parameters: | |
44 * A - matrix of size n X m | |
45 * x - vector of length m | |
46 * y - output vector of length n | |
47 * alpha - real constant | |
48 * n, m - dimensions of A | |
49 * | |
50 * Note: This function re-writes the contents of y. | |
51 * | |
52 **************************************************************************/ | |
53 void mat_vec(double alpha, double A[], double x[], double y[], mwSize n, mwSize m); | |
54 | |
55 | |
56 | |
57 /************************************************************************** | |
58 * Matrix-transpose-vector multiplication. | |
59 * | |
60 * Computes an operation of the form: | |
61 * | |
62 * y := alpha*A'*x | |
63 * | |
64 * Parameters: | |
65 * A - matrix of size n X m | |
66 * x - vector of length n | |
67 * y - output vector of length m | |
68 * alpha - real constant | |
69 * n, m - dimensions of A | |
70 * | |
71 * Note: This function re-writes the contents of y. | |
72 * | |
73 **************************************************************************/ | |
74 void matT_vec(double alpha, double A[], double x[], double y[], mwSize n, mwSize m); | |
75 | |
76 | |
77 | |
78 /************************************************************************** | |
79 * Sparse-matrix-vector multiplication. | |
80 * | |
81 * Computes an operation of the form: | |
82 * | |
83 * y := alpha*A*x | |
84 * | |
85 * where A is a sparse matrix. | |
86 * | |
87 * Parameters: | |
88 * pr,ir,jc - sparse representation of the matrix A, of size n x m | |
89 * x - vector of length m | |
90 * y - output vector of length n | |
91 * alpha - real constant | |
92 * n, m - dimensions of A | |
93 * | |
94 * Note: This function re-writes the contents of y. | |
95 * | |
96 **************************************************************************/ | |
97 void mat_sp_vec(double alpha, double pr[], mwIndex ir[], mwIndex jc[], double x[], double y[], mwSize n, mwSize m); | |
98 | |
99 | |
100 | |
101 /************************************************************************** | |
102 * Sparse-matrix-transpose-vector multiplication. | |
103 * | |
104 * Computes an operation of the form: | |
105 * | |
106 * y := alpha*A'*x | |
107 * | |
108 * where A is a sparse matrix. | |
109 * | |
110 * Parameters: | |
111 * pr,ir,jc - sparse representation of the matrix A, of size n x m | |
112 * x - vector of length m | |
113 * y - output vector of length n | |
114 * alpha - real constant | |
115 * n, m - dimensions of A | |
116 * | |
117 * Note: This function re-writes the contents of y. | |
118 * | |
119 **************************************************************************/ | |
120 void matT_sp_vec(double alpha, double pr[], mwIndex ir[], mwIndex jc[], double x[], double y[], mwSize n, mwSize m); | |
121 | |
122 | |
123 | |
124 /************************************************************************** | |
125 * Matrix-sparse-vector multiplication. | |
126 * | |
127 * Computes an operation of the form: | |
128 * | |
129 * y := alpha*A*x | |
130 * | |
131 * where A is a matrix and x is a sparse vector. | |
132 * | |
133 * Parameters: | |
134 * A - matrix of size n X m | |
135 * pr,ir,jc - sparse representation of the vector x, of length m | |
136 * y - output vector of length n | |
137 * alpha - real constant | |
138 * n, m - dimensions of A | |
139 * | |
140 * Note: This function re-writes the contents of y. | |
141 * | |
142 **************************************************************************/ | |
143 void mat_vec_sp(double alpha, double A[], double pr[], mwIndex ir[], mwIndex jc[], double y[], mwSize n, mwSize m); | |
144 | |
145 | |
146 | |
147 /************************************************************************** | |
148 * Matrix-transpose-sparse-vector multiplication. | |
149 * | |
150 * Computes an operation of the form: | |
151 * | |
152 * y := alpha*A'*x | |
153 * | |
154 * where A is a matrix and x is a sparse vector. | |
155 * | |
156 * Parameters: | |
157 * A - matrix of size n X m | |
158 * pr,ir,jc - sparse representation of the vector x, of length n | |
159 * y - output vector of length m | |
160 * alpha - real constant | |
161 * n, m - dimensions of A | |
162 * | |
163 * Note: This function re-writes the contents of y. | |
164 * | |
165 **************************************************************************/ | |
166 void matT_vec_sp(double alpha, double A[], double pr[], mwIndex ir[], mwIndex jc[], double y[], mwSize n, mwSize m); | |
167 | |
168 | |
169 | |
170 /************************************************************************** | |
171 * Sparse-matrix-sparse-vector multiplication. | |
172 * | |
173 * Computes an operation of the form: | |
174 * | |
175 * y := alpha*A*x | |
176 * | |
177 * where A is a sparse matrix and x is a sparse vector. | |
178 * | |
179 * Parameters: | |
180 * pr,ir,jc - sparse representation of the matrix A, of size n x m | |
181 * prx,irx,jcx - sparse representation of the vector x (of length m) | |
182 * y - output vector of length n | |
183 * alpha - real constant | |
184 * n, m - dimensions of A | |
185 * | |
186 * Note: This function re-writes the contents of y. | |
187 * | |
188 **************************************************************************/ | |
189 void mat_sp_vec_sp(double alpha, double pr[], mwIndex ir[], mwIndex jc[], double prx[], mwIndex irx[], mwIndex jcx[], double y[], mwSize n, mwSize m); | |
190 | |
191 | |
192 | |
193 /************************************************************************** | |
194 * Sparse-matrix-transpose-sparse-vector multiplication. | |
195 * | |
196 * Computes an operation of the form: | |
197 * | |
198 * y := alpha*A'*x | |
199 * | |
200 * where A is a sparse matrix and x is a sparse vector. | |
201 * | |
202 * Importnant note: this function is provided for completeness, but is NOT efficient. | |
203 * If possible, convert x to non-sparse representation and use matT_vec_sp instead. | |
204 * | |
205 * Parameters: | |
206 * pr,ir,jc - sparse representation of the matrix A, of size n x m | |
207 * prx,irx,jcx - sparse representation of the vector x (of length n) | |
208 * y - output vector of length n | |
209 * alpha - real constant | |
210 * n, m - dimensions of A | |
211 * | |
212 * Note: This function re-writes the contents of y. | |
213 * | |
214 **************************************************************************/ | |
215 void matT_sp_vec_sp(double alpha, double pr[], mwIndex ir[], mwIndex jc[], double prx[], mwIndex irx[], mwIndex jcx[], double y[], mwSize n, mwSize m); | |
216 | |
217 | |
218 | |
219 /************************************************************************** | |
220 * Matrix-matrix multiplication. | |
221 * | |
222 * Computes an operation of the form: | |
223 * | |
224 * X := alpha*A*B | |
225 * | |
226 * Parameters: | |
227 * A - matrix of size n X m | |
228 * B - matrix of size m X k | |
229 * X - output matrix of size n X k | |
230 * alpha - real constant | |
231 * n, m, k - dimensions of A, B | |
232 * | |
233 * Note: This function re-writes the contents of X. | |
234 * | |
235 **************************************************************************/ | |
236 void mat_mat(double alpha, double A[], double B[], double X[], mwSize n, mwSize m, mwSize k); | |
237 | |
238 | |
239 | |
240 /************************************************************************** | |
241 * Matrix-transpose-matrix multiplication. | |
242 * | |
243 * Computes an operation of the form: | |
244 * | |
245 * X := alpha*A*B | |
246 * | |
247 * Parameters: | |
248 * A - matrix of size n X m | |
249 * B - matrix of size m X k | |
250 * X - output matrix of size n X k | |
251 * alpha - real constant | |
252 * n, m, k - dimensions of A, B | |
253 * | |
254 * Note: This function re-writes the contents of X. | |
255 * | |
256 **************************************************************************/ | |
257 void matT_mat(double alpha, double A[], double B[], double X[], mwSize n, mwSize m, mwSize k); | |
258 | |
259 | |
260 | |
261 /************************************************************************** | |
262 * Tensor-matrix multiplication. | |
263 * | |
264 * This function accepts a 3-D tensor A of size n X m X k | |
265 * and a 2-D matrix B of size l X k. | |
266 * The function computes the 3-D tensor X of size n X m X l, where | |
267 * | |
268 * X(i,j,:) = B*A(i,j,:) | |
269 * | |
270 * for all i,j. | |
271 * | |
272 * Parameters: | |
273 * A - tensor of size n X m X k | |
274 * B - matrix of size l X k | |
275 * X - output tensor of size n X m X l | |
276 * alpha - real constant | |
277 * n, m, k, l - dimensions of A, B | |
278 * | |
279 * Note: This function re-writes the contents of X. | |
280 * | |
281 **************************************************************************/ | |
282 void tens_mat(double alpha, double A[], double B[], double X[], mwSize n, mwSize m, mwSize k, mwSize l); | |
283 | |
284 | |
285 | |
286 /************************************************************************** | |
287 * Tensor-matrix-transpose multiplication. | |
288 * | |
289 * This function accepts a 3-D tensor A of size n X m X k | |
290 * and a 2-D matrix B of size k X l. | |
291 * The function computes the 3-D tensor X of size n X m X l, where | |
292 * | |
293 * X(i,j,:) = B'*A(i,j,:) | |
294 * | |
295 * for all i,j. | |
296 * | |
297 * Parameters: | |
298 * A - tensor of size n X m X k | |
299 * B - matrix of size k X l | |
300 * X - output tensor of size n X m X l | |
301 * alpha - real constant | |
302 * n, m, k, l - dimensions of A, B | |
303 * | |
304 * Note: This function re-writes the contents of X. | |
305 * | |
306 **************************************************************************/ | |
307 void tens_matT(double alpha, double A[], double B[], double X[], mwSize n, mwSize m, mwSize k, mwSize l); | |
308 | |
309 | |
310 | |
311 /************************************************************************** | |
312 * Vector-vector sum. | |
313 * | |
314 * Computes an operation of the form: | |
315 * | |
316 * y := alpha*x + y | |
317 * | |
318 * Parameters: | |
319 * x - vector of length n | |
320 * y - output vector of length n | |
321 * alpha - real constant | |
322 * n - length of x,y | |
323 * | |
324 * Note: This function re-writes the contents of y. | |
325 * | |
326 **************************************************************************/ | |
327 void vec_sum(double alpha, double x[], double y[], mwSize n); | |
328 | |
329 /************************************************************************** | |
330 * Vector-vector scalar multiply. | |
331 * | |
332 * Computes an operation of the form: | |
333 * | |
334 * y := alpha* x.*y | |
335 * | |
336 * Parameters: | |
337 * x - vector of length n | |
338 * y - output vector of length n | |
339 * alpha - real constant | |
340 * n - length of x,y | |
341 * | |
342 * Note: This function re-writes the contents of y. | |
343 * | |
344 **************************************************************************/ | |
345 | |
346 | |
347 void vec_smult(double alpha, double x[], double y[], mwSize n); | |
348 | |
349 | |
350 /************************************************************************** | |
351 * Triangular back substitution. | |
352 * | |
353 * Solve the set of linear equations | |
354 * | |
355 * T*x = b | |
356 * | |
357 * where T is lower or upper triangular. | |
358 * | |
359 * Parameters: | |
360 * ul - 'U' for upper triangular, 'L' for lower triangular | |
361 * A - matrix of size n x m containing T | |
362 * b - vector of length k | |
363 * x - output vector of length k | |
364 * n - size of first dimension of A | |
365 * k - the size of the equation set, k<=n,m | |
366 * | |
367 * Note: | |
368 * The matrix A can be of any size n X m, as long as n,m >= k. | |
369 * Only the lower/upper triangle of the submatrix A(1:k,1:k) defines the | |
370 * matrix T (depending on the parameter ul). | |
371 * | |
372 **************************************************************************/ | |
373 void backsubst(char ul, double A[], double b[], double x[], mwSize n, mwSize k); | |
374 | |
375 | |
376 | |
377 /************************************************************************** | |
378 * Solve a set of equations using a Cholesky decomposition. | |
379 * | |
380 * Solve the set of linear equations | |
381 * | |
382 * M*x = b | |
383 * | |
384 * where M is positive definite with a known Cholesky decomposition: | |
385 * either M=L*L' (L lower triangular) or M=U'*U (U upper triangular). | |
386 * | |
387 * Parameters: | |
388 * ul - 'U' for upper triangular, 'L' for lower triangular decomposition | |
389 * A - matrix of size n x m with the Cholesky decomposition of M | |
390 * b - vector of length k | |
391 * x - output vector of length k | |
392 * n - size of first dimension of A | |
393 * k - the size of the equation set, k<=n,m | |
394 * | |
395 * Note: | |
396 * The matrix A can be of any size n X m, as long as n,m >= k. | |
397 * Only the lower/upper triangle of the submatrix A(1:k,1:k) is used as | |
398 * the Cholesky decomposition of M (depending on the parameter ul). | |
399 * | |
400 **************************************************************************/ | |
401 void cholsolve(char ul, double A[], double b[], double x[], mwSize n, mwSize k); | |
402 | |
403 | |
404 | |
405 /************************************************************************** | |
406 * Maximum absolute value. | |
407 * | |
408 * Returns the index of the coefficient with maximal absolute value in a vector. | |
409 * | |
410 * Parameters: | |
411 * x - vector of length n | |
412 * n - length of x | |
413 * | |
414 **************************************************************************/ | |
415 mwIndex maxabs(double x[], mwSize n); | |
416 | |
417 | |
418 | |
419 /************************************************************************** | |
420 * Maximum vector element. | |
421 * | |
422 * Returns the index of the maximal coefficient in a vector. | |
423 * | |
424 * Parameters: | |
425 * x - vector of length n | |
426 * n - length of x | |
427 * | |
428 **************************************************************************/ | |
429 mwIndex maxpos(double x[], mwSize n); | |
430 | |
431 | |
432 | |
433 /************************************************************************** | |
434 * Vector-vector dot product. | |
435 * | |
436 * Computes an operation of the form: | |
437 * | |
438 * c = a'*b | |
439 * | |
440 * Parameters: | |
441 * a, b - vectors of length n | |
442 * n - length of a,b | |
443 * | |
444 * Returns: The dot product c. | |
445 * | |
446 **************************************************************************/ | |
447 double dotprod(double a[], double b[], mwSize n); | |
448 | |
449 | |
450 | |
451 /************************************************************************** | |
452 * Indexed vector assignment. | |
453 * | |
454 * Perform a permutation assignment of the form | |
455 * | |
456 * y = x(ind) | |
457 * | |
458 * where ind is an array of indices to x. | |
459 * | |
460 * Parameters: | |
461 * y - output vector of length k | |
462 * x - input vector of arbitrary length | |
463 * ind - array of indices into x (indices begin at 0) | |
464 * k - length of the array ind | |
465 * | |
466 **************************************************************************/ | |
467 void vec_assign(double y[], double x[], mwIndex ind[], mwSize k); | |
468 | |
469 | |
470 | |
471 /************************************************************************** | |
472 * Matrix transpose. | |
473 * | |
474 * Computes Y := X' | |
475 * | |
476 * Parameters: | |
477 * X - input matrix of size n X m | |
478 * Y - output matrix of size m X n | |
479 * n, m - dimensions of X | |
480 * | |
481 **************************************************************************/ | |
482 void transpose(double X[], double Y[], mwSize n, mwSize m); | |
483 | |
484 | |
485 | |
486 /************************************************************************** | |
487 * Print a matrix. | |
488 * | |
489 * Parameters: | |
490 * A - matrix of size n X m | |
491 * n, m - dimensions of A | |
492 * matname - name of matrix to display | |
493 * | |
494 **************************************************************************/ | |
495 void printmat(double A[], int n, int m, char* matname); | |
496 | |
497 | |
498 | |
499 /************************************************************************** | |
500 * Print a sparse matrix. | |
501 * | |
502 * Parameters: | |
503 * A - sparse matrix of type double | |
504 * matname - name of matrix to display | |
505 * | |
506 **************************************************************************/ | |
507 void printspmat(mxArray *A, char* matname); | |
508 | |
509 | |
510 #endif | |
511 |