CMR  1.3.0
Classes | Functions
matrix.c File Reference
#include <cmr/matrix.h>
#include <assert.h>
#include <stdlib.h>
#include <stdint.h>
#include <math.h>
#include <limits.h>
#include <string.h>
#include "sort.h"
#include "env_internal.h"
#include "listmatrix.h"

Classes

struct  DblNonzero
 
struct  IntNonzero
 
struct  ChrNonzero
 

Functions

CMR_ERROR CMRsubmatCreate (CMR *cmr, size_t numRows, size_t numColumns, CMR_SUBMAT **psubmatrix)
 Creates a submatrix of given size. More...
 
CMR_ERROR CMRsubmatCreate1x1 (CMR *cmr, size_t row, size_t column, CMR_SUBMAT **psubmatrix)
 Creates a 1-by-1 submatrix. More...
 
CMR_ERROR CMRsubmatFree (CMR *cmr, CMR_SUBMAT **psubmatrix)
 Frees a submatrix. More...
 
CMR_ERROR CMRsubmatTranspose (CMR_SUBMAT *submatrix)
 Transposes a submatrix. More...
 
CMR_ERROR CMRsubmatZoomSubmat (CMR *cmr, CMR_SUBMAT *reference, CMR_SUBMAT *input, CMR_SUBMAT **poutput)
 Returns the submatrix input as a submatrix of the reference submatrix. More...
 
CMR_ERROR CMRsubmatWriteToStream (CMR *cmr, CMR_SUBMAT *submatrix, size_t numRows, size_t numColumns, FILE *stream)
 Writes the submatrix submatrix to the file stream by means of lists of row and column indices. More...
 
CMR_ERROR CMRsubmatWriteToFile (CMR *cmr, CMR_SUBMAT *submatrix, size_t numRows, size_t numColumns, const char *fileName)
 Writes the submatrix submatrix to the file by means of lists of row and column indices. More...
 
CMR_ERROR CMRsubmatReadFromStream (CMR *cmr, CMR_SUBMAT **psubmatrix, size_t *pnumMatrixRows, size_t *pnumMatrixColumns, FILE *stream)
 Reads the submatrix *psubmatrix from the file stream. More...
 
static int CMRsortSubmatrixCompare (const void *p1, const void *p2)
 
CMR_ERROR CMRsortSubmatrix (CMR *cmr, CMR_SUBMAT *submatrix)
 Sorts the row and column indices of submatrix. More...
 
CMR_ERROR CMRdblmatCreate (CMR *cmr, CMR_DBLMAT **matrix, int numRows, int numColumns, int numNonzeros)
 Creates a double matrix of with numRows rows, numColumns columns and numNonzeros nonzeros. The actual arrays are allocated but not initialized. More...
 
CMR_ERROR CMRintmatCreate (CMR *cmr, CMR_INTMAT **matrix, int numRows, int numColumns, int numNonzeros)
 Creates an int matrix of with numRows rows, numColumns columns and numNonzeros nonzeros. The actual arrays are allocated but not initialized. More...
 
CMR_ERROR CMRchrmatCreate (CMR *cmr, CMR_CHRMAT **matrix, int numRows, int numColumns, int numNonzeros)
 Creates a char matrix of with numRows rows, numColumns columns and numNonzeros nonzeros. The actual arrays are allocated but not initialized. More...
 
CMR_ERROR CMRdblmatFree (CMR *cmr, CMR_DBLMAT **pmatrix)
 Frees the memory of a double matrix. More...
 
CMR_ERROR CMRintmatFree (CMR *cmr, CMR_INTMAT **pmatrix)
 Frees the memory of an int matrix. More...
 
CMR_ERROR CMRchrmatFree (CMR *cmr, CMR_CHRMAT **pmatrix)
 Frees the memory of a char matrix. More...
 
CMR_ERROR CMRdblmatChangeNumNonzeros (CMR *cmr, CMR_DBLMAT *matrix, size_t newNumNonzeros)
 Changes the number of nonzeros and reallocates corresponding arrays. More...
 
CMR_ERROR CMRintmatChangeNumNonzeros (CMR *cmr, CMR_INTMAT *matrix, size_t newNumNonzeros)
 Changes the number of nonzeros and reallocates corresponding arrays. More...
 
CMR_ERROR CMRchrmatChangeNumNonzeros (CMR *cmr, CMR_CHRMAT *matrix, size_t newNumNonzeros)
 Changes the number of nonzeros and reallocates corresponding arrays. More...
 
static int compareEntries (const void **pa, const void **pb)
 
CMR_ERROR CMRdblmatSortNonzeros (CMR *cmr, CMR_DBLMAT *matrix)
 Sorts the nonzeros of a double matrix by column in ascending order. More...
 
CMR_ERROR CMRintmatSortNonzeros (CMR *cmr, CMR_INTMAT *matrix)
 Sorts the nonzeros of an int matrix by column in ascending order. More...
 
CMR_ERROR CMRchrmatSortNonzeros (CMR *cmr, CMR_CHRMAT *matrix)
 Sorts the nonzeros of a char matrix by column in ascending order. More...
 
CMR_ERROR CMRdblmatCopy (CMR *cmr, CMR_DBLMAT *matrix, CMR_DBLMAT **presult)
 Copies a double matrix to a newly allocated one. More...
 
CMR_ERROR CMRintmatCopy (CMR *cmr, CMR_INTMAT *matrix, CMR_INTMAT **presult)
 Copies an int matrix to a newly allocated one. More...
 
