|
GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
|

Go to the source code of this file.
Functions | |
| mat_struct * | G_matrix_init (int, int, int) |
| Initialize a matrix structure. | |
| int | G_matrix_zero (mat_struct *) |
| Clears (or resets) the matrix values to 0. | |
| int | G_matrix_set (mat_struct *, int, int, int) |
| Set parameters for an initialized matrix. | |
| mat_struct * | G_matrix_copy (const mat_struct *) |
| Copy a matrix. | |
| mat_struct * | G_matrix_add (mat_struct *, mat_struct *) |
| Adds two matrices. | |
| mat_struct * | G_matrix_subtract (mat_struct *, mat_struct *) |
| Subtract two matrices. | |
| mat_struct * | G_matrix_scale (mat_struct *, const double) |
| Scale a matrix by a scalar value. | |
| mat_struct * | G__matrix_add (mat_struct *, mat_struct *, const double, const double) |
| mat_struct * | G_matrix_product (mat_struct *, mat_struct *) |
| Returns product of two matrices. | |
| mat_struct * | G_matrix_transpose (mat_struct *) |
| Transpose a matrix. | |
| int | G_matrix_LU_solve (const mat_struct *, mat_struct **, const mat_struct *, mat_type) |
| Solve a general system A.X = B. | |
| mat_struct * | G_matrix_inverse (mat_struct *) |
| Returns the matrix inverse. | |
| void | G_matrix_free (mat_struct *) |
| Free up allocated matrix. | |
| void | G_matrix_print (mat_struct *) |
| Print out a matrix. | |
| int | G_matrix_set_element (mat_struct *, int, int, double) |
| double | G_matrix_get_element (mat_struct *, int, int) |
| Retrieve value of the (i,j)th element. | |
| vec_struct * | G_matvect_get_column (mat_struct *, int) |
| Retrieve a column of the matrix to a vector structure. | |
| vec_struct * | G_matvect_get_row (mat_struct *, int) |
| Retrieve a row of the matrix to a vector structure. | |
| vec_struct * | G_matvect_product (mat_struct *, vec_struct *, vec_struct *) |
| Calculates the matrix-vector product. | |
| int | G_matvect_extract_vector (mat_struct *, vtype, int) |
| Convert matrix to vector. | |
| int | G_matvect_retrieve_matrix (vec_struct *) |
| Revert a vector to matrix. | |
| vec_struct * | G_vector_init (int, int, vtype) |
| Initialize a vector structure. | |
| int | G_vector_set (vec_struct *, int, int, vtype, int) |
| double | G_vector_norm_euclid (vec_struct *) |
| Calculates euclidean norm. | |
| double | G_vector_norm_maxval (vec_struct *, int) |
| Calculates maximum value. | |
| vec_struct * | G_vector_copy (const vec_struct *, int) |
| Returns a vector copied from vc1. Underlying structure is preserved unless DO_COMPACT flag. | |
| vec_struct * | G_vector_product (vec_struct *, vec_struct *, vec_struct *) |
| Calculates the vector product. | |
| void | G_vector_free (vec_struct *) |
| Free an allocated vector structure. | |
| vec_struct * | G_vector_sub (vec_struct *, vec_struct *, vec_struct *) |
| Subtract two vectors. | |
| double | G_vector_norm1 (vec_struct *) |
| Calculates the 1-norm of a vector. | |
| int | G_matrix_read (FILE *, mat_struct *) |
| Read a matrix from a file stream. | |
| int | G_matrix_stdin (mat_struct *) |
| Read a matrix from standard input. | |
| int | G_matrix_eigen_sort (vec_struct *, mat_struct *) |
| Sort eigenvectors according to eigenvalues. | |
| mat_struct * | G_matrix_scalar_mul (double, mat_struct *, mat_struct *) |
| Calculates the scalar-matrix multiplication. | |
| mat_struct * | G_matrix_resize (mat_struct *, int, int) |
| Resizes a matrix. | |
| mat_struct * G__matrix_add | ( | mat_struct * | mt1, |
| mat_struct * | mt2, | ||
| const double | c1, | ||
| const double | c2 | ||
| ) |
Definition at line 278 of file la.c.
References _, G_matrix_init(), G_warning(), and NULL.
Referenced by G_matrix_add(), G_matrix_scale(), and G_matrix_subtract().
| mat_struct * G_matrix_add | ( | mat_struct * | mt1, |
| mat_struct * | mt2 | ||
| ) |
Adds two matrices.
Adds two matrices mt1 and mt2 and returns a resulting matrix. The return structure is automatically initialized.
| mt1 | |
| mt2 |
Definition at line 181 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 149 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_LU_solve().
| int G_matrix_eigen_sort | ( | vec_struct * | d, |
| mat_struct * | m | ||
| ) |
Sort eigenvectors according to eigenvalues.
Sort eigenvectors according to eigenvalues. Returns 0.
| d | |
| m |
Definition at line 1568 of file la.c.
References matrix_::cols, G_free(), G_matrix_get_element(), G_matrix_set(), G_matrix_set_element(), matrix_::ldim, ROWVEC_, matrix_::type, matrix_::v_indx, and matrix_::vals.
| void G_matrix_free | ( | mat_struct * | mt | ) |
Free up allocated matrix.
Free up allocated matrix.
| mt |
Definition at line 637 of file la.c.
References G_free().
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 724 of file la.c.
Referenced by G_matrix_eigen_sort(), G_matrix_print(), G_matrix_resize(), G_matrix_scalar_mul(), G_matvect_get_column(), G_matvect_get_row(), G_matvect_product(), 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 66 of file la.c.
References _, G_calloc, G_malloc, G_warning(), MATRIX_, and NULL.
Referenced by G__matrix_add(), G_matrix_copy(), 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 584 of file la.c.
References _, G_matrix_free(), G_matrix_init(), G_matrix_LU_solve(), G_warning(), NONSYM, and NULL.
| 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 464 of file la.c.
References _, G_free(), G_malloc, G_matrix_copy(), G_matrix_free(), G_warning(), NONSYM, and NULL.
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 655 of file la.c.
References G_matrix_get_element(), G_message(), and G_strlcpy().
| mat_struct * G_matrix_product | ( | mat_struct * | mt1, |
| mat_struct * | mt2 | ||
| ) |
Returns product of two matrices.
Returns a matrix with the product of matrix mt1 and mt2. The return matrix is automatically initialized.
| mt1 | |
| mt2 |
Definition at line 350 of file la.c.
References _, G_matrix_init(), G_warning(), and NULL.
| 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 1466 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
| in | |
| rows | |
| cols |
Definition at line 1518 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 | |
| matrix | |
| out |
Definition at line 216 of file la.c.
References _, G_matrix_get_element(), G_matrix_init(), G_matrix_resize(), G_matrix_set_element(), G_warning(), and NULL.
| mat_struct * G_matrix_scale | ( | mat_struct * | mt1, |
| const double | c | ||
| ) |
Scale a matrix by a scalar value.
Scales matrix mt1 by scalar value c. The resulting matrix is automatically initialized.
| mt1 | |
| c |
Definition at line 258 of file la.c.
References G__matrix_add(), and NULL.
| 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 120 of file la.c.
References _, matrix_::cols, G_calloc, G_warning(), matrix_::is_init, matrix_::ldim, MATRIX_, matrix_::rows, matrix_::type, matrix_::v_indx, and matrix_::vals.
Referenced by G_matrix_eigen_sort(), and G_matrix_read().
| int G_matrix_set_element | ( | mat_struct * | mt, |
| int | rowval, | ||
| int | colval, | ||
| double | val | ||
| ) |
Definition at line 693 of file la.c.
References _, and G_warning().
Referenced by G_matrix_eigen_sort(), 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 * | out | ) |
Read a matrix from standard input.
Populates matrix out with matrix read from stdin. Matrix out is automatically initialized. Returns -1 on failure or 0 on success.
| out |
Definition at line 1552 of file la.c.
References G_matrix_read().
| mat_struct * G_matrix_subtract | ( | mat_struct * | mt1, |
| mat_struct * | mt2 | ||
| ) |
Subtract two matrices.
Subtracts two matrices mt1 and mt2 and returns a resulting matrix. The return matrix is automatically initialized.
| mt1 | |
| mt2 |
Definition at line 198 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 398 of file la.c.
References G_matrix_init().
| int G_matrix_zero | ( | mat_struct * | A | ) |
Clears (or resets) the matrix values to 0.
| A |
Definition at line 96 of file la.c.
References matrix_::cols, matrix_::ldim, and matrix_::vals.
| 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 825 of file la.c.
References _, COLVEC_, CVEC, G_warning(), ROWVEC_, and RVEC.
| 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 745 of file la.c.
References _, CVEC, G_matrix_get_element(), G_matrix_set_element(), G_vector_init(), G_warning(), and NULL.
| 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 784 of file la.c.
References _, G_matrix_get_element(), G_matrix_set_element(), G_vector_init(), G_warning(), NULL, and RVEC.
| vec_struct * G_matvect_product | ( | mat_struct * | A, |
| vec_struct * | b, | ||
| vec_struct * | out | ||
| ) |
Calculates the matrix-vector product.
Calculates the product of a matrix and a vector
| A | |
| b |
Definition at line 894 of file la.c.
References _, b, matrix_::cols, G_matrix_get_element(), G_warning(), NULL, and matrix_::rows.
| int G_matvect_retrieve_matrix | ( | vec_struct * | vc | ) |
| 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 1355 of file la.c.
References _, COLVEC_, DO_COMPACT, G_calloc, G_malloc, G_warning(), NO_COMPACT, NULL, and ROWVEC_.
| void G_vector_free | ( | vec_struct * | v | ) |
Free an allocated vector structure.
Free an allocated vector structure.
| v |
Definition at line 991 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 947 of file la.c.
References COLVEC_, CVEC, G_calloc, G_malloc, G_warning(), NULL, ROWVEC_, and RVEC.
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 1250 of file la.c.
References _, G_matrix_get_element(), G_warning(), and ROWVEC_.
| 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 1135 of file la.c.
References _, G_fatal_error(), and ROWVEC_.
| 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 1180 of file la.c.
References _, G_fatal_error(), MAX_ABS, MAX_NEG, MAX_POS, and ROWVEC_.
| 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 | |
| out | Output vector |
Definition at line 1288 of file la.c.
References _, matrix_::cols, COLVEC_, G_matrix_get_element(), G_matrix_set_element(), G_warning(), MATRIX_, NULL, matrix_::rows, ROWVEC_, matrix_::type, and matrix_::v_indx.
Definition at line 1087 of file la.c.
References _, matrix_::cols, COLVEC_, CVEC, G_calloc, G_warning(), matrix_::is_init, matrix_::ldim, matrix_::rows, ROWVEC_, RVEC, matrix_::type, matrix_::v_indx, and matrix_::vals.
| 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 1013 of file la.c.
References _, matrix_::cols, COLVEC_, G_matrix_get_element(), G_matrix_set_element(), G_warning(), MATRIX_, NULL, matrix_::rows, ROWVEC_, matrix_::type, and matrix_::v_indx.