H2Lib  3.0
amatrix.h
Go to the documentation of this file.
1 
2 /* ------------------------------------------------------------
3  * This is the file "amatrix.h" of the H2Lib package.
4  * All rights reserved, Steffen Boerm 2009
5  * ------------------------------------------------------------ */
6 
11 #ifndef AMATRIX_H
12 #define AMATRIX_H
13 
23 typedef struct _amatrix amatrix;
24 
26 typedef amatrix *pamatrix;
27 
29 typedef const amatrix *pcamatrix;
30 
31 #include <assert.h>
32 #include <math.h>
33 #include <stdlib.h>
34 
35 #include "basic.h"
36 #include "settings.h"
37 #include "blas.h"
38 #include "avector.h"
39 #include "realavector.h"
40 #include "krylov.h"
41 
43 struct _amatrix {
45  field *a;
46 
49 
54 
56  void *owner;
57 };
58 
59 /* ------------------------------------------------------------ *
60  * Constructors and destructors *
61  * ------------------------------------------------------------ */
62 
76 
97  uint coff);
98 
114 
131 
145 
161 
168 HEADER_PREFIX void
170 
182 
201 new_sub_amatrix(pamatrix src, uint rows, uint roff, uint cols, uint coff);
202 
212 
225 
239 
249 HEADER_PREFIX void
251 
265 HEADER_PREFIX void
267 
283 HEADER_PREFIX void
285 
286 /* ------------------------------------------------------------
287  Access methods
288  ------------------------------------------------------------ */
289 
290 #ifdef __GNUC__
292 getentry_amatrix(pcamatrix, uint, uint) __attribute__ ((const,unused));
293 INLINE_PREFIX void
294 setentry_amatrix(pamatrix, uint, uint, field) __attribute__((unused));
296 addentry_amatrix(pamatrix, uint, uint, field) __attribute__((unused));
297 #endif
298 
306  longindex lda = a->ld;
307 #ifdef FULL_DEBUG
308  assert(row < a->rows);
309  assert(col < a->cols);
310 #endif
311 
312  return a->a[row + lda * col];
313 }
314 
321 INLINE_PREFIX void setentry_amatrix(pamatrix a, uint row, uint col, field x) {
322  longindex lda = a->ld;
323 #ifdef FULL_DEBUG
324  assert(row < a->rows);
325  assert(col < a->cols);
326 #endif
327 
328  a->a[row + lda * col] = x;
329 }
330 
338 INLINE_PREFIX field addentry_amatrix(pamatrix a, uint row, uint col, field x) {
339  longindex lda = a->ld;
340 #ifdef FULL_DEBUG
341  assert(row < a->rows);
342  assert(col < a->cols);
343 #endif
344 
345  return (a->a[row + lda * col] += x);
346 }
347 
348 /* ------------------------------------------------------------
349  Statistics
350  ------------------------------------------------------------ */
351 
362 HEADER_PREFIX uint
364 
375 HEADER_PREFIX size_t
377 
388 HEADER_PREFIX size_t
390 
391 /* ------------------------------------------------------------
392  Simple utility functions
393  ------------------------------------------------------------ */
394 
398 HEADER_PREFIX void
399 clear_amatrix(pamatrix a);
400 
406 HEADER_PREFIX void
407 clear_lower_amatrix(pamatrix a, bool strict);
408 
414 HEADER_PREFIX void
415 clear_upper_amatrix(pamatrix a, bool strict);
416 
423 HEADER_PREFIX void
424 identity_amatrix(pamatrix a);
425 
429 HEADER_PREFIX void
430 random_amatrix(pamatrix a);
431 
440 HEADER_PREFIX void
441 random_invertible_amatrix(pamatrix a, real alpha);
442 
446 HEADER_PREFIX void
447 random_selfadjoint_amatrix(pamatrix a);
448 
459 HEADER_PREFIX void
460 random_spd_amatrix(pamatrix a, real alpha);
461 
470 HEADER_PREFIX void
471 copy_amatrix(bool atrans, pcamatrix a, pamatrix b);
472 
483 HEADER_PREFIX void
484 copy_colpiv_amatrix(bool atrans, pcamatrix a, const uint *colpiv,
485  pamatrix b);
486 
491 HEADER_PREFIX pamatrix
493 
505 HEADER_PREFIX void
506 copy_sub_amatrix(bool atrans, pcamatrix a, pamatrix b);
507 
511 HEADER_PREFIX void
513 
517 HEADER_PREFIX void
519 
531 check_ortho_amatrix(bool atrans, pcamatrix a);
532 
533 /* ------------------------------------------------------------
534  Basic linear algebra
535  ------------------------------------------------------------ */
536 
542 HEADER_PREFIX void
543 scale_amatrix(field alpha, pamatrix a);
544 
550 HEADER_PREFIX void
551 conjugate_amatrix(pamatrix a);
552 
564 
575 
585 
595 
608 
620 HEADER_PREFIX void
622 
634 HEADER_PREFIX void
636  pavector trg);
637 
650 HEADER_PREFIX void
651 mvm_amatrix_avector(field alpha, bool atrans, pcamatrix a, pcavector src,
652  pavector trg);
653 
661 HEADER_PREFIX void
662 add_amatrix(field alpha, bool atrans, pcamatrix a, pamatrix b);
663 
678 HEADER_PREFIX void
679 addmul_amatrix(field alpha, bool atrans, pcamatrix a, bool btrans, pcamatrix b,
680  pamatrix c);
681 
698 HEADER_PREFIX void
699 bidiagmul_amatrix(field alpha, bool atrans, pamatrix a, pcavector d,
700  pcavector l);
701 
704 #endif
pamatrix init_amatrix(pamatrix a, uint rows, uint cols)
Initialize an amatrix object.
void copy_colpiv_amatrix(bool atrans, pcamatrix a, const uint *colpiv, pamatrix b)
Copy a matrix into another matrix, permuting the columns, i.e., or .
real normfrob2_amatrix(pcamatrix a)
Compute the squared Frobenius norm of a matrix .
size_t longindex
Unsigned long type.
Definition: settings.h:88
void resize_amatrix(pamatrix a, uint rows, uint cols)
Change the dimensions of an amatrix object without preserving its coefficients.
void addeval_amatrix_avector(field alpha, pcamatrix a, pcavector src, pavector trg)
Multiply a matrix by a vector , .
amatrix * pamatrix
Pointer to amatrix object.
Definition: amatrix.h:26
void uninit_amatrix(pamatrix a)
Uninitialize an amatrix object.
Definition: avector.h:39
pamatrix new_amatrix(uint rows, uint cols)
Create a new amatrix object.
pamatrix clone_amatrix(pcamatrix src)
Create a duplicate of an existing amatrix.
field * a
Matrix coefficients in column-major order, i.e., corresponds to a[i+j*ld].
Definition: amatrix.h:45
void random_amatrix(pamatrix a)
Fill a matrix with random values.
void random_invertible_amatrix(pamatrix a, real alpha)
Fill a square matrix with random values and ensure that it is invertible.
void mvm_amatrix_avector(field alpha, bool atrans, pcamatrix a, pcavector src, pavector trg)
Multiply a matrix or its adjoint by a vector, or .
uint getactives_amatrix()
Get number of currently initialized amatrix objects.
unsigned uint
Unsigned integer type.
Definition: settings.h:70
void add_amatrix(field alpha, bool atrans, pcamatrix a, pamatrix b)
Add two matrices, or .
field getentry_amatrix(pcamatrix a, uint row, uint col)
Read a matrix entry .
Definition: amatrix.h:305
real norm2diff_amatrix(pcamatrix a, pcamatrix b)
Approximate the spectral norm of the difference of two matrices and .
pamatrix new_sub_amatrix(pamatrix src, uint rows, uint roff, uint cols, uint coff)
Create a new amatrix object representing a submatrix.
void copy_sub_amatrix(bool atrans, pcamatrix a, pamatrix b)
Copy a matrix into another matrix, or .
double _Complex field
Field type.
Definition: settings.h:171
real check_ortho_amatrix(bool atrans, pcamatrix a)
Check whether a matrix or its adjoint is isometric.
void resizecopy_amatrix(pamatrix a, uint rows, uint cols)
Change the dimensions of an amatrix object while preserving as many of its coefficients as possible...
field dotprod_amatrix(pcamatrix a, pcamatrix b)
Compute the Frobenius inner product of two matrices and .
pamatrix new_identity_amatrix(uint rows, uint cols)
Create a new amatrix object representing the identity.
const amatrix * pcamatrix
Pointer to constant amatrix object.
Definition: amatrix.h:29
uint rows
Number of rows.
Definition: amatrix.h:51
#define INLINE_PREFIX
Prefix for inline functions.
Definition: settings.h:36
pamatrix new_pointer_amatrix(field *src, uint rows, uint cols)
Create a new amatrix object using a given array for the coefficients.
void conjugate_amatrix(pamatrix a)
compute the complex conjugate of a matrix .
void addevaltrans_amatrix_avector(field alpha, pcamatrix a, pcavector src, pavector trg)
Multiply the adjoint of a matrix by a vector , .
pamatrix init_sub_amatrix(pamatrix a, pamatrix src, uint rows, uint roff, uint cols, uint coff)
Initialize an amatrix object to represent a submatrix.
void clear_amatrix(pamatrix a)
Set a matrix to zero.
void del_amatrix(pamatrix a)
Delete an amatrix object.
size_t getsize_amatrix(pcamatrix a)
Get size of a given amatrix object.
void bidiagmul_amatrix(field alpha, bool atrans, pamatrix a, pcavector d, pcavector l)
Multiply a matrix by a bidiagonal matrix, or .
pamatrix init_vec_amatrix(pamatrix a, pavector src, uint rows, uint cols)
Initialize an amatrix object by a vector.
void identity_amatrix(pamatrix a)
Set a matrix to identity.
size_t getsize_heap_amatrix(pcamatrix a)
Get heap size of a given amatrix object.
void clear_lower_amatrix(pamatrix a, bool strict)
Set the lower triangular part of a matrix to zero.
void random_spd_amatrix(pamatrix a, real alpha)
Fill a matrix with random values and ensure that it is positive definite.
uint ld
Leading dimension, i.e., increment used to switch from one column to the next.
Definition: amatrix.h:48
#define HEADER_PREFIX
Prefix for function declarations.
Definition: settings.h:43
pamatrix init_pointer_amatrix(pamatrix a, pfield src, uint rows, uint cols)
Initialize an amatrix object using a given array for the coefficients.
double real
real floating point type.
Definition: settings.h:97
void scale_amatrix(field alpha, pamatrix a)
Scale a matrix by a factor , .
void addmul_amatrix(field alpha, bool atrans, pcamatrix a, bool btrans, pcamatrix b, pamatrix c)
Multiply two matrices, , , or .
void setentry_amatrix(pamatrix a, uint row, uint col, field x)
Set a matrix entry, .
Definition: amatrix.h:321
void clear_upper_amatrix(pamatrix a, bool strict)
Set the upper triangular part of a matrix to zero.
void print_amatrix(pcamatrix a)
Print a matrix.
field * pfield
Pointer to field array.
Definition: settings.h:185
void print_matlab_amatrix(pcamatrix a)
Print a matrix in Matlab format.
void copy_amatrix(bool atrans, pcamatrix a, pamatrix b)
Copy a matrix into another matrix, or .
pamatrix init_identity_amatrix(pamatrix a, uint rows, uint cols)
Initialize an amatrix object and set it to identity.
real normfrob_amatrix(pcamatrix a)
Compute the Frobenius norm of a matrix .
Representation of a matrix as an array in column-major order.
Definition: amatrix.h:43
uint cols
Number of columns.
Definition: amatrix.h:53
pamatrix init_zero_amatrix(pamatrix a, uint rows, uint cols)
Initialize an amatrix object and set it to zero.
void * owner
Points to owner of coefficient storage if this is a submatrix.
Definition: amatrix.h:56
pamatrix new_zero_amatrix(uint rows, uint cols)
Create a new amatrix object representing a zero matrix.
real norm2_amatrix(pcamatrix A)
Approximate the spectral norm of a matrix .
field addentry_amatrix(pamatrix a, uint row, uint col, field x)
Add to a matrix entry, .
Definition: amatrix.h:338
void random_selfadjoint_amatrix(pamatrix a)
Fill a matrix with random values and ensure that it is self-adjoint.