CMR_ERROR CMRchrmatCopy (CMR *cmr, CMR_CHRMAT *matrix, CMR_CHRMAT **presult)
 Copies a char matrix to a newly allocated one. More...
 
CMR_ERROR CMRdblmatTranspose (CMR *cmr, CMR_DBLMAT *matrix, CMR_DBLMAT **presult)
 Creates the transpose of a double matrix. More...
 
CMR_ERROR CMRintmatTranspose (CMR *cmr, CMR_INTMAT *matrix, CMR_INTMAT **presult)
 Creates the transpose of an int matrix. More...
 
CMR_ERROR CMRchrmatTranspose (CMR *cmr, CMR_CHRMAT *matrix, CMR_CHRMAT **presult)
 Creates the transpose of a char matrix. More...
 
CMR_ERROR CMRdblmatPermute (CMR *cmr, CMR_DBLMAT *matrix, size_t *rows, size_t *columns, CMR_DBLMAT **presult)
 Creates the double matrix obtained from matrix by applying row- and column-permutations. More...
 
CMR_ERROR CMRintmatPermute (CMR *cmr, CMR_INTMAT *matrix, size_t *rows, size_t *columns, CMR_INTMAT **presult)
 Creates the int matrix obtained from matrix by applying row- and column-permutations. More...
 
CMR_ERROR CMRchrmatPermute (CMR *cmr, CMR_CHRMAT *matrix, size_t *rows, size_t *columns, CMR_CHRMAT **presult)
 Creates the char matrix obtained from matrix by applying row- and column-permutations. More...
 
CMR_ERROR CMRdblmatPrintSparse (CMR *cmr, CMR_DBLMAT *matrix, FILE *stream)
 Prints a double matrix in sparse format. More...
 
CMR_ERROR CMRintmatPrintSparse (CMR *cmr, CMR_INTMAT *matrix, FILE *stream)
 Prints an int matrix in sparse format. More...
 
CMR_ERROR CMRchrmatPrintSparse (CMR *cmr, CMR_CHRMAT *matrix, FILE *stream)
 Prints a char matrix in sparse format. More...
 
CMR_ERROR CMRdblmatPrintDense (CMR *cmr, CMR_DBLMAT *matrix, FILE *stream, char zeroChar, bool header)
 Prints a double matrix in dense format. More...
 
CMR_ERROR CMRintmatPrintDense (CMR *cmr, CMR_INTMAT *matrix, FILE *stream, char zeroChar, bool header)
 Prints an int matrix in dense format. More...
 
CMR_ERROR CMRchrmatPrintDense (CMR *cmr, CMR_CHRMAT *matrix, FILE *stream, char zeroChar, bool header)
 Prints a char matrix in dense format. More...
 
static int compareDblNonzeros (const void *pa, const void *pb)
 
CMR_ERROR CMRdblmatCreateFromSparseStream (CMR *cmr, FILE *stream, CMR_DBLMAT **presult)
 Reads a double matrix from a file stream in sparse format. More...
 
static int compareIntNonzeros (const void *pa, const void *pb)
 
CMR_ERROR CMRintmatCreateFromSparseStream (CMR *cmr, FILE *stream, CMR_INTMAT **presult)
 Reads an int matrix from a file stream in sparse format. More...
 
static int compareChrNonzeros (const void *pa, const void *pb)
 
CMR_ERROR CMRchrmatCreateFromSparseStream (CMR *cmr, FILE *stream, CMR_CHRMAT **presult)
 Reads a char matrix from a file stream in sparse format. More...
 
CMR_ERROR CMRdblmatCreateFromDenseStream (CMR *cmr, FILE *stream, CMR_DBLMAT **presult)
 Reads a double matrix from a file stream in dense format. More...
 
CMR_ERROR CMRintmatCreateFromDenseStream (CMR *cmr, FILE *stream, CMR_INTMAT **presult)
 Reads an int matrix from a file stream in dense format. More...
 
CMR_ERROR CMRchrmatCreateFromDenseStream (CMR *cmr, FILE *stream, CMR_CHRMAT **presult)
 Reads a char matrix from a file stream in dense format. More...
 
bool CMRdblmatCheckEqual (CMR_DBLMAT *matrix1, CMR_DBLMAT *matrix2)
 Checks whether two double matrices are equal. More...
 
bool CMRintmatCheckEqual (CMR_INTMAT *matrix1, CMR_INTMAT *matrix2)
 Checks whether two int matrices are equal. More...
 
bool CMRchrmatCheckEqual (CMR_CHRMAT *matrix1, CMR_CHRMAT *matrix2)
 Checks whether two char matrices are equal. More...
 
CMR_ERROR CMRdblmatCheckTranspose (CMR *cmr, CMR_DBLMAT *matrix1, CMR_DBLMAT *matrix2, bool *pareTranspose)
 Checks whether two double matrices are transposes of each other. More...
 
CMR_ERROR CMRintmatCheckTranspose (CMR *cmr, CMR_INTMAT *matrix1, CMR_INTMAT *matrix2, bool *pareTranspose)
 Checks whether two int matrices are transposes of each other. More...
 
CMR_ERROR CMRchrmatCheckTranspose (CMR *cmr, CMR_CHRMAT *matrix1, CMR_CHRMAT *matrix2, bool *pareTranspose)
 Checks whether two char matrices are transposes of each other. More...
 
char * CMRdblmatConsistency (CMR_DBLMAT *matrix)
 Checks a double matrix for consistency. More...
 
char * CMRintmatConsistency (CMR_INTMAT *matrix)
 Checks an int matrix for consistency. More...
 
