The Original CHomP Software
|
A class for representing sparse matrices containing elements of the 'euclidom' type. More...
#include <chains.h>
Public Member Functions | |
mmatrix () | |
The default constructor. More... | |
mmatrix (const mmatrix< euclidom > &m) | |
The copy constructor. More... | |
mmatrix< euclidom > & | operator= (const mmatrix< euclidom > &s) |
The assignment operator. More... | |
~mmatrix () | |
The destructor of a matrix. More... | |
void | define (int_t numrows, int_t numcols) |
Defines the number of rows and columns and increases the internal tables if necessary. More... | |
void | identity (int_t size) |
Defines the matrix to be the identity of the given size. More... | |
void | add (int_t row, int_t col, const euclidom &e) |
Adds a value to the given element of the matrix. More... | |
euclidom | get (int_t row, int_t col) const |
Returns the value at the desired location of the matrix. More... | |
const chain< euclidom > & | getrow (int_t n) const |
Returns a reference to the entire row stored as a chain. More... | |
const chain< euclidom > & | getcol (int_t n) const |
Returns a reference to the entire column stored as a chain. More... | |
int_t | getnrows () const |
Returns the number of rows in the matrix. More... | |
int_t | getncols () const |
Returns the number of columns in the matrix. More... | |
void | addrow (int_t dest, int_t source, const euclidom &e) |
Adds one row to another with a given coefficient. More... | |
void | addcol (int_t dest, int_t source, const euclidom &e) |
Adds one column to another with a given coefficient. More... | |
void | swaprows (int_t i, int_t j) |
Swaps two rows of the matrix. More... | |
void | swapcols (int_t i, int_t j) |
Swaps two columns of the matrix. More... | |
void | multiplyrow (int_t n, const euclidom &e) |
Multiplies the row by the given coefficient and updates columns. More... | |
void | multiplycol (int_t n, const euclidom &e) |
Multiplies the column by the given coefficient and updates rows. More... | |
int_t | findrow (int_t req_elements=1, int_t start=-1) const |
Finds a row containing at least the required number of nonzero elements, starting at the given row. More... | |
int_t | findcol (int_t req_elements=1, int_t start=-1) const |
Finds a column containing at least the required number of nonzero elements, starting at the given column. More... | |
int_t | reducerow (int_t n, int_t preferred) |
Reduces the given row of the matrix and updates its columns. More... | |
int_t | reducecol (int_t n, int_t preferred) |
Reduces the given column of the matrix and updates its rows. More... | |
void | simple_reductions (bool quiet=false) |
Runs some random simple reductions. More... | |
void | simple_form (bool quiet=false) |
Transforms the matrix to a simple form (nearly SNF). More... | |
int_t | arrange_towards_SNF (int_t *invertible_count=0) |
Swaps rows and columns to make the simple form closer to SNF. More... | |
void | simple_form_to_SNF (bool quiet=false) |
Transforms the matrix from the simple form to actual SNF. More... | |
void | invert (void) |
Inverts the matrix. Throws an error message on failure. More... | |
void | multiply (const mmatrix< euclidom > &m1, const mmatrix< euclidom > &m2) |
Computes the product of the two given matrices. More... | |
void | submatrix (const mmatrix< euclidom > &matr, const chain< euclidom > &domain, const chain< euclidom > &range) |
Extracts a submatrix from the given matrix. More... | |
outputstream & | show_hom_col (outputstream &out, int_t col, const chain< euclidom > &range, const char *txt=NULL) const |
Writes a column with only these coefficients which exist in 'range', and shows their positions in that chain. More... | |
std::ostream & | show_hom_col (std::ostream &out, int_t col, const chain< euclidom > &range, const char *txt=NULL) const |
Writes a column with only these coefficients which exist in 'range', and shows their positions in that chain. More... | |
outputstream & | showrowscols (outputstream &out, chain< euclidom > *table, int_t tablen, int_t first=0, int_t howmany=0, const char *label=NULL) const |
Writes the matrix to an output stream by its rows or columns. More... | |
outputstream & | showrows (outputstream &out, int_t first=0, int_t howmany=0, const char *label="Row ") const |
Writes the matrix to an output stream by its rows. More... | |
std::ostream & | showrows (std::ostream &out, int_t first=0, int_t howmany=0, const char *label="Row ") const |
Writes the matrix to an output stream by its rows. More... | |
outputstream & | showcols (outputstream &out, int_t first=0, int_t howmany=0, const char *label="Col ") const |
Writes the matrix to an output stream by its rows. More... | |
std::ostream & | showcols (std::ostream &out, int_t first=0, int_t howmany=0, const char *label="Col ") const |
Writes the matrix to an output stream by its rows. More... | |
outputstream & | showmap (outputstream &out, const char *maplabel=NULL, const char *xlabel=NULL, const char *ylabel=NULL) const |
Writes the matrix as a linear map on generators. More... | |
std::ostream & | showmap (std::ostream &out, const char *maplabel=NULL, const char *xlabel=NULL, const char *ylabel=NULL) const |
Writes the matrix as a linear map on generators. More... | |
Public Attributes | |
simplelist< mmatrix< euclidom > > | dom_dom |
This is a list of matrices to be updated together with the changes to the columns or rows of the current matrix. More... | |
simplelist< mmatrix< euclidom > > | dom_img |
simplelist< mmatrix< euclidom > > | img_dom |
simplelist< mmatrix< euclidom > > | img_img |
Private Member Functions | |
int_t | findrowcol (int_t req_elements, int_t start, int which) const |
An internal procedure for both findrow and findcol. More... | |
void | increase (int_t numrows, int_t numcols) |
Increases tables to be enough to keep the given number of columns and rows. More... | |
void | increaserows (int_t numrows) |
Increases tables to be enough to keep the given number of rows. More... | |
void | increasecols (int_t numcols) |
Increases tables to be enough to keep the given number of columns. More... | |
void | division_SNF_correction (const euclidom &a, int_t pos1, const euclidom &b, int_t pos2) |
Makes a correction of division in the "diagonal" at the given two positions, so that the entry at pos1 divides the one at pos2. More... | |
void | mult_left (const int_t setRows[], const int_t setCols[], const mmatrix< euclidom > &M, const mmatrix< euclidom > &invM, bool update_linked) |
Multiplies the matrix from the left by an invertible square matrix whose possibly nonzero entries are only in the given rows and columns. More... | |
void | mult_right (const int_t setRows[], const int_t setCols[], const mmatrix< euclidom > &M, const mmatrix< euclidom > &invM, bool update_linked) |
Multiplies the matrix from the right by an invertible square matrix whose possibly nonzero entries are only in the given rows and columns. More... | |
Static Private Member Functions | |
static void | extendedGCD (const euclidom &a, const euclidom &b, euclidom &x, euclidom &y) |
Extended Euclidean algorithm for the computation of the greatest common divisor, together with the coefficients that satisfy the Bezout's identity ax + by = gcd (a,b). More... | |
Private Attributes | |
int_t | nrows |
The number of rows in the matrix. More... | |
int_t | ncols |
The number of columns in the matrix. More... | |
int_t | allrows |
The number of allocated rows. More... | |
int_t | allcols |
The number of allocated columns. More... | |
chain< euclidom > * | rows |
The rows of the matrix. More... | |
chain< euclidom > * | cols |
The columns of the matrix. More... | |
A class for representing sparse matrices containing elements of the 'euclidom' type.
This class has very specific functionality to be used mainly for the purpose of homology computation.
|
inline |
The default constructor.
Definition at line 1347 of file chains.h.
|
inline |
The copy constructor.
Added by Marcin Zelawski and fixed by Pawel Pilarczyk.
Definition at line 1381 of file chains.h.
References chomp::homology::mmatrix< euclidom >::allcols, chomp::homology::mmatrix< euclidom >::allrows, chomp::homology::mmatrix< euclidom >::ncols, and chomp::homology::mmatrix< euclidom >::nrows.
|
inline |
|
inline |
Adds a value to the given element of the matrix.
Definition at line 1468 of file chains.h.
|
inline |
Adds one column to another with a given coefficient.
Updates all the matrices which are linked to this one.
Definition at line 1572 of file chains.h.
|
inline |
Adds one row to another with a given coefficient.
Updates all the matrices which are linked to this one.
Definition at line 1545 of file chains.h.
|
inline |
Swaps rows and columns to make the simple form closer to SNF.
After these changes, all the invertible coefficients are gathered at the beginning of the "diagonal" and are made equal 1, and the noninvertible coefficients are moved to follow them along the "diagonal". Updates all the matrices which are linked to this one. If given a nonzero pointer, saves the number of invertible entries at the "diagonal". Returns the number of nonzero entries at the "diagonal". WARNING: SEEMS NOT TO WORK CORRECTLY AT THE MOMENT.
Definition at line 2062 of file chains.h.
|
inline |
Defines the number of rows and columns and increases the internal tables if necessary.
Useful for creating large zero matrices.
Definition at line 1364 of file chains.h.
|
inlineprivate |
Makes a correction of division in the "diagonal" at the given two positions, so that the entry at pos1 divides the one at pos2.
Note that pos1 must be smaller than pos2. This procedure is based upon the suggestions at http://en.wikipedia.org/wiki/Smith_normal_form. Updates all the matrices which are linked to this one.
Definition at line 2144 of file chains.h.
|
inlinestaticprivate |
Extended Euclidean algorithm for the computation of the greatest common divisor, together with the coefficients that satisfy the Bezout's identity ax + by = gcd (a,b).
Based upon http://en.wikipedia.org/wiki/Extended_Euclidean_algorithm (section "Formal description of the algorithm", subsection "Iterative method").
Definition at line 2400 of file chains.h.
|
inline |
Finds a column containing at least the required number of nonzero elements, starting at the given column.
If 'req_elements' is set to -1 then looks for a zero column. Returns the number of the column satisfying the desired property, or -1 if not found.
Definition at line 1759 of file chains.h.
|
inline |
Finds a row containing at least the required number of nonzero elements, starting at the given row.
If 'req_elements' is set to -1 then looks for a zero row. Returns the number of the row satisfying the desired property, or -1 if not found.
|
inlineprivate |
An internal procedure for both findrow and findcol.
The value of which is: row = 1, col = 0.
Definition at line 1685 of file chains.h.
|
inline |
Returns the value at the desired location of the matrix.
If 'row' or 'col' is set to -1, gets the first element in it or returns 0 if the colum/row is empty.
Definition at line 1495 of file chains.h.
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
|
inlineprivate |
Increases tables to be enough to keep the given number of columns and rows.
This function does not set 'nrows' and 'ncols'.
Definition at line 2598 of file chains.h.
|
inlineprivate |
Increases tables to be enough to keep the given number of columns.
|
inlineprivate |
Increases tables to be enough to keep the given number of rows.
|
inline |
Inverts the matrix. Throws an error message on failure.
Definition at line 2428 of file chains.h.
|
inlineprivate |
Multiplies the matrix from the left by an invertible square matrix whose possibly nonzero entries are only in the given rows and columns.
The matrix provided for multiplication consists only of the selected rows and columns, numbered sequentially from 0. If it is known that the matrix to be multiplied has nonzero entries in the given rows only in the given columns then this information can be provided to speed up the multiplication. If requested, updates the matrices linked to this one.
Definition at line 2204 of file chains.h.
|
inlineprivate |
Multiplies the matrix from the right by an invertible square matrix whose possibly nonzero entries are only in the given rows and columns.
The matrix provided for multiplication consists only of the selected rows and columns, numbered sequentially from 0. If it is known that the matrix to be multiplied has nonzero entries in the given columns only in the given rows then this information can be provided to speed up the multiplication. If requested, updates the matrices linked to this one.
Definition at line 2302 of file chains.h.
|
inline |
Computes the product of the two given matrices.
The matrix is replaced with the product.
Definition at line 2502 of file chains.h.
|
inline |
Multiplies the column by the given coefficient and updates rows.
Definition at line 1669 of file chains.h.
|
inline |
Multiplies the row by the given coefficient and updates columns.
|
inline |
The assignment operator.
Added by Marcin Zelawski and fixed by Pawel Pilarczyk.
Definition at line 1412 of file chains.h.
|
inline |
Reduces the given column of the matrix and updates its rows.
A preferred number of a row to leave is given. Updates all the matrices which are linked to this one. Returns the number of the row to be reduced next, or -1 if done.
Definition at line 1817 of file chains.h.
|
inline |
Reduces the given row of the matrix and updates its columns.
A preferred number of a column to leave is given. Updates all the matrices which are linked to this one. Returns the number of the column to be reduced next, or -1 if done.
Definition at line 1765 of file chains.h.
|
inline |
Writes a column with only these coefficients which exist in 'range', and shows their positions in that chain.
Definition at line 2542 of file chains.h.
|
inline |
Writes a column with only these coefficients which exist in 'range', and shows their positions in that chain.
Definition at line 2587 of file chains.h.
|
inline |
Writes the matrix to an output stream by its rows.
Definition at line 1901 of file chains.h.
|
inline |
Writes the matrix to an output stream by its rows.
Definition at line 1908 of file chains.h.
|
inline |
Writes the matrix as a linear map on generators.
Definition at line 1917 of file chains.h.
|
inline |
Writes the matrix as a linear map on generators.
Definition at line 1937 of file chains.h.
|
inline |
|
inline |
Writes the matrix to an output stream by its rows.
Definition at line 1892 of file chains.h.
|
inline |
Writes the matrix to an output stream by its rows or columns.
Definition at line 1869 of file chains.h.
|
inline |
Transforms the matrix to a simple form (nearly SNF).
Updates all the matrices which are linked to this one.
Definition at line 2003 of file chains.h.
References chomp::homology::scon, and chomp::homology::sout.
|
inline |
Transforms the matrix from the simple form to actual SNF.
Calls "arrange_towards_SNF" first, and then makes appropriate corrections of the coefficients at the "diagonal" so that each nonzero coefficient divides its successor. Assumes that the matrix is already in the simple form. Updates all the matrices which are linked to this one. WARNING: SEEMS NOT TO WORK CORRECTLY AT THE MOMENT.
Definition at line 2103 of file chains.h.
References chomp::homology::sout.
|
inline |
Runs some random simple reductions.
Updates all the matrices which are linked to this one. This function is launched at the beginning of the 'simple_form' procedure.
Definition at line 1946 of file chains.h.
References chomp::homology::scon, and chomp::homology::sout.
|
inline |
Extracts a submatrix from the given matrix.
Uses the positions in the 'domain' and 'range' chains as the column and row numbers for the coefficients in the new matrix.
|
inline |
Swaps two columns of the matrix.
Updates all the matrices which are linked to this one.
Definition at line 1626 of file chains.h.
References chomp::multiwork::swap().
|
inline |
Swaps two rows of the matrix.
Updates all the matrices which are linked to this one.
Definition at line 1599 of file chains.h.
References chomp::multiwork::swap().
|
private |
The number of allocated columns.
Definition at line 1271 of file chains.h.
Referenced by chomp::homology::mmatrix< euclidom >::mmatrix().
|
private |
The number of allocated rows.
Definition at line 1268 of file chains.h.
Referenced by chomp::homology::mmatrix< euclidom >::mmatrix().
|
private |
simplelist<mmatrix<euclidom> > chomp::homology::mmatrix< euclidom >::dom_dom |
This is a list of matrices to be updated together with the changes to the columns or rows of the current matrix.
These matrices may have these spaces as their domains or ranges (codomains, images). For instance, "dom_img" is a list of matrices such that the domain of the current matrix is the image of each of them.
simplelist<mmatrix<euclidom> > chomp::homology::mmatrix< euclidom >::dom_img |
simplelist<mmatrix<euclidom> > chomp::homology::mmatrix< euclidom >::img_dom |
simplelist<mmatrix<euclidom> > chomp::homology::mmatrix< euclidom >::img_img |
|
private |
The number of columns in the matrix.
Definition at line 1265 of file chains.h.
Referenced by chomp::homology::mmatrix< euclidom >::mmatrix().
|
private |
The number of rows in the matrix.
Definition at line 1262 of file chains.h.
Referenced by chomp::homology::mmatrix< euclidom >::mmatrix().
|
private |