Data Structures | |
| struct | EGdMatrix_t |
| structure to hold a dense matrix, we choose a row representation of the matrix, and we allow row and column permutations. All actual values in the matrix are stored in EGdMatrix_t::matval, and the rows in EGdMatrix_t::matrow. More... | |
Files | |
| file | eg_dmatrix.c |
| file | eg_dmatrix.ex.c |
This file shows some examples of the use of EGdMatrix_t structure and functions. as a test-set we use the Hilber Matrix wich is a matrix with coefficients
| |
| file | eg_dmatrix.h |
This file provide the user interface and function definitions for Dense Matrices. | |
Defines | |
| #define | EGdMatrixAddColMultiple(__dmatrix, __dest, __orig, __num) |
| Given a number '__num' and a two rows '__orig', '__dest', set columns '__dest' to '__dest' + '__orig' * '__num'. Note that the number MUST_NOT be stored in column '__dest', and note that columns '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works. | |
| #define | EGdMatrixAddRowMultiple(__dmatrix, __dest, __orig, __num) |
| Given a number '__num' and a two rows '__orig', '__dest', set rows '__dest' to '__dest' + '__orig' * '__num'. Note that the number MUST_NOT be stored in row '__dest', and note that rows '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works. | |
| #define | EGdMatrixClear(__dmatrix) |
| Clear a dense matrix structure, i.e. free all internally allocated data of the structure. Note that no further use of the structure can be made unless it is re-initialized and set to a suitable size. | |
| #define | EGdMatrixDisplay(__dmatrix, __nat_order, __ofile) |
| Display a given EGdMatrix_t structure contents. | |
| #define | EGdMatrixInit(__dmatrix) memset(__dmatrix,0,sizeof(EGdMatrix_t)) |
| Initialize (as a dense matrix of dimension 0x0) an EGdMatrix_t structure. | |
| #define | EGdMatrixMultiplyCol(__dmatrix, __colind, __mult) |
| Given a number and a column, multiply the complete column by the given number. Note that the number MUST_NOT be stored in the column being multiplied, this is because of the way GNU_MP interface works. | |
| #define | EGdMatrixMultiplyRow(__dmatrix, row_ind, multiple) |
| Given a number and a row, multiply the complete row by the given number. Note that the number MUST_NOT be stored in the row being multiplied, this is because of the way GNU_MP interface works. | |
| #define | EGdMatrixSetDimension(__dmatrix, __nnewrows, __nnewcols) |
| Set new dimensions for a dense matrix structure. | |
| #define | EGdMatrixSubColMultiple(__dmatrix, __dest, __orig, __num) |
| Given a number '__num' and a two rows '__orig', '__dest', set columns '__dest' to '__dest' - '__orig' * '__num'. Note that the number MUST_NOT be stored in column '__dest', and note that columns '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works. | |
| #define | EGdMatrixSubRowMultiple(__dmatrix, __dest, __orig, __num) |
| Given a number '__num' and a two rows '__orig', '__dest', set rows '__dest' to '__dest' - '__orig' * '__num'. Note that the number MUST_NOT be stored in row '__dest', and note that rows '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works. | |
| #define | HILBERT_TABLE_SIZE 9U |
| size of the table of eigenvalues of the hilbert matrix | |
Typedefs | |
| typedef struct EGdMatrix_t | EGdMatrix_t |
| structure to hold a dense matrix, we choose a row representation of the matrix, and we allow row and column permutations. All actual values in the matrix are stored in EGdMatrix_t::matval, and the rows in EGdMatrix_t::matrow. | |
Functions | |
| int | dmatrix_parseargs (int argc, char **argv, size_t *n, size_t *m) |
| parse the input argumenbts for the program | |
| void | dmatrix_usage (char *program) |
| display the usage message for this program | |
| int | EGdMatrixGaussianElimination (EGdMatrix_t *const __dmatrix, const unsigned do_col_perm, const unsigned do_row_perm, unsigned *const rank, const EGlpNum_t zero_tol, int *const status) |
| This function performs gaussian elimination to the given matrix, depending on the given options it may do row/columns permutations allong the way to improve numerical stabillity. | |
| int | main (int argc, char **argv) |
| main function | |
Variables | |
| static unsigned | dmatrix_hilbert_eigenvalues [HILBERT_TABLE_SIZE] |
| table containing 1/eigenvalues of the hilbert matrix. | |
Here we define a common interface for dense matrices (i.e. a structure), and some common operations over dense matrices. The definition uses EGlpNum as reference number type, this allow for template initializations.
| #define EGdMatrixAddColMultiple | ( | __dmatrix, | ||
| __dest, | ||||
| __orig, | ||||
| __num | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ const size_t __EGdest = (__dest);\ const size_t __EGori = (__orig);\ size_t __EGdmj = __EGdm->row_sz;\ while(__EGdmj--) \ EGlpNumAddInnProdTo(__EGdm->matrow[__EGdmj][__EGdest],\ __EGdm->matrow[__EGdmj][__EGori],__num);\ } while(0)
Given a number '__num' and a two rows '__orig', '__dest', set columns '__dest' to '__dest' + '__orig' * '__num'. Note that the number MUST_NOT be stored in column '__dest', and note that columns '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works.
| __dmatrix | dense matrix structure pointer. | |
| '__orig' | index of the column whose multiple will be added to the '__dest' column. | |
| '__dest' | column to be replaced by '__dest' + '__orig' * '__num'. | |
| '__num' | constant to be multiply to the '__orig' and be added to the '__dest' column. |
Definition at line 238 of file eg_dmatrix.h.
| #define EGdMatrixAddRowMultiple | ( | __dmatrix, | ||
| __dest, | ||||
| __orig, | ||||
| __num | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ const size_t __EGdest = (size_t)(__dest);\ const size_t __EGori = (size_t)(__orig);\ size_t __EGdmj = __EGdm->col_sz;\ while(__EGdmj--) \ EGlpNumAddInnProdTo(__EGdm->matrow[__EGdest][__EGdmj],\ __EGdm->matrow[__EGori][__EGdmj],__num);\ } while(0)
Given a number '__num' and a two rows '__orig', '__dest', set rows '__dest' to '__dest' + '__orig' * '__num'. Note that the number MUST_NOT be stored in row '__dest', and note that rows '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works.
| __dmatrix | dense matrix structure pointer. | |
| '__orig' | index of the row whose multiple will be added to the '__dest' row. | |
| '__dest' | row to be replaced by '__dest' + '__orig' * '__num'. | |
| '__num' | constant to be multiply to the '__orig' and be added to the '__dest' row. |
Definition at line 165 of file eg_dmatrix.h.
| #define EGdMatrixClear | ( | __dmatrix | ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ EGlpNumFreeArray(__EGdm->matval);\ EGfree(__EGdm->matrow);\ int_EGlpNumFreeArray(__EGdm->col_ord);\ int_EGlpNumFreeArray(__EGdm->row_ord);} while(0)
Clear a dense matrix structure, i.e. free all internally allocated data of the structure. Note that no further use of the structure can be made unless it is re-initialized and set to a suitable size.
| __dmatrix | dense matrix structure pointer. |
Definition at line 82 of file eg_dmatrix.h.
Referenced by main().
| #define EGdMatrixDisplay | ( | __dmatrix, | ||
| __nat_order, | ||||
| __ofile | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ char* __EGdmstr = 0;\ size_t __EGdmi, __EGdmj;\ fprintf(__ofile,"Matrix %p\nDimensions: %zd rows, %zd columns\n", (void*)__EGdm, __EGdm->row_sz, __EGdm->col_sz);\ if(__nat_order){\ for(__EGdmi = 0 ; __EGdmi < __EGdm->row_sz ; __EGdmi++){\ for(__EGdmj = 0 ; __EGdmj < __EGdm->col_sz ; __EGdmj++){\ __EGdmstr = EGlpNumGetStr(__EGdm->matrow[__EGdmi][__EGdmj]);\ fprintf(__ofile,"%10s ", __EGdmstr);\ EGfree(__EGdmstr);\ }\ fprintf(__ofile,"\n");}\ } else {\ for(__EGdmi = 0 ; __EGdmi < __EGdm->row_sz ; __EGdmi++){\ for(__EGdmj = 0 ; __EGdmj < __EGdm->col_sz ; __EGdmj++){\ __EGdmstr = EGlpNumGetStr(__EGdm->matrow[__EGdm->row_ord[__EGdmi]][__EGdm->col_ord[__EGdmj]]);\ fprintf(__ofile,"%10s ", __EGdmstr);\ EGfree(__EGdmstr);\ }\ fprintf(__ofile,"\n");}\ }} while(0)
Display a given EGdMatrix_t structure contents.
| __dmatrix | dense matrix structure pointer. | |
| __nat_order | if set to one, display the matrix using the natural internal order, i.e. we discard the order of columns and rows as defined in EGdMatrix_t::col_ord and EGdMatrix_t::row_ord. Otherwise, use such orders. | |
| __ofile | pointer to a FILE structure where we want the output to be printed. |
Definition at line 124 of file eg_dmatrix.h.
Referenced by main().
| #define EGdMatrixInit | ( | __dmatrix | ) | memset(__dmatrix,0,sizeof(EGdMatrix_t)) |
Initialize (as a dense matrix of dimension 0x0) an EGdMatrix_t structure.
| __dmatrix | dense matrix structure pointer. |
Definition at line 74 of file eg_dmatrix.h.
Referenced by main().
| #define EGdMatrixMultiplyCol | ( | __dmatrix, | ||
| __colind, | ||||
| __mult | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ const size_t __EGdmi = (__colind);\ size_t __EGdmj = __EGdm->row_sz;\ while(__EGdmj--) EGlpNumMultTo(__EGdm->matrow[__EGdmj][__EGdmi],__mult);\ } while(0)
Given a number and a column, multiply the complete column by the given number. Note that the number MUST_NOT be stored in the column being multiplied, this is because of the way GNU_MP interface works.
| __dmatrix | dense matrix structure pointer. | |
| __colind | index of the column being multiplied, note that we will multiply the column stored in EGdMatrix_t::matrow[*][__colind], wich is different to say that we multiply the column in the __colind-th position in the column ordering (to do that, then __colind should be EGdMatrix_t::col_ord[k]). | |
| __mult | constant to be multiply to the column. |
Definition at line 287 of file eg_dmatrix.h.
| #define EGdMatrixMultiplyRow | ( | __dmatrix, | ||
| row_ind, | ||||
| multiple | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ const size_t __EGdmi = (row_ind);\ size_t __EGdmj = __EGdm->col_sz;\ while(__EGdmj--) EGlpNumMultTo(__EGdm->matrow[__EGdmi][__EGdmj],multiple);\ } while(0)
Given a number and a row, multiply the complete row by the given number. Note that the number MUST_NOT be stored in the row being multiplied, this is because of the way GNU_MP interface works.
| __dmatrix | dense matrix structure pointer. | |
| row_ind | index of the row being multiplied, note that we will multiply the row stored in EGdMatrix_t::matrow[row_ind], wich is different to say that we multiply the row in the row_ind-th position in the row ordering (to do that, then row_ind should be EGdMatrix_t::row_ord[k]). | |
| multiple | constant to be multiply to the row. |
Definition at line 213 of file eg_dmatrix.h.
| #define EGdMatrixSetDimension | ( | __dmatrix, | ||
| __nnewrows, | ||||
| __nnewcols | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ register int __EGdmi;\ __EGdm->col_sz = (__nnewcols);\ __EGdm->row_sz = (__nnewrows);\ EGlpNumReallocArray(&(__EGdm->matval),__EGdm->col_sz * __EGdm->row_sz);\ EGrealloc(__EGdm->matrow,__EGdm->row_sz * sizeof(EGlpNum_t*));\ int_EGlpNumReallocArray(&(__EGdm->col_ord),__EGdm->col_sz);\ int_EGlpNumReallocArray(&(__EGdm->row_ord),__EGdm->row_sz);\ __EGdmi = (int)(__EGdm->col_sz);\ while(__EGdmi--) __EGdm->col_ord[__EGdmi] = __EGdmi;\ __EGdmi = (int)(__EGdm->row_sz);\ while(__EGdmi--) \ __EGdm->matrow[__EGdmi] = __EGdm->matval + ((size_t)(__EGdmi) * __EGdm->col_sz);\ __EGdmi = (int)(__EGdm->row_sz);\ while(__EGdmi--) __EGdm->row_ord[__EGdmi] = __EGdmi;} while(0)
Set new dimensions for a dense matrix structure.
| __dmatrix | dense matrix structure pointer. | |
| __nnewrows | number of rows in the matrix. | |
| __nnewcols | number of columns in the matrix. |
Definition at line 98 of file eg_dmatrix.h.
Referenced by main().
| #define EGdMatrixSubColMultiple | ( | __dmatrix, | ||
| __dest, | ||||
| __orig, | ||||
| __num | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ const size_t __EGdest = (size_t)(__dest);\ const size_t __EGori = (size_t)(__orig);\ size_t __EGdmj = __EGdm->row_sz;\ while(__EGdmj--) \ EGlpNumSubInnProdTo(__EGdm->matrow[__EGdmj][__EGdest],\ __EGdm->matrow[__EGdmj][__EGori],__num);\ } while(0)
Given a number '__num' and a two rows '__orig', '__dest', set columns '__dest' to '__dest' - '__orig' * '__num'. Note that the number MUST_NOT be stored in column '__dest', and note that columns '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works.
| __dmatrix | dense matrix structure pointer. | |
| '__orig' | index of the column whose multiple will be added to the '__dest' column. | |
| '__dest' | column to be replaced by '__dest' - '__orig' * '__num'. | |
| '__num' | constant to be multiply to the '__orig' and be added to the '__dest' column. |
Definition at line 266 of file eg_dmatrix.h.
| #define EGdMatrixSubRowMultiple | ( | __dmatrix, | ||
| __dest, | ||||
| __orig, | ||||
| __num | ||||
| ) |
do{\ EGdMatrix_t*const __EGdm = (__dmatrix);\ const size_t __EGdest = (__dest);\ const size_t __EGori = (__orig);\ size_t __EGdmj = __EGdm->col_sz;\ while(__EGdmj--) \ EGlpNumSubInnProdTo(__EGdm->matrow[__EGdest][__EGdmj],\ __EGdm->matrow[__EGori][__EGdmj],__num);\ } while(0)
Given a number '__num' and a two rows '__orig', '__dest', set rows '__dest' to '__dest' - '__orig' * '__num'. Note that the number MUST_NOT be stored in row '__dest', and note that rows '__orig' and '__dest' should be different. This is needed because of the way GNU_MP interface works.
| __dmatrix | dense matrix structure pointer. | |
| '__orig' | index of the row whose multiple will be added to the '__dest' row. | |
| '__dest' | row to be replaced by '__dest' - '__orig' * '__num'. | |
| '__num' | constant to be multiply to the '__orig' and be added to the '__dest' row. |
Definition at line 193 of file eg_dmatrix.h.
| #define HILBERT_TABLE_SIZE 9U |
size of the table of eigenvalues of the hilbert matrix
Definition at line 45 of file eg_dmatrix.ex.c.
Referenced by main().
| typedef struct EGdMatrix_t EGdMatrix_t |
structure to hold a dense matrix, we choose a row representation of the matrix, and we allow row and column permutations. All actual values in the matrix are stored in EGdMatrix_t::matval, and the rows in EGdMatrix_t::matrow.
| int dmatrix_parseargs | ( | int | argc, | |
| char ** | argv, | |||
| size_t * | n, | |||
| size_t * | m | |||
| ) |
parse the input argumenbts for the program
Definition at line 74 of file eg_dmatrix.ex.c.
References dmatrix_usage().
Referenced by main().