char * CMRchrmatConsistency (CMR_CHRMAT *matrix)
 Checks a char matrix for consistency. More...
 
bool CMRdblmatIsBinary (CMR *cmr, CMR_DBLMAT *matrix, double epsilon, CMR_SUBMAT **psubmatrix)
 Checks if a double matrix has only entries in \( \{0,1\} \) with absolute error tolerance epsilon. More...
 
bool CMRintmatIsBinary (CMR *cmr, CMR_INTMAT *matrix, CMR_SUBMAT **psubmatrix)
 Checks if an int matrix has only entries in \( \{0,1\} \). More...
 
bool CMRchrmatIsBinary (CMR *cmr, CMR_CHRMAT *matrix, CMR_SUBMAT **psubmatrix)
 Checks if a char matrix has only entries in \( \{0,1\} \). More...
 
bool CMRdblmatIsTernary (CMR *cmr, CMR_DBLMAT *matrix, double epsilon, CMR_SUBMAT **psubmatrix)
 Checks if a double matrix has only entries in \( \{-1,0,+1\} \) with absolute error tolerance epsilon. More...
 
bool CMRintmatIsTernary (CMR *cmr, CMR_INTMAT *matrix, CMR_SUBMAT **psubmatrix)
 Checks if an int matrix has only entries in \( \{-1,0,+1\} \). More...
 
bool CMRchrmatIsTernary (CMR *cmr, CMR_CHRMAT *matrix, CMR_SUBMAT **psubmatrix)
 Checks if a double matrix has only entries in \( \{-1,0,+1\} \). More...
 
CMR_ERROR CMRdblmatZoomSubmat (CMR *cmr, CMR_DBLMAT *matrix, CMR_SUBMAT *submatrix, CMR_DBLMAT **presult)
 Creates a submatrix of a double matrix as an explicit matrix. More...
 
CMR_ERROR CMRintmatZoomSubmat (CMR *cmr, CMR_INTMAT *matrix, CMR_SUBMAT *submatrix, CMR_INTMAT **presult)
 Creates a submatrix of an int matrix as an explicit matrix. More...
 
CMR_ERROR CMRchrmatFilter (CMR *cmr, CMR_CHRMAT *matrix, size_t numRows, size_t *rows, size_t numColumns, size_t *columns, CMR_CHRMAT **presult)
 Creates a numRows \( \times \) numColumns submatrix of the char matrix indexed by rows and columns. More...
 
CMR_ERROR CMRchrmatZoomSubmat (CMR *cmr, CMR_CHRMAT *matrix, CMR_SUBMAT *submatrix, CMR_CHRMAT **presult)
 Creates a submatrix of a char matrix as an explicit matrix. More...
 
CMR_ERROR CMRdblmatSupport (CMR *cmr, CMR_DBLMAT *matrix, double epsilon, CMR_CHRMAT **presult)
 Creates the (binary) support matrix of a double matrix as a char matrix with absolute error tolerance epsilon. More...
 
CMR_ERROR CMRintmatSupport (CMR *cmr, CMR_INTMAT *matrix, CMR_CHRMAT **presult)
 Creates the (binary) support matrix of an int matrix as a char matrix. More...
 
CMR_ERROR CMRchrmatSupport (CMR *cmr, CMR_CHRMAT *matrix, CMR_CHRMAT **presult)
 Creates the (binary) support matrix of a char matrix as a char matrix. More...
 
CMR_ERROR CMRdblmatSignedSupport (CMR *cmr, CMR_DBLMAT *matrix, double epsilon, CMR_CHRMAT **presult)
 Creates the (ternary) signed support matrix of a double matrix as a char matrix with absolute error tolerance epsilon. More...
 
CMR_ERROR CMRintmatSignedSupport (CMR *cmr, CMR_INTMAT *matrix, CMR_CHRMAT **presult)
 Creates the (ternary) signed support matrix of an int matrix as a char matrix. More...
 
CMR_ERROR CMRchrmatSignedSupport (CMR *cmr, CMR_CHRMAT *matrix, CMR_CHRMAT **presult)
 Creates the (ternary) signed support matrix of a char matrix as a char matrix. More...
 
CMR_ERROR CMRintmatToChr (CMR *cmr, CMR_INTMAT *matrix, CMR_CHRMAT **presult)
 Converts an int matrix to a char matrix. More...
 
CMR_ERROR CMRdblmatFindEntry (CMR_DBLMAT *matrix, size_t row, size_t column, size_t *pentry)
 Finds a specific entry of a double matrix. More...
 
CMR_ERROR CMRintmatFindEntry (CMR_INTMAT *matrix, size_t row, size_t column, size_t *pentry)
 Finds a specific entry of an int matrix. More...
 
CMR_ERROR CMRchrmatFindEntry (CMR_CHRMAT *matrix, size_t row, size_t column, size_t *pentry)
 Finds a specific entry of a char matrix. More...
 
static size_t findMaximum (size_t *array, size_t length, size_t *pmaxIndex)
 
static CMR_ERROR findBadSubmatrixByMaximum (CMR *cmr, ChrListMat *listmatrix, CMR_SUBMAT **psubmatrix)
 
CMR_ERROR CMRdblmatFindBinarySubmatrix (CMR *cmr, CMR_DBLMAT *matrix, double epsilon, CMR_SUBMAT **psubmatrix)
 Finds a large binary submatrix with absolute error tolerance epsilon. More...
 
CMR_ERROR CMRdblmatFindTernarySubmatrix (CMR *cmr, CMR_DBLMAT *matrix, double epsilon, CMR_SUBMAT **psubmatrix)
 Finds a large ternary submatrix with absolute error tolerance epsilon. More...
 

