Functions | |
void | cpl_matrix_dump (const cpl_matrix *matrix, FILE *stream) |
Print a matrix. | |
cpl_matrix * | cpl_matrix_new (int rows, int columns) |
Create a zero matrix of given size. | |
cpl_matrix * | cpl_matrix_wrap (int rows, int columns, double *data) |
Create a new matrix from existing data. | |
void | cpl_matrix_delete (cpl_matrix *matrix) |
Delete a matrix. | |
void * | cpl_matrix_unwrap (cpl_matrix *matrix) |
Delete a matrix, but not its data buffer. | |
int | cpl_matrix_get_nrow (const cpl_matrix *matrix) |
Get the number of rows of a matrix. | |
int | cpl_matrix_get_ncol (const cpl_matrix *matrix) |
Get the number of columns of a matrix. | |
double * | cpl_matrix_get_data (const cpl_matrix *matrix) |
Get the pointer to a matrix data buffer, or NULL in case of error. | |
double | cpl_matrix_get (const cpl_matrix *matrix, int row, int column) |
Get the value of a matrix element. | |
cpl_error_code | cpl_matrix_set (cpl_matrix *matrix, int row, int column, double value) |
Write a value to a matrix element. | |
cpl_matrix * | cpl_matrix_duplicate (const cpl_matrix *matrix) |
Make a copy of a matrix. | |
cpl_matrix * | cpl_matrix_extract (const cpl_matrix *matrix, int start_row, int start_column, int step_row, int step_column, int nrows, int ncolumns) |
Extract a submatrix from a matrix. | |
cpl_matrix * | cpl_matrix_extract_row (const cpl_matrix *matrix, int row) |
Extract a matrix row. | |
cpl_matrix * | cpl_matrix_extract_column (const cpl_matrix *matrix, int column) |
Copy a matrix column. | |
cpl_matrix * | cpl_matrix_extract_diagonal (const cpl_matrix *matrix, int diagonal) |
Extract a matrix diagonal. | |
cpl_error_code | cpl_matrix_fill (cpl_matrix *matrix, double value) |
Write the same value to all matrix elements. | |
cpl_error_code | cpl_matrix_fill_row (cpl_matrix *matrix, double value, int row) |
Write the same value to a matrix row. | |
cpl_error_code | cpl_matrix_fill_column (cpl_matrix *matrix, double value, int column) |
Write the same value to a matrix column. | |
cpl_error_code | cpl_matrix_fill_diagonal (cpl_matrix *matrix, double value, int diagonal) |
Write the same value to a matrix diagonal. | |
cpl_error_code | cpl_matrix_copy (cpl_matrix *matrix, const cpl_matrix *submatrix, int row, int col) |
Write the values of a matrix into another matrix. | |
cpl_error_code | cpl_matrix_fill_window (cpl_matrix *matrix, double value, int row, int col, int nrow, int ncol) |
Write the same value into a submatrix of a matrix. | |
cpl_error_code | cpl_matrix_shift (cpl_matrix *matrix, int rshift, int cshift) |
Shift matrix elements. | |
cpl_error_code | cpl_matrix_threshold_small (cpl_matrix *matrix, double tolerance) |
Rounding to zero very small numbers in matrix. | |
int | cpl_matrix_is_zero (const cpl_matrix *matrix, double tolerance) |
Check for zero matrix. | |
int | cpl_matrix_is_diagonal (const cpl_matrix *matrix, double tolerance) |
Check if a matrix is diagonal. | |
int | cpl_matrix_is_identity (const cpl_matrix *matrix, double tolerance) |
Check for identity matrix. | |
cpl_error_code | cpl_matrix_swap_rows (cpl_matrix *matrix, int row1, int row2) |
Swap two matrix rows. | |
cpl_error_code | cpl_matrix_swap_columns (cpl_matrix *matrix, int column1, int column2) |
Swap two matrix columns. | |
cpl_error_code | cpl_matrix_swap_rowcolumn (cpl_matrix *matrix, int row) |
Swap a matrix column with a matrix row. | |
cpl_error_code | cpl_matrix_flip_rows (cpl_matrix *matrix) |
Reverse order of rows in matrix. | |
cpl_error_code | cpl_matrix_flip_columns (cpl_matrix *matrix) |
Reverse order of columns in matrix. | |
cpl_matrix * | cpl_matrix_transpose_create (const cpl_matrix *matrix) |
Create transposed matrix. | |
cpl_error_code | cpl_matrix_sort_rows (cpl_matrix *matrix, int mode) |
Sort matrix by rows. | |
cpl_error_code | cpl_matrix_sort_columns (cpl_matrix *matrix, int mode) |
Sort matrix by columns. | |
cpl_error_code | cpl_matrix_erase_rows (cpl_matrix *matrix, int start, int count) |
Delete rows from a matrix. | |
cpl_error_code | cpl_matrix_erase_columns (cpl_matrix *matrix, int start, int count) |
Delete columns from a matrix. | |
cpl_error_code | cpl_matrix_resize (cpl_matrix *matrix, int top, int bottom, int left, int right) |
Reframe a matrix. | |
cpl_error_code | cpl_matrix_set_size (cpl_matrix *matrix, int rows, int columns) |
Resize a matrix. | |
cpl_error_code | cpl_matrix_append (cpl_matrix *matrix1, const cpl_matrix *matrix2, int mode) |
Append a matrix to another. | |
cpl_error_code | cpl_matrix_add (cpl_matrix *matrix1, const cpl_matrix *matrix2) |
Add two matrices. | |
cpl_error_code | cpl_matrix_subtract (cpl_matrix *matrix1, const cpl_matrix *matrix2) |
Subtract a matrix from another. | |
cpl_error_code | cpl_matrix_multiply (cpl_matrix *matrix1, const cpl_matrix *matrix2) |
Multiply two matrices element by element. | |
cpl_error_code | cpl_matrix_divide (cpl_matrix *matrix1, const cpl_matrix *matrix2) |
Divide a matrix by another element by element. | |
cpl_error_code | cpl_matrix_add_scalar (cpl_matrix *matrix, double value) |
Add a scalar to a matrix. | |
cpl_error_code | cpl_matrix_subtract_scalar (cpl_matrix *matrix, double value) |
Subtract a scalar to a matrix. | |
cpl_error_code | cpl_matrix_multiply_scalar (cpl_matrix *matrix, double value) |
Multiply a matrix by a scalar. | |
cpl_error_code | cpl_matrix_divide_scalar (cpl_matrix *matrix, double value) |
Divide a matrix by a scalar. | |
cpl_error_code | cpl_matrix_logarithm (cpl_matrix *matrix, double base) |
Compute the logarithm of matrix elements. | |
cpl_error_code | cpl_matrix_exponential (cpl_matrix *matrix, double base) |
Compute the exponential of matrix elements. | |
cpl_error_code | cpl_matrix_power (cpl_matrix *matrix, double exponent) |
Compute a power of matrix elements. | |
cpl_matrix * | cpl_matrix_product_create (const cpl_matrix *matrix1, const cpl_matrix *matrix2) |
Rows-by-columns product of two matrices. | |
cpl_error_code | cpl_matrix_do_echelon (cpl_matrix *matrix) |
Reduce the matrix in row echelon form. | |
double | cpl_matrix_get_determinant (const cpl_matrix *matrix) |
Compute the determinant of a matrix. | |
cpl_matrix * | cpl_matrix_solve (const cpl_matrix *coeff, const cpl_matrix *rhs) |
Solution of a linear system. | |
cpl_matrix * | cpl_matrix_invert_create (const cpl_matrix *matrix) |
Find a matrix inverse. | |
cpl_matrix * | cpl_matrix_solve_normal (const cpl_matrix *coeff, const cpl_matrix *rhs) |
Solution of a normal equation using a pseudo-inverse. | |
double | cpl_matrix_get_mean (const cpl_matrix *matrix) |
Find the mean of all matrix elements. | |
double | cpl_matrix_get_stdev (const cpl_matrix *matrix) |
Find the standard deviation of matrix elements. | |
double | cpl_matrix_get_median (const cpl_matrix *matrix) |
Find the median of matrix elements. | |
double | cpl_matrix_get_min (const cpl_matrix *matrix) |
Find the minimum value of matrix elements. | |
double | cpl_matrix_get_max (const cpl_matrix *matrix) |
Find the maximum value of matrix elements. | |
cpl_error_code | cpl_matrix_get_minpos (const cpl_matrix *matrix, int *row, int *column) |
Find position of minimum value of matrix elements. | |
cpl_error_code | cpl_matrix_get_maxpos (const cpl_matrix *matrix, int *row, int *column) |
Find position of the maximum value of matrix elements. |
NaN
or infinity).
#include <cpl_matrix.h>
|
Add two matrices.
Add two matrices element by element. The two matrices must have identical sizes. The result is written to the first matrix. |
|
Add a scalar to a matrix.
Add the same value to each matrix element. |
|
Append a matrix to another.
If mode is set to 0, the matrices must have the same number of rows, and are connected horizontally with the first matrix on the left. If mode is set to 1, the matrices must have the same number of columns, and are connected vertically with the first matrix on top. The first matrix is expanded to include the values from the second matrix, while the second matrix is left untouched.
|
|
Write the values of a matrix into another matrix.
The values of submatrix are written to matrix starting at the indicated row and column. There are no restrictions on the sizes of submatrix: just the parts of submatrix overlapping matrix are copied. There are no restrictions on row and col either, that can also be negative. If the two matrices do not overlap, nothing is done, but an error condition is set. |
|
Delete a matrix.
NULL , nothing is done. |
|
Divide a matrix by another element by element.
Divide each element of the first matrix by the corresponding element of the second one. The two matrices must have the same number of rows and columns. The result is written to the first matrix. No check is made against a division by zero. |
|
Divide a matrix by a scalar.
Divide each matrix element by the same value. |
|
Reduce the matrix in row echelon form.
The input matrix is reduced in row echelon form using the Gauss elimination method. A matrix is in row echelon form when:
|
|
Print a matrix.
fprintf() . |
|
Make a copy of a matrix.
A copy of the input matrix is created. To destroy the duplicated matrix the function |
|
Delete columns from a matrix.
A portion of the matrix data is physically removed. The pointer to matrix data may change, therefore pointers previously retrieved by calling |
|
Delete rows from a matrix.
A portion of the matrix data is physically removed. The pointer to matrix data may change, therefore pointers previously retrieved by calling |
|
Compute the exponential of matrix elements.
Each matrix element is replaced by its exponential in the specified base. The base must be positive. |
|
Extract a submatrix from a matrix.
The new matrix will include the nrows x ncolumns values read from the input matrix elements starting from position (start_row, start_column), in a grid of steps step_row and step_column. If the extraction parameters exceed the input matrix boundaries, just the overlap is returned, and this matrix would have sizes smaller than nrows x ncolumns. To destroy the new matrix the function |
|
Copy a matrix column.
If a MxN matrix is given in input, the extracted row is a new Mx1 matrix. The column number is counted from 0. To destroy the new matrix the function |
|
Extract a matrix diagonal.
If a MxN matrix is given in input, the extracted diagonal is a Mx1 matrix if N >= M, or a 1xN matrix if N < M. The diagonal number is counted from 0, corresponding to the matrix diagonal starting at element (0,0). A square matrix has just one diagonal; if M != N, the number of diagonals in the matrix is |M - N| + 1. To specify a diagonal sequence number outside this range would set an error condition, and a |
|
Extract a matrix row.
If a MxN matrix is given in input, the extracted row is a new 1xN matrix. The row number is counted from 0. To destroy the new matrix the function |
|
Write the same value to all matrix elements.
Write the same value to all matrix elements. |
|
Write the same value to a matrix column.
Write the same value to a matrix column. Columns are counted starting from 0. |
|
Write the same value to a matrix diagonal.
Write the same value to a matrix diagonal. The diagonal number is counted from 0, corresponding to the diagonal starting at element (0,0). A square matrix has just one diagonal; if M != N, the number of diagonals in the matrix is |M - N| + 1, counted along the longer side of the matrix. |
|
Write the same value to a matrix row.
Write the same value to a matrix row. Rows are counted starting from 0. |
|
Write the same value into a submatrix of a matrix.
The specified value is written to matrix starting at the indicated row and column; nrow and ncol can exceed the input matrix boundaries, just the range overlapping the matrix is used in that case. |
|
Reverse order of columns in matrix.
The order of the columns in the matrix is reversed in place. |
|
Reverse order of rows in matrix.
The order of the rows in the matrix is reversed in place. |
|
Get the value of a matrix element.
Get the value of a matrix element. The matrix rows and columns are counted from 0,0. |
|
Get the pointer to a matrix data buffer, or
A cpl_matrix object includes an array of values of type double. This function returns a pointer to this internal array, whose first element corresponds to the cpl_matrix element 0,0. The internal array contains in sequence all the cpl_matrix rows. For instance, in the case of a 3x4 matrix, the array elements 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 11
|
|
Compute the determinant of a matrix.
The input matrix must be a square matrix. In case of a 1x1 matrix, the matrix single element value is returned. |
|
Find the maximum value of matrix elements.
The maximum value of all matrix elements is found. |
|
Find position of the maximum value of matrix elements.
The position of the maximum value of all matrix elements is found. If more than one matrix element have a value corresponding to the maximum, the lowest element row number is returned in row. If more than one maximum matrix elements have the same row number, the lowest element column number is returned in column. |
|
Find the mean of all matrix elements.
The mean value of all matrix elements is calculated.
|
|
Find the median of matrix elements.
The median value of all matrix elements is calculated. |
|
Find the minimum value of matrix elements.
The minimum value of all matrix elements is found. |
|
Find position of minimum value of matrix elements.
The position of the minimum value of all matrix elements is found. If more than one matrix element have a value corresponding to the minimum, the lowest element row number is returned in row. If more than one minimum matrix elements have the same row number, the lowest element column number is returned in column. |
|
Get the number of columns of a matrix.
Determine the number of columns in a matrix. |
|
Get the number of rows of a matrix.
Determine the number of rows in a matrix. |
|
Find the standard deviation of matrix elements.
The standard deviation of all matrix elements is calculated.
|
|
Find a matrix inverse.
The input must be a square matrix. To destroy the new matrix the function
|
|
Check if a matrix is diagonal.
A threshold may be specified to consider zero any number that is close enough to zero. If the specified tolerance is negative, a default of |
|
Check for identity matrix.
A threshold may be specified to consider zero any number that is close enough to zero, and 1 any number that is close enough to 1. If the specified tolerance is negative, a default of |
|
Check for zero matrix.
After specific manipulations of a matrix some of its elements may theoretically be expected to be zero. However, because of numerical noise, such elements may turn out not to be exactly zero. In this specific case, if any of the matrix element is not exactly zero, the matrix would not be classified as a null matrix. A threshold may be specified to consider zero any number that is close enough to zero. If the specified tolerance is negative, a default of |
|
Compute the logarithm of matrix elements.
Each matrix element is replaced by its logarithm in the specified base. The base and all matrix elements must be positive. If this is not the case, the matrix would not be modified. |
|
Multiply two matrices element by element.
Multiply the two matrices element by element. The two matrices must have identical sizes. The result is written to the first matrix.
|
|
Multiply a matrix by a scalar.
Multiply each matrix element by the same factor. |
|
Create a zero matrix of given size.
This function allocates and initialises to zero a matrix of given size. To destroy this matrix the function |
|
Compute a power of matrix elements.
Each matrix element is replaced by its power to the specified exponent. If the specified exponent is not negative, all matrix elements must be not negative; if the specified exponent is negative, all matrix elements must be positive; otherwise, an error condition is set and the matrix will be left unchanged. If the exponent is zero, then any (non negative) matrix element would be assigned the value 1.0. |
|
Rows-by-columns product of two matrices.
Rows-by-columns product of two matrices. The number of columns of the first matrix must be equal to the number of rows of the second matrix. To destroy the new matrix the function |
|
Reframe a matrix.
The input matrix is reframed according to specifications. Extra rows and column on the sides might also be negative, as long as they are compatible with the matrix sizes: the input matrix would be reduced in size accordingly, but an attempt to remove all matrix columns and/or rows is flagged as an error because zero length matrices are illegal. The old matrix elements contained in the new shape are left unchanged, and new matrix elements added by the reshaping are initialised to zero. No reshaping (i.e., all the extra rows set to zero) would not be flagged as an error.
|
|
Write a value to a matrix element.
Write a value to a matrix element. The matrix rows and columns are counted from 0,0. |
|
Resize a matrix.
The input matrix is resized according to specifications. The old matrix elements contained in the resized matrix are left unchanged, and new matrix elements added by an increase of the matrix number of rows and/or columns are initialised to zero.
|
|
Shift matrix elements.
The performed shift operation is cyclical (toroidal), i.e., matrix elements shifted out of one side of the matrix get shifted in from its opposite side. There are no restrictions on the values of the shift. Positive shifts are always in the direction of increasing row/column indexes.
|
|
Solution of a linear system.
Compute the solution of a system of N equations with N unknowns: coeff * X = rhs
coeff must be an NxN matrix, and rhs a Nx1 matrix (a one-column matrix). To destroy the solution matrix the function
|
|
Solution of a normal equation using a pseudo-inverse.
The following redundant linear system of N equations and M unknowns is given:
coeff * X = rhs where coeff is the NxM matrix of the coefficients, X is the Mx1 matrix of the unknowns, and rhs the Nx1 matrix representing the nonhomogeneous terms. Then the pseudo-inverse solution to this equation is defined as:
X = inverse(transp(coeff)) * coeff) * transp(coeff) * rhs
The solution matrix is solving the equation according to a least-squares criterion. Note that the number of unknowns can be greater, equal, or less than the number of equations. To destroy the solution matrix the function |
|
Sort matrix by columns.
The matrix elements of the top row are used as reference for the column sorting, if there are identical the values of the second row are considered, etc. Columns with the largest values go on the right. If mode is equal to zero, the columns are sorted according to their absolute values (zeroes at left). |
|
Sort matrix by rows.
The matrix elements of the leftmost column are used as reference for the row sorting, if there are identical the values of the second column are considered, etc. Rows with the greater values go on top. If mode is equal to zero, the rows are sorted according to their absolute values (zeroes at bottom). |
|
Subtract a matrix from another.
Subtract the second matrix from the first one element by element. The two matrices must have identical sizes. The result is written to the first matrix. |
|
Subtract a scalar to a matrix.
Subtract the same value to each matrix element. |
|
Swap two matrix columns.
The values of two given matrix columns are exchanged. Columns are counted starting from 0. If the same column number is given twice, nothing is done and no error is set. |
|
Swap a matrix column with a matrix row.
The values of the indicated row are exchanged with the column having the same sequence number. Rows and columns are counted starting from 0. |
|
Swap two matrix rows.
The values of two given matrix rows are exchanged. Rows are counted starting from 0. If the same row number is given twice, nothing is done and no error is set. |
|
Rounding to zero very small numbers in matrix.
After specific manipulations of a matrix some of its elements may theoretically be expected to be zero (for instance, as a result of multiplying a matrix by its inverse). However, because of numerical noise, such elements may turn out not to be exactly zero. With this function any very small number in the matrix is turned to exactly zero. If the tolerance is zero or negative, a default threshold of |
|
Create transposed matrix.
The transposed of the input matrix is created. To destroy the new matrix the function |
|
Delete a matrix, but not its data buffer.
cpl_matrix_wrap() constructor, if the data buffer specified then was not allocated using the functions of the cpl_memory module. In such a case, the data buffer should be deallocated separately. See the documentation of the function cpl_matrix_wrap() . If matrix is NULL , nothing is done, and a NULL pointer is returned. |
|
Create a new matrix from existing data.
This function creates a new matrix that will encapsulate the given data. At any error condition, a 0 1 2 3 4 5 6 7 8 9 10 11 0 1 2 3 4 5 6 7 8 9 10 11 cpl_matrix_delete() would take care of deallocating it. To avoid problems with the memory managment, the specified data buffer should be allocated using the functions of the cpl_memory module, and also statically allocated data should be strictly avoided. If this were not the case, this matrix should not be destroyed using cpl_matrix_delete() , but cpl_matrix_unwrap() should be used instead; moreover, functions implying memory handling (as cpl_matrix_set_size() , or cpl_matrix_delete_row() ) should not be used. |