GRASS GIS 7 Programmer's Manual
7.9.dev(2021)-e5379bbd7
|
Go to the source code of this file.
Functions | |
mat_struct * | G_matrix_init (int, int, int) |
Initialize a matrix structure. More... | |
int | G_matrix_zero (mat_struct *) |
Clears (or resets) the matrix values to 0. More... | |
int | G_matrix_set (mat_struct *, int, int, int) |
Set parameters for an initialized matrix. More... | |
mat_struct * | G_matrix_copy (const mat_struct *) |
Copy a matrix. More... | |
mat_struct * | G_matrix_add (mat_struct *, mat_struct *) |
Adds two matricies. More... | |
mat_struct * | G_matrix_subtract (mat_struct *, mat_struct *) |
Subtract two matricies. More... | |
mat_struct * | G_matrix_scale (mat_struct *, const double) |
Scale a matrix by a scalar value. More... | |
mat_struct * | G__matrix_add (mat_struct *, mat_struct *, const double, const double) |
General add/subtract/scalar multiply routine. More... | |
mat_struct * | G_matrix_product (mat_struct *, mat_struct *) |
Returns product of two matricies. More... | |
mat_struct * | G_matrix_transpose (mat_struct *) |
Transpose a matrix. More... | |
int | G_matrix_LU_solve (const mat_struct *, mat_struct **, const mat_struct *, mat_type) |
Solve a general system A.X = B. More... | |
mat_struct * | G_matrix_inverse (mat_struct *) |
Returns the matrix inverse. More... | |
void | G_matrix_free (mat_struct *) |
Free up allocated matrix. More... | |
void | G_matrix_print (mat_struct *) |
Print out a matrix. More... | |
int | G_matrix_set_element (mat_struct *, int, int, double) |
Set the value of the (i, j)th element. More... | |
double | G_matrix_get_element (mat_struct *, int, int) |
Retrieve value of the (i,j)th element. More... | |
vec_struct * | G_matvect_get_column (mat_struct *, int) |
Retrieve a column of the matrix to a vector structure. More... | |
vec_struct * | G_matvect_get_row (mat_struct *, int) |
Retrieve a row of the matrix to a vector structure. More... | |
vec_struct * | G_matvect_product (mat_struct *, vec_struct *, vec_struct *) |
Calculates the matrix-vector product. More... | |
int | G_matvect_extract_vector (mat_struct *, vtype, int) |
Convert matrix to vector. More... | |
int | G_matvect_retrieve_matrix (vec_struct *) |
Revert a vector to matrix. More... | |
vec_struct * | G_vector_init (int, int, vtype) |
Initialize a vector structure. More... | |
int | G_vector_set (vec_struct *, int, int, vtype, int) |
Set parameters for vector structure. More... | |
double | G_vector_norm_euclid (vec_struct *) |
Calculates euclidean norm. More... | |
double | G_vector_norm_maxval (vec_struct *, int) |
Calculates maximum value. More... | |
vec_struct * | G_vector_copy (const vec_struct *, int) |
Returns a vector copied from vc1. Underlying structure is preserved unless DO_COMPACT flag. More... | |
vec_struct * | G_vector_product (vec_struct *, vec_struct *, vec_struct *) |
Calculates the vector product. More... | |
void | G_vector_free (vec_struct *) |
Free an allocated vector structure. More... | |
vec_struct * | G_vector_sub (vec_struct *, vec_struct *, vec_struct *) |
Subtract two vectors. More... | |
double | G_vector_norm1 (vec_struct *) |
Calculates the 1-norm of a vector. More... | |
int | G_matrix_read (FILE *, mat_struct *) |
Read a matrix from a file stream. More... | |
int | G_matrix_stdin (mat_struct *) |
int | G_matrix_eigen_sort (vec_struct *, mat_struct *) |
Sort eigenvectors according to eigenvalues. More... | |
mat_struct * | G_matrix_scalar_mul (double, mat_struct *, mat_struct *) |
Calculates the scalar-matrix multiplication. More... | |
mat_struct * | G_matrix_resize (mat_struct *, int, int) |
Resizes a matrix. More... | |
mat_struct * G__matrix_add | ( | mat_struct * | mt1, |
mat_struct * | mt2, | ||
const double | c1, | ||
const double | c2 | ||
) |
General add/subtract/scalar multiply routine.
General add/subtract/scalar multiply routine. c2 may be zero, but c1 must be non-zero.
mt1 | |
mt2 | |
c1 | |
c2 |
Definition at line 278 of file la.c.
References _, matrix_::cols, G_matrix_init(), G_warning(), matrix_::is_init, matrix_::ldim, NULL, matrix_::rows, and matrix_::vals.
Referenced by G_matrix_add(), and G_matrix_subtract().
mat_struct * G_matrix_add | ( | mat_struct * | mt1, |
mat_struct * | mt2 | ||
) |
Adds two matricies.
Adds two matricies mt1 and mt2 and returns a resulting matrix. The return structure is automatically initialized.
mt1 | |
mt2 |
Definition at line 178 of file la.c.
References G__matrix_add().
mat_struct * G_matrix_copy | ( | const mat_struct * | A | ) |
Copy a matrix.
Copy matrix A by exactly duplicating its contents.
A |
Definition at line 145 of file la.c.
Referenced by G_matrix_LU_solve().
int G_matrix_eigen_sort | ( | vec_struct * | d, |
mat_struct * | m | ||
) |
void G_matrix_free | ( | mat_struct * | mt | ) |
Free up allocated matrix.
Free up allocated matrix.
mt |
Definition at line 667 of file la.c.
References G_free(), matrix_::is_init, and matrix_::vals.
Referenced by G_matrix_inverse(), and G_matrix_LU_solve().
double G_matrix_get_element | ( | mat_struct * | mt, |
int | rowval, | ||
int | colval | ||
) |
Retrieve value of the (i,j)th element.
Retrieve the value of the (i, j)th element to a double value. Index values are C-like ie. zero-based. Note: Does currently not set an error flag for bounds checking.
mt | |
rowval | |
colval |
Definition at line 759 of file la.c.
References matrix_::ldim, and matrix_::vals.
Referenced by G_matrix_print(), G_matrix_resize(), G_matrix_scalar_mul(), G_matvect_get_column(), G_matvect_get_row(), G_vector_norm1(), G_vector_product(), and G_vector_sub().
mat_struct * G_matrix_init | ( | int | rows, |
int | cols, | ||
int | ldim | ||
) |
Initialize a matrix structure.
Initialize a matrix structure
rows | |
cols | |
ldim |
Definition at line 56 of file la.c.
References _, matrix_::cols, G_calloc, G_malloc, G_warning(), matrix_::is_init, matrix_::ldim, MATRIX_, NULL, matrix_::rows, matrix_::type, matrix_::v_indx, and matrix_::vals.
Referenced by G__matrix_add(), G_matrix_inverse(), G_matrix_product(), G_matrix_resize(), G_matrix_scalar_mul(), and G_matrix_transpose().
mat_struct * G_matrix_inverse | ( | mat_struct * | mt | ) |
Returns the matrix inverse.
Calls G_matrix_LU_solve() to obtain matrix inverse using LU decomposition. Returns NULL on failure.
mt |
Definition at line 608 of file la.c.
References _, matrix_::cols, G_matrix_free(), G_matrix_init(), G_matrix_LU_solve(), G_warning(), if(), matrix_::ldim, NONSYM, NULL, matrix_::rows, and matrix_::vals.
int G_matrix_LU_solve | ( | const mat_struct * | mt1, |
mat_struct ** | xmat0, | ||
const mat_struct * | bmat, | ||
mat_type | mtype | ||
) |
Solve a general system A.X = B.
Solve a general system A.X = B, where A is a NxN matrix, X and B are NxC matrices, and we are to solve for C arrays in X given B. Uses LU decomposition.
Links to LAPACK function dgesv_() and similar to perform the core routine. (By default solves for a general non-symmetric matrix.)
mtype is a flag to indicate what kind of matrix (real/complex, Hermitian, symmetric, general etc.) is used (NONSYM, SYM, HERMITIAN).
Warning: NOT YET COMPLETE: only some solutions' options available. Now, only general real matrix is supported.
mt1 | |
xmat0 | |
bmat | |
mtype |
Definition at line 480 of file la.c.
References _, matrix_::cols, f77_dgesv, G_free(), G_malloc, G_matrix_copy(), G_matrix_free(), G_warning(), matrix_::is_init, matrix_::ldim, NONSYM, NULL, matrix_::rows, and matrix_::vals.
Referenced by G_matrix_inverse().
void G_matrix_print | ( | mat_struct * | mt | ) |
Print out a matrix.
Print out a representation of the matrix to standard output.
mt |
Definition at line 687 of file la.c.
References matrix_::cols, G_matrix_get_element(), G_message(), and matrix_::rows.
mat_struct * G_matrix_product | ( | mat_struct * | mt1, |
mat_struct * | mt2 | ||
) |
Returns product of two matricies.
Returns a matrix with the product of matrix mt1 and mt2. The return matrix is automatically initialized.
mt1 | |
mt2 |
Definition at line 356 of file la.c.
References _, matrix_::cols, f77_dgemm, G_matrix_init(), G_warning(), matrix_::is_init, matrix_::ldim, NULL, matrix_::rows, and matrix_::vals.
int G_matrix_read | ( | FILE * | fp, |
mat_struct * | out | ||
) |
Read a matrix from a file stream.
Populates matrix structure out with matrix read from file stream fp. Matrix out is automatically initialized. Returns -1 on error and 0 on success.
fp | |
out |
Definition at line 1542 of file la.c.
References _, G_getl(), G_matrix_set(), G_matrix_set_element(), and G_warning().
Referenced by G_matrix_stdin().
mat_struct * G_matrix_resize | ( | mat_struct * | in, |
int | rows, | ||
int | cols | ||
) |
Resizes a matrix.
Resizes a matrix
A | |
rows | |
cols |
Definition at line 1596 of file la.c.
References matrix_::cols, G_matrix_get_element(), G_matrix_init(), G_matrix_set_element(), and matrix_::rows.
Referenced by G_matrix_scalar_mul().
mat_struct * G_matrix_scalar_mul | ( | double | scalar, |
mat_struct * | matrix, | ||
mat_struct * | out | ||
) |
Calculates the scalar-matrix multiplication.
Calculates the scalar-matrix multiplication
scalar | |
A |
Definition at line 214 of file la.c.
References _, matrix_::cols, G_matrix_get_element(), G_matrix_init(), G_matrix_resize(), G_matrix_set_element(), G_warning(), NULL, matrix_::rows, and Key_Value::value.
mat_struct * G_matrix_scale | ( | mat_struct * | mt1, |
const double | c | ||
) |
int G_matrix_set | ( | mat_struct * | A, |
int | rows, | ||
int | cols, | ||
int | ldim | ||
) |
Set parameters for an initialized matrix.
Set parameters for matrix A that is allocated, but not yet fully initialized. Is an alternative to G_matrix_init().
A | |
rows | |
cols | |
ldim |
Definition at line 114 of file la.c.
Referenced by G_matrix_read().
int G_matrix_set_element | ( | mat_struct * | mt, |
int | rowval, | ||
int | colval, | ||
double | val | ||
) |
Set the value of the (i, j)th element.
Set the value of the (i, j)th element to a double value. Index values are C-like ie. zero-based. The row number is given first as is conventional. Returns -1 if the accessed cell is outside the bounds.
mt | |
rowval | |
colval | |
val |
Definition at line 726 of file la.c.
References _, matrix_::cols, G_warning(), matrix_::is_init, matrix_::ldim, matrix_::rows, and matrix_::vals.
Referenced by G_matrix_read(), G_matrix_resize(), G_matrix_scalar_mul(), G_matvect_get_column(), G_matvect_get_row(), G_vector_product(), and G_vector_sub().
int G_matrix_stdin | ( | mat_struct * | ) |
Definition at line 1630 of file la.c.
References G_matrix_read().
mat_struct * G_matrix_subtract | ( | mat_struct * | mt1, |
mat_struct * | mt2 | ||
) |
Subtract two matricies.
Subtracts two matricies mt1 and mt2 and returns a resulting matrix. The return matrix is automatically initialized.
mt1 | |
mt2 |
Definition at line 197 of file la.c.
References G__matrix_add().
mat_struct * G_matrix_transpose | ( | mat_struct * | mt | ) |
Transpose a matrix.
Transpose matrix m1 by creating a new one and populating with transposed elements. The return matrix is automatically initialized.
mt |
Definition at line 410 of file la.c.
References matrix_::cols, G_matrix_init(), matrix_::ldim, matrix_::rows, and matrix_::vals.
int G_matrix_zero | ( | mat_struct * | A | ) |
int G_matvect_extract_vector | ( | mat_struct * | mt, |
vtype | vt, | ||
int | indx | ||
) |
Convert matrix to vector.
Convert the matrix mt to a vector structure. The vtype, vt, is RVEC or CVEC which specifies a row vector or column vector. The index, indx, indicates the row/column number (zero based).
mt | |
vt | |
indx |
Definition at line 866 of file la.c.
References _, matrix_::cols, COLVEC_, CVEC, G_warning(), matrix_::rows, ROWVEC_, RVEC, matrix_::type, and matrix_::v_indx.
vec_struct * G_matvect_get_column | ( | mat_struct * | mt, |
int | col | ||
) |
Retrieve a column of the matrix to a vector structure.
Retrieve a column of matrix mt to a returning vector structure
mt | |
col |
Definition at line 782 of file la.c.
References _, matrix_::cols, CVEC, G_matrix_get_element(), G_matrix_set_element(), G_vector_init(), G_warning(), matrix_::is_init, matrix_::ldim, NULL, and matrix_::rows.
vec_struct * G_matvect_get_row | ( | mat_struct * | mt, |
int | row | ||
) |
Retrieve a row of the matrix to a vector structure.
Retrieves a row from matrix mt and returns it in a vector structure.
mt | |
row |
Definition at line 823 of file la.c.
References _, matrix_::cols, G_matrix_get_element(), G_matrix_set_element(), G_vector_init(), G_warning(), matrix_::is_init, matrix_::ldim, NULL, and RVEC.
vec_struct * G_matvect_product | ( | mat_struct * | A, |
vec_struct * | b, | ||
vec_struct * | out | ||
) |
int G_matvect_retrieve_matrix | ( | vec_struct * | vc | ) |
Revert a vector to matrix.
Revert vector vc to a matrix.
vc |
Definition at line 916 of file la.c.
References MATRIX_, matrix_::type, and matrix_::v_indx.
vec_struct * G_vector_copy | ( | const vec_struct * | vc1, |
int | comp_flag | ||
) |
Returns a vector copied from vc1. Underlying structure is preserved unless DO_COMPACT flag.
vc1 | |
comp_flag |
Definition at line 1429 of file la.c.
References _, matrix_::cols, COLVEC_, DO_COMPACT, G_calloc, G_malloc, G_warning(), matrix_::is_init, matrix_::ldim, NO_COMPACT, NULL, matrix_::rows, ROWVEC_, matrix_::type, matrix_::v_indx, and matrix_::vals.
void G_vector_free | ( | vec_struct * | v | ) |
Free an allocated vector structure.
Free an allocated vector structure.
v |
Definition at line 1042 of file la.c.
References G_free(), matrix_::is_init, and matrix_::vals.
vec_struct * G_vector_init | ( | int | cells, |
int | ldim, | ||
vtype | vt | ||
) |
Initialize a vector structure.
Returns an initialized vector structure with cell cells, of dimension ldim, and of type vt.
cells | |
ldim | |
vt |
Definition at line 995 of file la.c.
References matrix_::cols, COLVEC_, CVEC, G_calloc, G_malloc, G_warning(), matrix_::is_init, matrix_::ldim, NULL, matrix_::rows, ROWVEC_, RVEC, matrix_::type, matrix_::v_indx, and matrix_::vals.
Referenced by G_matvect_get_column(), and G_matvect_get_row().
double G_vector_norm1 | ( | vec_struct * | vc | ) |
Calculates the 1-norm of a vector.
Calculates the 1-norm of a vector
vc |
Definition at line 1318 of file la.c.
References _, matrix_::cols, G_matrix_get_element(), G_warning(), if(), matrix_::is_init, matrix_::rows, ROWVEC_, matrix_::type, and matrix_::v_indx.
double G_vector_norm_euclid | ( | vec_struct * | vc | ) |
Calculates euclidean norm.
Calculates the euclidean norm of a row or column vector, using BLAS routine dnrm2_().
vc |
Definition at line 1192 of file la.c.
References _, matrix_::cols, f77_dnrm2, G_fatal_error(), if(), matrix_::is_init, matrix_::ldim, matrix_::rows, ROWVEC_, matrix_::type, matrix_::v_indx, and matrix_::vals.
double G_vector_norm_maxval | ( | vec_struct * | vc, |
int | vflag | ||
) |
Calculates maximum value.
Calculates the maximum value of a row or column vector. The vflag setting defines which value to be calculated: vflag: 1 Indicates maximum value
-1 Indicates minimum value
0 Indicates absolute value [???]
vc | |
vflag |
Definition at line 1243 of file la.c.
References _, matrix_::cols, G_fatal_error(), if(), matrix_::is_init, matrix_::ldim, MAX_ABS, MAX_NEG, MAX_POS, matrix_::rows, ROWVEC_, matrix_::type, matrix_::v_indx, and matrix_::vals.
vec_struct * G_vector_product | ( | vec_struct * | v1, |
vec_struct * | v2, | ||
vec_struct * | out | ||
) |
Calculates the vector product.
Calculates the vector product of two vectors
v1 | |
v2 |
Definition at line 1355 of file la.c.
References _, matrix_::cols, COLVEC_, G_matrix_get_element(), G_matrix_set_element(), G_warning(), if(), matrix_::is_init, MATRIX_, NULL, matrix_::rows, ROWVEC_, matrix_::type, matrix_::v_indx, and matrix_::vals.
int G_vector_set | ( | vec_struct * | A, |
int | cells, | ||
int | ldim, | ||
vtype | vt, | ||
int | vindx | ||
) |
vec_struct * G_vector_sub | ( | vec_struct * | v1, |
vec_struct * | v2, | ||
vec_struct * | out | ||
) |
Subtract two vectors.
Subtracts two vectors, v1 and v2, and returns and populates vector out.
v1 | |
v2 | |
out |
Definition at line 1065 of file la.c.
References _, matrix_::cols, COLVEC_, G_matrix_get_element(), G_matrix_set_element(), G_warning(), if(), matrix_::is_init, MATRIX_, NULL, matrix_::rows, ROWVEC_, matrix_::type, and matrix_::v_indx.