Function Documentation

CMR_ERROR CMRchrmatChangeNumNonzeros ( CMR cmr,
CMR_CHRMAT matrix,
size_t  newNumNonzeros 
)

Changes the number of nonzeros and reallocates corresponding arrays.

Parameters
cmrCMR environment.
matrixA matrix.
newNumNonzerosNew number of nonzeros.
bool CMRchrmatCheckEqual ( CMR_CHRMAT matrix1,
CMR_CHRMAT matrix2 
)

Checks whether two char matrices are equal.

Parameters
matrix1First matrix.
matrix2Second matrix.
CMR_ERROR CMRchrmatCheckTranspose ( CMR cmr,
CMR_CHRMAT matrix1,
CMR_CHRMAT matrix2,
bool *  pareTranspose 
)

Checks whether two char matrices are transposes of each other.

Parameters
cmrCMR environment.
matrix1First matrix
matrix2Second matrix
pareTransposePointer for storing whether matrix1 and matrix2 are tranposes of each other.
char* CMRchrmatConsistency ( CMR_CHRMAT matrix)

Checks a char matrix for consistency.

Checks whether the entries of a row are sorted by column in ascending order. Checks for duplicate entries. Checks for zero entries.

Returns
NULL if consistent. Otherwise, an explanation string is returned, which must free'd with free().
See also
CMRconsistencyAssert() for checking the returned string and aborting in case of inconsistency.
Parameters
matrixA matrix.
CMR_ERROR CMRchrmatCopy ( CMR cmr,
CMR_CHRMAT matrix,
CMR_CHRMAT **  presult 
)

Copies a char matrix to a newly allocated one.

Parameters
cmrCMR environment.
matrixA matrix.
presultPointer for storing a copy of matrix.
CMR_ERROR CMRchrmatCreate ( CMR cmr,
CMR_CHRMAT **  matrix,
int  numRows,
int  numColumns,
int  numNonzeros 
)

Creates a char matrix of with numRows rows, numColumns columns and numNonzeros nonzeros. The actual arrays are allocated but not initialized.

Parameters
cmrCMR environment.
matrixPointer for storing the created matrix.
numRowsNumber of rows.
numColumnsNumber of columns.
numNonzerosNumber of nonzeros.
CMR_ERROR CMRchrmatCreateFromDenseStream ( CMR cmr,
FILE *  stream,
CMR_CHRMAT **  presult 
)

Reads a char matrix from a file stream in dense format.

Returns CMR_ERROR_INPUT in case of errors. In this case, *presult will be NULL.

Parameters
cmrCMR environment.
streamFile stream to read from.
presultPointer for storing the matrix.
CMR_ERROR CMRchrmatCreateFromSparseStream ( CMR cmr,
FILE *  stream,
CMR_CHRMAT **  presult 
)

Reads a char matrix from a file stream in sparse format.

Returns CMR_ERROR_INPUT in case of errors. In this case, *presult will be NULL.

Parameters
cmrCMR environment.
streamFile stream to read from.
presultPointer for storing the matrix.
CMR_ERROR CMRchrmatFilter ( CMR cmr,
CMR_CHRMAT matrix,
size_t  numRows,
size_t *  rows,
size_t  numColumns,
size_t *  columns,
CMR_CHRMAT **  presult 
)

Creates a numRows \( \times \) numColumns submatrix of the char matrix indexed by rows and columns.

Parameters
cmrCMR environment.
matrixMatrix.
numRowsNumber of rows of submatrix.
rowsRows of matrix to be copied into the submatrix.
numColumnsNumber of columns of submatrix.
columnsColumns of matrix to be copied into the submatrix.
presultPointer for storing the created submatrix.
CMR_ERROR CMRchrmatFindEntry ( CMR_CHRMAT matrix,
size_t  row,
size_t  column,
size_t *  pentry 
)

Finds a specific entry of a char matrix.

Searches for the entry at (row, column) using binary search. If an entry is zero, then *pentry is set to SIZE_MAX.

Parameters
matrixInput matrix.
rowA row.
columnA column.
pentryPointer for storing the entry at row, column, or SIZE_MAX if it is zero.
CMR_ERROR CMRchrmatFree ( CMR cmr,
CMR_CHRMAT **  pmatrix 
)

Frees the memory of a char matrix.

Parameters
cmrCMR environment.
pmatrixPointer to matrix.
bool CMRchrmatIsBinary ( CMR cmr,
CMR_CHRMAT matrix,
CMR_SUBMAT **  psubmatrix 
)

Checks if a char matrix has only entries in \( \{0,1\} \).

Parameters
cmrCMR environment.
matrixA matrix.
psubmatrixPointer for storing a non-binary entry as a submatrix (may be NULL).
bool CMRchrmatIsTernary ( CMR cmr,
CMR_CHRMAT matrix,
CMR_SUBMAT **  psubmatrix 
)

Checks if a double matrix has only entries in \( \{-1,0,+1\} \).

Parameters
cmrCMR environment.
matrixA matrix.
psubmatrixPointer for storing a non-ternary entry as a submatrix (may be NULL).
CMR_ERROR CMRchrmatPermute ( CMR cmr,
CMR_CHRMAT matrix,
size_t *  rows,
size_t *  columns,
CMR_CHRMAT **  presult 
)

Creates the char matrix obtained from matrix by applying row- and column-permutations.