| void dmatrix_usage | ( | char * | program | ) |
display the usage message for this program
Definition at line 63 of file eg_dmatrix.ex.c.
Referenced by dmatrix_parseargs().
| int EGdMatrixGaussianElimination | ( | EGdMatrix_t *const | dmatrix, | |
| const unsigned | do_col_perm, | |||
| const unsigned | do_row_perm, | |||
| unsigned *const | ext_rank, | |||
| const EGlpNum_t | zero_tol, | |||
| int *const | ext_status | |||
| ) |
This function performs gaussian elimination to the given matrix, depending on the given options it may do row/columns permutations allong the way to improve numerical stabillity.
| __dmatrix | dense matrix structure pointer. | |
| do_col_perm | if set to one, the try columns permutation to improve numericall stabillity, otherwise, not do column permutations at all. | |
| do_row_perm | if set to one, try row permutations to improve numericall stabillity, otherwise, not do row permutations at all. | |
| status | pointer to where return an status, if the procedure finish all the way (i.e. the matrix is full rank), then we return EG_ALGSTAT_SUCCESS, if the matrix is found to be partial rank, the status is EG_ALGSTAT_PARTIAL, otherwise, we return EG_ALGSTAT_NUMERROR, wich means that we stoped because a zero pivot was found (after checking for allowed row/collumns permmutations). | |
| rank | where to return the (proven) rank of the matrix. This number is accurate if the status is EG_ALGSTAT_SUCCESS, or EG_ALGSTAT_PARTIAL, but is just a lower bound if the status is EG_ALGSTAT_NUMERROR | |
| zero_tol | What is the threshold for a value to be considered zero. |
Referenced by main().
| int main | ( | int | argc, | |
| char ** | argv | |||
| ) |
main function
Definition at line 109 of file eg_dmatrix.ex.c.
References CHECKRVALG, EGdMatrix_t::col_ord, dmatrix_hilbert_eigenvalues, dmatrix_parseargs(), EGdBsRed(), EGdBsRedAddElement, EGdBsRedClear, EGdBsRedInit, EGdBsRedProfile, EGdBsRedSetLength, EGdMatrixClear, EGdMatrixDisplay, EGdMatrixGaussianElimination(), EGdMatrixInit, EGdMatrixSetDimension, EGlib_info(), EGlib_version(), EGlpNumClear(), EGlpNumStart(), EGmin, EGsetLimits(), EGsigSet, HILBERT_TABLE_SIZE, EGdMatrix_t::matrow, MESSAGE, and EGdMatrix_t::row_ord.

unsigned dmatrix_hilbert_eigenvalues[HILBERT_TABLE_SIZE] [static] |
{
1U,
12U,
180U,
2800U,
44100U,
698544U,
11099088U,
176679360U,
2815827300U
}
table containing 1/eigenvalues of the hilbert matrix.
Definition at line 49 of file eg_dmatrix.ex.c.
Referenced by main().
1.7.1