Parameters
cmrCMR environment.
matrixGiven matrix.
rowsMapping from new rows to rows of matrix (may be NULL for identity).
columnsMapping from new columns to columns of matrix (may be NULL for identity).
presultPointer for storing the permuted matrix.
CMR_ERROR CMRchrmatPrintDense ( CMR cmr,
CMR_CHRMAT matrix,
FILE *  stream,
char  zeroChar,
bool  header 
)

Prints a char matrix in dense format.

Parameters
cmrCMR environment.
matrixA matrix.
streamFile stream to print to.
zeroCharCharacter to print for a zero.
headerWhether to print row and column indices.
CMR_ERROR CMRchrmatPrintSparse ( CMR cmr,
CMR_CHRMAT matrix,
FILE *  stream 
)

Prints a char matrix in sparse format.

Parameters
cmrCMR environment.
matrixA matrix.
streamFile stream to print to.
CMR_ERROR CMRchrmatSignedSupport ( CMR cmr,
CMR_CHRMAT matrix,
CMR_CHRMAT **  presult 
)

Creates the (ternary) signed support matrix of a char matrix as a char matrix.

Parameters
cmrCMR environment.
matrixDouble matrix
presultPointer for storing the signed support matrix of matrix.
CMR_ERROR CMRchrmatSortNonzeros ( CMR cmr,
CMR_CHRMAT matrix 
)

Sorts the nonzeros of a char matrix by column in ascending order.

Parameters
cmrCMR environment.
matrixA matrix.
CMR_ERROR CMRchrmatSupport ( CMR cmr,
CMR_CHRMAT matrix,
CMR_CHRMAT **  presult 
)

Creates the (binary) support matrix of a char matrix as a char matrix.

Parameters
cmrCMR environment.
matrixDouble matrix
presultPointer for storing the support matrix of matrix.
CMR_ERROR CMRchrmatTranspose ( CMR cmr,
CMR_CHRMAT matrix,
CMR_CHRMAT **  presult 
)

Creates the transpose of a char matrix.

Parameters
cmrCMR environment.
matrixGiven matrix.
presultPointer for storing the transpose of matrix.
CMR_ERROR CMRchrmatZoomSubmat ( CMR cmr,
CMR_CHRMAT matrix,
CMR_SUBMAT submatrix,
CMR_CHRMAT **  presult 
)

Creates a submatrix of a char matrix as an explicit matrix.

Parameters
cmrCMR environment.
matrixA matrix
submatrixA submatrix of matrix.
presultPointer for storing the resulting double matrix.
CMR_ERROR CMRdblmatChangeNumNonzeros ( CMR cmr,
CMR_DBLMAT matrix,
size_t  newNumNonzeros 
)

Changes the number of nonzeros and reallocates corresponding arrays.

Parameters
cmrCMR environment.
matrixGiven matrix.
newNumNonzerosNew number of nonzeros.
bool CMRdblmatCheckEqual ( CMR_DBLMAT matrix1,
CMR_DBLMAT matrix2 
)

Checks whether two double matrices are equal.

Parameters
matrix1First matrix.
matrix2Second matrix.
CMR_ERROR CMRdblmatCheckTranspose ( CMR cmr,
CMR_DBLMAT matrix1,
CMR_DBLMAT matrix2,
bool *  pareTranspose 
)

Checks whether two double matrices are transposes of each other.

Parameters
cmrCMR environment.
matrix1First matrix.
matrix2Second matrix.
pareTransposePointer for storing whether matrix1 and matrix2 are tranposes of each other.
char* CMRdblmatConsistency ( CMR_DBLMAT matrix)

Checks a double matrix for consistency.

Checks whether the entries of a row are sorted by column in ascending order. Checks for duplicate entries. Checks for zero entries.

Returns
NULL if consistent. Otherwise, an explanation string is returned, which must free'd with free().
See also
CMRconsistencyAssert() for checking the returned string and aborting in case of inconsistency.
Parameters
matrixA matrix.
CMR_ERROR CMRdblmatCopy ( CMR cmr,
CMR_DBLMAT matrix,
CMR_DBLMAT **  presult 
)

Copies a double matrix to a newly allocated one.

Parameters
cmrCMR environment.
matrixA matrix.
presultPointer for storing a copy of matrix.
CMR_ERROR CMRdblmatCreate ( CMR cmr,
CMR_DBLMAT **  matrix,
int  numRows,
int  numColumns,
int  numNonzeros 
)

Creates a double matrix of with numRows rows, numColumns columns and numNonzeros nonzeros. The actual arrays are allocated but not initialized.

Parameters
cmrCMR environment.
matrixPointer for storing the created matrix.
numRowsNumber of rows.
numColumnsNumber of columns.
numNonzerosNumber of nonzeros.
CMR_ERROR CMRdblmatCreateFromDenseStream ( CMR cmr,
FILE *  stream,
CMR_DBLMAT **  presult 
)

Reads a double matrix from a file stream in dense format.

Returns CMR_ERROR_INPUT in case of errors. In this case, *presult will be NULL.

Parameters
cmrCMR environment.
streamFile stream to read from.
presultPointer for storing the matrix.
CMR_ERROR CMRdblmatCreateFromSparseStream ( CMR cmr,
FILE *  stream,
CMR_DBLMAT **  presult 
)

Reads a double matrix from a file stream in sparse format.

Returns CMR_ERROR_INPUT in case of errors. In this case, *presult will be NULL.

Parameters
cmrCMR environment.
streamFile stream to read from.
presultPointer for storing the matrix.
CMR_ERROR CMRdblmatFindBinarySubmatrix ( CMR cmr,
CMR_DBLMAT matrix,
double  epsilon,
CMR_SUBMAT **  psubmatrix 
)

Finds a large binary submatrix with absolute error tolerance epsilon.

Parameters
cmrCMR environment.
matrixA matrix.
epsilonAbsolute error tolerance.
psubmatrixPointer for storing a large binary submatrix.
CMR_ERROR CMRdblmatFindEntry ( CMR_DBLMAT matrix,
size_t  row,
size_t  column,
size_t *  pentry 
)

Finds a specific entry of a double matrix.

Searches for the entry at (row, column) using binary search.

Parameters
matrixInput matrix.
rowA row.
columnA column.
pentryPointer for storing the entry at row, column, or SIZE_MAX if it is zero.
CMR_ERROR CMRdblmatFindTernarySubmatrix ( CMR cmr,
CMR_DBLMAT matrix,
double  epsilon,
CMR_SUBMAT **  psubmatrix 
)

Finds a large ternary submatrix with absolute error tolerance epsilon.

Parameters
cmrCMR environment.
matrixA matrix.
epsilonAbsolute error tolerance.
psubmatrixPointer for storing a large binary submatrix.
CMR_ERROR CMRdblmatFree ( CMR cmr,
CMR_DBLMAT **  pmatrix 
)

Frees the memory of a double matrix.

Parameters
cmrCMR environment.
pmatrixPointer to matrix.
bool CMRdblmatIsBinary ( CMR cmr,
CMR_DBLMAT matrix,
double  epsilon,
CMR_SUBMAT **  psubmatrix 
)

Checks if a double matrix has only entries in \( \{0,1\} \) with absolute error tolerance epsilon.

Parameters
cmrCMR environment.
matrixA matrix.
epsilonAbsolute error tolerance.
psubmatrixPointer for storing a non-binary entry as a submatrix (may be NULL).
bool CMRdblmatIsTernary ( CMR cmr,
CMR_DBLMAT matrix,
double  epsilon,
CMR_SUBMAT **  psubmatrix 
)

Checks if a double matrix has only entries in \( \{-1,0,+1\} \) with absolute error tolerance epsilon.

Parameters
cmrCMR environment.
matrixA matrix.
epsilonAbsolute error tolerance.
psubmatrixPointer for storing a non-ternary entry as a submatrix (may be NULL).
CMR_ERROR CMRdblmatPermute ( CMR cmr,
CMR_DBLMAT matrix,
size_t *  rows,
size_t *  columns,
CMR_DBLMAT **  presult 
)

Creates the double matrix obtained from matrix by applying row- and column-permutations.

Parameters
cmrCMR environment.
matrixGiven matrix.
rowsMapping from new rows to rows of matrix (may be NULL for identity).
columnsMapping from new columns to columns of matrix (may be NULL for identity).
presultPointer for storing the permuted matrix.
CMR_ERROR CMRdblmatPrintDense ( CMR cmr,
CMR_DBLMAT matrix,
FILE *  stream,
char  zeroChar,
bool  header 
)

Prints a double matrix in dense format.

Parameters
cmrCMR environment.
matrixA matrix.
streamFile stream to print to.
zeroCharCharacter to print for a zero.
headerWhether to print row and column indices.
CMR_ERROR CMRdblmatPrintSparse ( CMR cmr,
CMR_DBLMAT matrix,
FILE *  stream 
)

Prints a double matrix in sparse format.

Parameters
cmrCMR environment.
matrixA matrix.
streamFile stream to print to.
CMR_ERROR CMRdblmatSignedSupport ( CMR cmr,
CMR_DBLMAT matrix,
double  epsilon,
CMR_CHRMAT **  presult 
)

Creates the (ternary) signed support matrix of a double matrix as a char matrix with absolute error tolerance epsilon.

Parameters
cmrCMR environment.
matrixDouble matrix
epsilonAbsolute error tolerance.
presultPointer for storing the support matrix of matrix.
CMR_ERROR CMRdblmatSortNonzeros ( CMR cmr,
CMR_DBLMAT matrix 
)

Sorts the nonzeros of a double matrix by column in ascending order.

Parameters
cmrCMR environment.
matrixA matrix.
CMR_ERROR CMRdblmatSupport ( CMR cmr,
CMR_DBLMAT matrix,
double  epsilon,
CMR_CHRMAT **  presult 
)

Creates the (binary) support matrix of a double matrix as a char matrix with absolute error tolerance epsilon.

Parameters
cmrCMR environment.
matrixDouble matrix
epsilonAbsolute error tolerance.
presultPointer for storing the support matrix of matrix.
CMR_ERROR CMRdblmatTranspose ( CMR cmr,
CMR_DBLMAT matrix,
CMR_DBLMAT **  presult 
)

Creates the transpose of a double matrix.

Parameters
cmrCMR environment.
matrixA matrix.
presultPointer for storing the transpose of matrix.
CMR_ERROR CMRdblmatZoomSubmat ( CMR cmr,
CMR_DBLMAT matrix,
CMR_SUBMAT submatrix,
CMR_DBLMAT **  presult 
)

Creates a submatrix of a double matrix as an explicit matrix.

Parameters
cmrCMR environment.
matrixA matrix
submatrixA submatrix of matrix.
presultPointer for storing the resulting matrix.
CMR_ERROR CMRintmatChangeNumNonzeros ( CMR cmr,
CMR_INTMAT matrix,
size_t  newNumNonzeros 
)

Changes the number of nonzeros and reallocates corresponding arrays.

Parameters
cmrCMR environment.
matrixA matrix.
newNumNonzerosNew number of nonzeros.
bool CMRintmatCheckEqual ( CMR_INTMAT matrix1,
CMR_INTMAT matrix2 
)

Checks whether two int matrices are equal.

Parameters
matrix1First matrix.
matrix2Second matrix.
CMR_ERROR CMRintmatCheckTranspose ( CMR cmr,
CMR_INTMAT matrix1,
CMR_INTMAT matrix2,
bool *  pareTranspose 
)

Checks whether two int matrices are transposes of each other.

Parameters
cmrCMR environment.
matrix1First matrix
matrix2Second matrix
pareTransposePointer for storing whether matrix1 and matrix2 are tranposes of each other.
char* CMRintmatConsistency ( CMR_INTMAT matrix)

Checks an int matrix for consistency.

Checks whether the entries of a row are sorted by column in ascending order. Checks for duplicate entries. Checks for zero entries.

Returns
NULL if consistent. Otherwise, an explanation string is returned, which must free'd with free().
See also
CMRconsistencyAssert() for checking the returned string and aborting in case of inconsistency.
Parameters
matrixA matrix.
CMR_ERROR CMRintmatCopy ( CMR cmr,
CMR_INTMAT matrix,
CMR_INTMAT **  presult 
)

Copies an int matrix to a newly allocated one.

Parameters
cmrCMR environment.
matrixA matrix.
presultPointer for storing a copy of matrix.
CMR_ERROR CMRintmatCreate ( CMR cmr,
CMR_INTMAT **  matrix,
int  numRows,
int  numColumns,
int  numNonzeros 
)

Creates an int matrix of with numRows rows, numColumns columns and numNonzeros nonzeros. The actual arrays are allocated but not initialized.

Parameters
cmrCMR environment.
matrixPointer for storing the created matrix.
numRowsNumber of rows.
numColumnsNumber of columns.
numNonzerosNumber of nonzeros.
CMR_ERROR CMRintmatCreateFromDenseStream ( CMR cmr,
FILE *  stream,
CMR_INTMAT **  presult 
)

Reads an int matrix from a file stream in dense format.

Returns CMR_ERROR_INPUT in case of errors. In this case, *presult will be NULL.

Parameters
cmrCMR environment.
streamFile stream to read from.
presultPointer for storing the matrix.
CMR_ERROR CMRintmatCreateFromSparseStream ( CMR cmr,
FILE *  stream,
CMR_INTMAT **  presult 
)

Reads an int matrix from a file stream in sparse format.

Returns CMR_ERROR_INPUT in case of errors. In this case, *presult will be NULL.

Parameters
cmrCMR environment.
streamFile stream to read from.
presultPointer for storing the matrix.
CMR_ERROR CMRintmatFindEntry ( CMR_INTMAT matrix,
size_t  row,
size_t  column,
size_t *  pentry 
)

Finds a specific entry of an int matrix.

Searches for the entry at (row, column) using binary search.

Parameters
matrixInput matrix.
rowA row.
columnA column.
pentryPointer for storing the entry at row, column, or SIZE_MAX if it is zero.
CMR_ERROR CMRintmatFree ( CMR cmr,
CMR_INTMAT **  pmatrix 
)

Frees the memory of an int matrix.

Parameters
cmrCMR environment.
pmatrixPointer to matrix.
bool CMRintmatIsBinary ( CMR cmr,
CMR_INTMAT matrix,
CMR_SUBMAT **  psubmatrix 
)

Checks if an int matrix has only entries in \( \{0,1\} \).

Parameters
cmrCMR environment.
matrixA matrix.
psubmatrixPointer for storing a non-binary entry as a submatrix (may be NULL).
bool CMRintmatIsTernary ( CMR cmr,
CMR_INTMAT matrix,
CMR_SUBMAT **  psubmatrix 
)

Checks if an int matrix has only entries in \( \{-1,0,+1\} \).

Parameters
cmrCMR environment.
matrixA matrix.
psubmatrixPointer for storing a non-ternary entry as a submatrix (may be NULL).
CMR_ERROR CMRintmatPermute ( CMR cmr,
CMR_INTMAT matrix,
size_t *  rows,
size_t *  columns,
CMR_INTMAT **  presult 
)

Creates the int matrix obtained from matrix by applying row- and column-permutations.

Parameters
cmrCMR environment.
matrixGiven matrix.
rowsMapping from new rows to rows of matrix (may be NULL for identity).
columnsMapping from new columns to columns of matrix (may be NULL for identity).
presultPointer for storing the permuted matrix.
CMR_ERROR CMRintmatPrintDense ( CMR cmr,
CMR_INTMAT matrix,
FILE *  stream,
char  zeroChar,
bool  header 
)

Prints an int matrix in dense format.

Parameters
cmrCMR environment.
matrixA matrix.
streamFile stream to print to.
zeroCharCharacter to print for a zero.
headerWhether to print row and column indices.
CMR_ERROR CMRintmatPrintSparse ( CMR cmr,
CMR_INTMAT matrix,
FILE *  stream 
)

Prints an int matrix in sparse format.

Parameters
cmrCMR environment.
matrixA matrix.
streamFile stream to print to.
CMR_ERROR CMRintmatSignedSupport ( CMR cmr,
CMR_INTMAT matrix,
CMR_CHRMAT **  presult 
)

Creates the (ternary) signed support matrix of an int matrix as a char matrix.

Parameters
cmrCMR environment.
matrixDouble matrix
presultPointer for storing the signed support matrix of matrix.
CMR_ERROR CMRintmatSortNonzeros ( CMR cmr,
CMR_INTMAT matrix 
)

Sorts the nonzeros of an int matrix by column in ascending order.

Parameters
cmrCMR environment.
matrixA matrix.
CMR_ERROR CMRintmatSupport ( CMR cmr,
CMR_INTMAT matrix,
CMR_CHRMAT **  presult 
)

Creates the (binary) support matrix of an int matrix as a char matrix.

Parameters
cmrCMR environment.
matrixDouble matrix
presultPointer for storing the support matrix of matrix.
CMR_ERROR CMRintmatToChr ( CMR cmr,
CMR_INTMAT matrix,
CMR_CHRMAT **  presult 
)

Converts an int matrix to a char matrix.

Returns
CMR_ERROR_INPUT in case of overflow.
Parameters
cmrCMR environment.
matrixInput matrix.
presultPointer for storing the output matrix.
CMR_ERROR CMRintmatTranspose ( CMR cmr,
CMR_INTMAT matrix,
CMR_INTMAT **  presult 
)

Creates the transpose of an int matrix.

Parameters
cmrCMR environment.
matrixGiven matrix.
presultPointer for storing the transpose of matrix.
CMR_ERROR CMRintmatZoomSubmat ( CMR cmr,
CMR_INTMAT matrix,
CMR_SUBMAT submatrix,
CMR_INTMAT **  presult 
)

Creates a submatrix of an int matrix as an explicit matrix.

Parameters
cmrCMR environment.
matrixA matrix
submatrixA submatrix of matrix.
presultPointer for storing the resulting matrix.
CMR_ERROR CMRsortSubmatrix ( CMR cmr,
CMR_SUBMAT submatrix 
)

Sorts the row and column indices of submatrix.

Parameters
cmrCMR environment.
submatrixThe submatrix.
static int CMRsortSubmatrixCompare ( const void *  p1,
const void *  p2 
)
static
CMR_ERROR CMRsubmatCreate ( CMR cmr,
size_t  numRows,
size_t  numColumns,
CMR_SUBMAT **  psubmatrix 
)

Creates a submatrix of given size.

Only allocates the memory. Use rows and columns attributes of *psubmatrix to actually set the row and column indices, respectively.

Parameters
cmrCMR environment.
numRowsNumber of rows
numColumnsNumber of columns
psubmatrixPointer to where the submatrix is to be stored.
CMR_ERROR CMRsubmatCreate1x1 ( CMR cmr,
size_t  row,
size_t  column,
CMR_SUBMAT **  psubmatrix 
)

Creates a 1-by-1 submatrix.

Parameters
cmrCMR environment.
rowRow of entry
columnColumn of entry
psubmatrixPointer to submatrix
CMR_ERROR CMRsubmatFree ( CMR cmr,
CMR_SUBMAT **  psubmatrix 
)

Frees a submatrix.

Parameters
cmrCMR environment.
psubmatrixPointer to submatrix.
CMR_ERROR CMRsubmatReadFromStream ( CMR cmr,
CMR_SUBMAT **  psubmatrix,
size_t *  pnumMatrixRows,
size_t *  pnumMatrixColumns,
FILE *  stream 
)

Reads the submatrix *psubmatrix from the file stream.

Parameters
cmrCMR environment.
psubmatrixPointer for storing the submatrix.
pnumMatrixRowsPointer for storing the number of rows of the original matrix; may be NULL.
pnumMatrixColumnsPointer for storing the number of rows of the original matrix; may be NULL.
streamFile stream to save submatrix to.
CMR_ERROR CMRsubmatTranspose ( CMR_SUBMAT submatrix)

Transposes a submatrix.

Parameters
submatrixSubmatrix to transpose.
CMR_ERROR CMRsubmatWriteToFile ( CMR cmr,
CMR_SUBMAT submatrix,
size_t  numRows,
size_t  numColumns,
const char *  fileName 
)

Writes the submatrix submatrix to the file by means of lists of row and column indices.

Parameters
cmrCMR environment.
submatrixReference submatrix.
numRowsNumber of rows of original matrix.
numColumnsNumber of columns of original matrix.
fileNameFile name to save submatrix to; NULL indicates stdout.
CMR_ERROR CMRsubmatWriteToStream ( CMR cmr,
CMR_SUBMAT submatrix,
size_t  numRows,
size_t  numColumns,
FILE *  stream 
)

Writes the submatrix submatrix to the file stream by means of lists of row and column indices.

Parameters
cmrCMR environment.
submatrixReference submatrix.
numRowsNumber of rows of original matrix.
numColumnsNumber of columns of original matrix.
streamFile stream to save submatrix to.
CMR_ERROR CMRsubmatZoomSubmat ( CMR cmr,
CMR_SUBMAT reference,
CMR_SUBMAT input,
CMR_SUBMAT **  poutput 
)

Returns the submatrix input as a submatrix of the reference submatrix.

Assumes that input is a sub-submatrix of references, i.e., each row/column of input must also appear in reference.

Parameters
cmrCMR environment.
referenceReference submatrix.
inputInput submatrix.
poutputPointer for storing the output submatrix.
static int compareChrNonzeros ( const void *  pa,
const void *  pb 
)
static
static int compareDblNonzeros ( const void *  pa,
const void *  pb 
)
static
static int compareEntries ( const void **  pa,
const void **  pb 
)
static
static int compareIntNonzeros ( const void *  pa,
const void *  pb 
)
static
static CMR_ERROR findBadSubmatrixByMaximum ( CMR cmr,
ChrListMat listmatrix,
CMR_SUBMAT **  psubmatrix 
)
static
static size_t findMaximum ( size_t *  array,
size_t  length,
size_t *  pmaxIndex 
)
static