GRASS 8 Programmer's Manual 8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
defs/gmath.h
Go to the documentation of this file.
1#ifndef GRASS_GMATHDEFS_H
2#define GRASS_GMATHDEFS_H
3
4/* dalloc.c */
5double *G_alloc_vector(size_t);
6double **G_alloc_matrix(int, int);
7float *G_alloc_fvector(size_t);
8float **G_alloc_fmatrix(int, int);
9void G_free_vector(double *);
10void G_free_matrix(double **);
11void G_free_fvector(float *);
12void G_free_fmatrix(float **);
13
14/* ialloc.c */
15int *G_alloc_ivector(size_t);
16int **G_alloc_imatrix(int, int);
17void G_free_ivector(int *);
18void G_free_imatrix(int **);
19
20/* fft.c */
21extern int fft(int, double *[2], int, int, int);
22extern int fft2(int, double (*)[2], int, int, int);
23
24/* gauss.c */
25extern double G_math_rand_gauss(double);
26
27/* max_pow2.c */
28extern long G_math_max_pow2(long n);
29extern long G_math_min_pow2(long n);
30
31/* rand1.c */
32extern void G_math_srand(int);
33extern int G_math_srand_auto(void);
34extern float G_math_rand(void);
35
36/* del2g.c */
37extern int del2g(double *[2], int, double);
38
39/* getg.c */
40extern int getg(double, double *[2], int);
41
42/* eigen_tools.c */
43extern int G_math_egvorder(double *, double **, long);
44
45/* mult.c */
46extern int G_math_complex_mult(double *v1[2], int size1, double *v2[2],
47 int size2, double *v3[2], int size3);
48
49/* lu.c */
50extern int G_ludcmp(double **, int, int *, double *);
51extern void G_lubksb(double **a, int n, int *indx, double b[]);
52
53/* findzc.c */
54extern int G_math_findzc(double conv[], int size, double zc[], double thresh,
55 int num_orients);
56
57/* *************************************************************** */
58/* ***** WRAPPER FOR CCMATH FUNCTIONS USED IN GRASS ************** */
59/* *************************************************************** */
60extern int G_math_solv(double **, double *, int);
61extern int G_math_solvps(double **, double *, int);
62extern void G_math_solvtd(double *, double *, double *, double *, int);
63extern int G_math_solvru(double **, double *, int);
64extern int G_math_minv(double **, int);
65extern int G_math_psinv(double **, int);
66extern int G_math_ruinv(double **, int);
67extern void G_math_eigval(double **, double *, int);
68extern void G_math_eigen(double **, double *, int);
69extern double G_math_evmax(double **, double *, int);
70extern int G_math_svdval(double *, double **, int, int);
71extern int G_math_sv2val(double *, double **, int, int);
72extern int G_math_svduv(double *, double **, double **, int, double **, int);
73extern int G_math_sv2uv(double *, double **, double **, int, double **, int);
74extern int G_math_svdu1v(double *, double **, int, double **, int);
75
76/* *************************************************************** */
77/* *************** LINEARE EQUATION SYSTEM PART ****************** */
78/* *************************************************************** */
79
80/* Sparse matrix and sparse vector functions
81 * */
84extern void G_math_free_spmatrix(G_math_spvector **, int);
87extern G_math_spvector **G_math_A_to_Asp(double **, int, double);
88extern double **G_math_Asp_to_A(G_math_spvector **, int);
89extern double **G_math_Asp_to_sband_matrix(G_math_spvector **, int, int);
90extern G_math_spvector **G_math_sband_matrix_to_Asp(double **, int, int,
91 double);
92extern void G_math_print_spmatrix(G_math_spvector **, int);
93extern void G_math_Ax_sparse(G_math_spvector **, double *, double *, int);
94
95/*Symmetric band matrix handling */
96extern double **G_math_matrix_to_sband_matrix(double **, int, int);
97extern double **G_math_sband_matrix_to_matrix(double **, int, int);
98extern void G_math_Ax_sband(double **A, double *x, double *y, int rows,
99 int bandwidth);
100
101/*linear equation solver, most of them are multithreaded with OpenMP */
102extern int G_math_solver_gauss(double **, double *, double *, int);
103extern int G_math_solver_lu(double **, double *, double *, int);
104extern int G_math_solver_cholesky(double **, double *, double *, int, int);
105extern void G_math_solver_cholesky_sband(double **, double *, double *, int,
106 int);
107extern int G_math_solver_jacobi(double **, double *, double *, int, int, double,
108 double);
109extern int G_math_solver_gs(double **, double *, double *, int, int, double,
110 double);
111
112extern int G_math_solver_pcg(double **, double *, double *, int, int, double,
113 int);
114extern int G_math_solver_cg(double **, double *, double *, int, int, double);
115extern int G_math_solver_cg_sband(double **, double *, double *, int, int, int,
116 double);
117extern int G_math_solver_bicgstab(double **, double *, double *, int, int,
118 double);
119extern int G_math_solver_sparse_jacobi(G_math_spvector **, double *, double *,
120 int, int, double, double);
121extern int G_math_solver_sparse_gs(G_math_spvector **, double *, double *, int,
122 int, double, double);
123extern int G_math_solver_sparse_pcg(G_math_spvector **, double *, double *, int,
124 int, double, int);
125extern int G_math_solver_sparse_cg(G_math_spvector **, double *, double *, int,
126 int, double);
127extern int G_math_solver_sparse_bicgstab(G_math_spvector **, double *, double *,
128 int, int, double);
129
130/* solver algorithms and helper functions */
131extern void G_math_gauss_elimination(double **, double *, int);
132extern void G_math_lu_decomposition(double **, double *, int);
133extern int G_math_cholesky_decomposition(double **, int, int);
134extern void G_math_cholesky_sband_decomposition(double **, double **, int, int);
135extern void G_math_backward_substitution(double **, double *, double *, int);
136extern void G_math_forward_substitution(double **, double *, double *, int);
137extern void G_math_cholesky_sband_substitution(double **, double *, double *,
138 int, int);
139
140/*BLAS like level 1,2 and 3 functions */
141
142/*level 1 vector - vector grass implementation with OpenMP thread support */
143extern void G_math_d_x_dot_y(double *, double *, double *, int);
144extern void G_math_d_asum_norm(double *, double *, int);
145extern void G_math_d_euclid_norm(double *, double *, int);
146extern void G_math_d_max_norm(double *, double *, int);
147extern void G_math_d_ax_by(double *, double *, double *, double, double, int);
148extern void G_math_d_copy(double *, double *, int);
149
150extern void G_math_f_x_dot_y(float *, float *, float *, int);
151extern void G_math_f_asum_norm(float *, float *, int);
152extern void G_math_f_euclid_norm(float *, float *, int);
153extern void G_math_f_max_norm(float *, float *, int);
154extern void G_math_f_ax_by(float *, float *, float *, float, float, int);
155extern void G_math_f_copy(float *, float *, int);
156
157extern void G_math_i_x_dot_y(int *, int *, double *, int);
158extern void G_math_i_asum_norm(int *, double *, int);
159extern void G_math_i_euclid_norm(int *, double *, int);
160extern void G_math_i_max_norm(int *, int *, int);
161extern void G_math_i_ax_by(int *, int *, int *, int, int, int);
162extern void G_math_i_copy(int *, int *, int);
163
164/*ATLAS blas level 1 wrapper */
165extern double G_math_ddot(double *, double *, int);
166extern float G_math_sdot(float *, float *, int);
167extern float G_math_sdsdot(float *, float *, float, int);
168extern double G_math_dnrm2(double *, int);
169extern double G_math_dasum(double *, int);
170extern double G_math_idamax(double *, int);
171extern float G_math_snrm2(float *, int);
172extern float G_math_sasum(float *, int);
173extern float G_math_isamax(float *, int);
174extern void G_math_dscal(double *, double, int);
175extern void G_math_sscal(float *, float, int);
176extern void G_math_dcopy(double *, double *, int);
177extern void G_math_scopy(float *, float *, int);
178extern void G_math_daxpy(double *, double *, double, int);
179extern void G_math_saxpy(float *, float *, float, int);
180
181/*level 2 matrix - vector grass implementation with OpenMP thread support */
182extern void G_math_d_Ax(double **, double *, double *, int, int);
183extern void G_math_f_Ax(float **, float *, float *, int, int);
184extern void G_math_d_x_dyad_y(double *, double *, double **, int, int);
185extern void G_math_f_x_dyad_y(float *, float *, float **, int, int);
186extern void G_math_d_aAx_by(double **, double *, double *, double, double,
187 double *, int, int);
188extern void G_math_f_aAx_by(float **, float *, float *, float, float, float *,
189 int, int);
190extern int G_math_d_A_T(double **A, int rows);
191extern int G_math_f_A_T(float **A, int rows);
192
193/*level 3 matrix - matrix grass implementation with OpenMP thread support */
194extern void G_math_d_aA_B(double **, double **, double, double **, int, int);
195extern void G_math_f_aA_B(float **, float **, float, float **, int, int);
196extern void G_math_d_AB(double **, double **, double **, int, int, int);
197extern void G_math_f_AB(float **, float **, float **, int, int, int);
198
199#endif /* GRASS_GMATHDEFS_H */
int G_math_d_A_T(double **A, int rows)
Compute the transposition of matrix A. Matrix A will be overwritten.
int G_math_solver_sparse_jacobi(G_math_spvector **, double *, double *, int, int, double, double)
The iterative jacobi solver for sparse matrices.
void G_math_d_aAx_by(double **, double *, double *, double, double, double *, int, int)
Compute the scaled matrix - vector product of matrix double **A and vector x and y.
G_math_spvector * G_math_alloc_spvector(int)
Allocate memory for a sparse vector.
void G_math_d_ax_by(double *, double *, double *, double, double, int)
Scales vectors x and y with the scalars a and b and adds them.
int G_math_sv2uv(double *, double **, double **, int, double **, int)
Compute the singular value transformation when m >> n.
float ** G_alloc_fmatrix(int, int)
Floating point matrix memory allocation.
Definition dalloc.c:95
int G_ludcmp(double **, int, int *, double *)
LU decomposition.
Definition lu.c:17
void G_math_forward_substitution(double **, double *, double *, int)
forward substitution
int * G_alloc_ivector(size_t)
Vector matrix memory allocation.
Definition ialloc.c:38
double ** G_math_Asp_to_A(G_math_spvector **, int)
Convert a sparse matrix into a quadratic matrix.
void G_math_f_ax_by(float *, float *, float *, float, float, int)
Scales vectors x and y with the scalars a and b and adds them.
void G_math_Ax_sband(double **A, double *x, double *y, int rows, int bandwidth)
Compute the matrix - vector product of symmetric band matrix A and vector x.
void G_math_dcopy(double *, double *, int)
Copy vector x to vector y.
void G_math_f_AB(float **, float **, float **, int, int, int)
Matrix multiplication.
double G_math_rand_gauss(double)
Definition gauss.c:15
void G_math_f_aAx_by(float **, float *, float *, float, float, float *, int, int)
Compute the scaled matrix - vector product of matrix A and vectors x and y.
long G_math_max_pow2(long n)
Finds least power of 2 >= n
Definition max_pow2.c:14
void G_math_f_x_dyad_y(float *, float *, float **, int, int)
Compute the dyadic product of two vectors. The result is stored in the matrix A.
int G_math_solver_pcg(double **, double *, double *, int, int, double, int)
The iterative preconditioned conjugate gradients solver for symmetric positive definite matrices.
void G_math_sscal(float *, float, int)
Scale vector x with scalar a using the CBLAS routine cblas_dscal.
int G_math_sv2val(double *, double **, int, int)
Compute singular values when m >> n.
int G_math_solver_gs(double **, double *, double *, int, int, double, double)
The iterative gauss seidel solver for quadratic matrices.
int G_math_srand_auto(void)
Seed the pseudo-random number generator from the time and PID.
Definition rand1.c:35
void G_free_matrix(double **)
Matrix memory deallocation.
Definition dalloc.c:154
int G_math_solvru(double **, double *, int)
void G_math_free_spmatrix(G_math_spvector **, int)
Release the memory of the sparse matrix.
void G_free_imatrix(int **)
Matrix memory deallocation.
Definition ialloc.c:96
int G_math_svdu1v(double *, double **, int, double **, int)
Compute the singular value transformation with A overloaded by the partial U-matrix.
int G_math_solver_lu(double **, double *, double *, int)
The LU solver for quardatic matrices.
void G_lubksb(double **a, int n, int *indx, double b[])
LU backward substitution.
Definition lu.c:103
void G_math_i_max_norm(int *, int *, int)
Compute the maximum norm of vector x.
void G_free_fmatrix(float **)
Floating point matrix memory deallocation.
Definition dalloc.c:173
int G_math_cholesky_decomposition(double **, int, int)
cholesky decomposition for symmetric, positive definite matrices with bandwidth optimization
void G_math_cholesky_sband_decomposition(double **, double **, int, int)
Cholesky decomposition of a symmetric band matrix.
void G_math_solver_cholesky_sband(double **, double *, double *, int, int)
Cholesky symmetric band matrix solver for linear equation systems of type Ax = b.
void G_math_f_max_norm(float *, float *, int)
Compute the maximum norm of vector x.
int G_math_egvorder(double *, double **, long)
Definition eigen_tools.c:8
void G_math_i_euclid_norm(int *, double *, int)
Compute the euclid norm of vector x.
int G_math_solv(double **, double *, int)
Solve a general linear system A*x = b.
int G_math_findzc(double conv[], int size, double zc[], double thresh, int num_orients)
Finds locations and orientations of zero crossings.
Definition findzc.c:52
int G_math_solver_sparse_pcg(G_math_spvector **, double *, double *, int, int, double, int)
The iterative preconditioned conjugate gradients solver for sparse symmetric positive definite matric...
float G_math_sdsdot(float *, float *, float, int)
Compute the dot product of vector x and y using the CBLAS routine cblas_sdsdot.
G_math_spvector ** G_math_alloc_spmatrix(int)
Allocate memory for a sparse matrix.
void G_math_free_spvector(G_math_spvector *)
Release the memory of the sparse vector.
int G_math_solver_bicgstab(double **, double *, double *, int, int, double)
The iterative biconjugate gradients solver with stabilization for unsymmetric non-definite matrices.
double ** G_math_Asp_to_sband_matrix(G_math_spvector **, int, int)
Convert a symmetric sparse matrix into a symmetric band matrix.
int G_math_complex_mult(double *v1[2], int size1, double *v2[2], int size2, double *v3[2], int size3)
Definition mult.c:22
void G_math_i_ax_by(int *, int *, int *, int, int, int)
Scales vectors x and y with the scalars a and b and adds them.
double G_math_dasum(double *, int)
Compute the absolute sum norm of vector x using the CBLAS routine cblas_dasum.
int G_math_solvps(double **, double *, int)
Solve a symmetric positive definite linear system S*x = b.
int G_math_solver_sparse_bicgstab(G_math_spvector **, double *, double *, int, int, double)
The iterative biconjugate gradients solver with stabilization for unsymmetric non-definite matrices.
double * G_alloc_vector(size_t)
Vector matrix memory allocation.
Definition dalloc.c:38
float G_math_sdot(float *, float *, int)
Compute the dot product of vector x and y using the CBLAS routine cblas_sdot.
void G_math_d_x_dot_y(double *, double *, double *, int)
Compute the dot product of vector x and y.
float G_math_snrm2(float *, int)
Compute the euclidean norm of vector x using the CBLAS routine cblas_dnrm2.
void G_math_f_asum_norm(float *, float *, int)
Compute the asum norm of vector x.
void G_math_f_copy(float *, float *, int)
Copy the vector x to y.
int fft2(int, double(*)[2], int, int, int)
Fast Fourier Transform for two-dimensional array.
Definition fft.c:64
void G_free_fvector(float *)
Vector memory deallocation.
Definition dalloc.c:136
long G_math_min_pow2(long n)
Finds largest power of 2 <= n
Definition max_pow2.c:40
double ** G_math_sband_matrix_to_matrix(double **, int, int)
Convert a symmetric band matrix into a symmetric matrix.
int fft(int, double *[2], int, int, int)
Fast Fourier Transform for two-dimensional array.
Definition fft.c:120
int getg(double, double *[2], int)
Definition getg.c:15
double G_math_dnrm2(double *, int)
Compute the euclidean norm of vector x using the CBLAS routine cblas_dnrm2.
void G_math_backward_substitution(double **, double *, double *, int)
backward substitution
void G_math_cholesky_sband_substitution(double **, double *, double *, int, int)
Forward and backward substitution of a lower tringular symmetric band matrix of A from system Ax = b.
void G_math_i_asum_norm(int *, double *, int)
Compute the asum norm of vector x.
int G_math_ruinv(double **, int)
Invert an upper right triangular matrix T -> Inv(T).
int G_math_solver_sparse_cg(G_math_spvector **, double *, double *, int, int, double)
The iterative conjugate gradients solver for sparse symmetric positive definite matrices.
double G_math_evmax(double **, double *, int)
int del2g(double *[2], int, double)
Definition del2g.c:42
void G_math_Ax_sparse(G_math_spvector **, double *, double *, int)
Compute the matrix - vector product of sparse matrix **Asp and vector x.
int G_math_add_spvector(G_math_spvector **, G_math_spvector *, int)
Adds a sparse vector to a sparse matrix at position row.
void G_math_d_AB(double **, double **, double **, int, int, int)
Matrix multiplication.
int G_math_svdval(double *, double **, int, int)
Compute the singular values of a real m by n matrix A.
void G_math_f_aA_B(float **, float **, float, float **, int, int)
Add two matrices and scale matrix A with the scalar a.
void G_math_lu_decomposition(double **, double *, int)
lu decomposition
void G_math_solvtd(double *, double *, double *, double *, int)
Solve a tridiagonal linear system M*x = y.
void G_math_d_euclid_norm(double *, double *, int)
Compute the euclid norm of vector x.
void G_math_d_x_dyad_y(double *, double *, double **, int, int)
Compute the dyadic product of two vectors. The result is stored in the matrix A.
void G_math_f_x_dot_y(float *, float *, float *, int)
Compute the dot product of vector x and y.
void G_math_dscal(double *, double, int)
Scale vector x with scalar a using the CBLAS routine cblas_dscal.
double G_math_idamax(double *, int)
Compute the maximum norm of vector x using the CBLAS routine cblas_idamax.
void G_math_eigval(double **, double *, int)
Compute the eigenvalues of a real symmetric matrix A.
void G_math_gauss_elimination(double **, double *, int)
Gauss elimination.
void G_math_i_copy(int *, int *, int)
Copy the vector x to y.
int G_math_svduv(double *, double **, double **, int, double **, int)
float G_math_sasum(float *, int)
Compute the absolute sum norm of vector x using the CBLAS routine cblas_dasum.
double ** G_alloc_matrix(int, int)
Matrix memory allocation.
Definition dalloc.c:55
void G_math_d_asum_norm(double *, double *, int)
Compute the asum norm of vector x.
int G_math_solver_gauss(double **, double *, double *, int)
The gauss elimination solver for quardatic matrices.
void G_free_vector(double *)
Vector memory deallocation.
Definition dalloc.c:118
void G_math_d_aA_B(double **, double **, double, double **, int, int)
Add two matrices and scale matrix A with the scalar a.
float G_math_isamax(float *, int)
Compute the maximum norm of vector x using the CBLAS routine cblas_idamax.
void G_math_srand(int)
Seed the pseudo-random number generator.
Definition rand1.c:25
int G_math_solver_cg(double **, double *, double *, int, int, double)
The iterative conjugate gradients solver for symmetric positive definite matrices.
void G_math_i_x_dot_y(int *, int *, double *, int)
Compute the dot product of vector x and y.
int G_math_minv(double **, int)
Invert (in place) a general real matrix A -> Inv(A).
G_math_spvector ** G_math_A_to_Asp(double **, int, double)
Convert a quadratic matrix into a sparse matrix.
int G_math_f_A_T(float **A, int rows)
Compute the transposition of matrix A. Matrix A will be overwritten.
int G_math_solver_jacobi(double **, double *, double *, int, int, double, double)
The iterative jacobi solver for quadratic matrices.
void G_math_d_Ax(double **, double *, double *, int, int)
Compute the matrix - vector product of matrix A and vector x.
int G_math_solver_cholesky(double **, double *, double *, int, int)
The choleksy decomposition solver for quardatic, symmetric positive definite matrices.
G_math_spvector ** G_math_sband_matrix_to_Asp(double **, int, int, double)
Convert a symmetric band matrix into a sparse matrix.
void G_math_d_max_norm(double *, double *, int)
Compute the maximum norm of vector x.
void G_math_scopy(float *, float *, int)
Copy vector x to vector y.
void G_math_d_copy(double *, double *, int)
Copy the vector x to y.
int G_math_solver_cg_sband(double **, double *, double *, int, int, int, double)
The iterative conjugate gradients solver for symmetric positive definite band matrices.
int ** G_alloc_imatrix(int, int)
Matrix memory allocation.
Definition ialloc.c:55
void G_math_f_euclid_norm(float *, float *, int)
Compute the euclid norm of vector x.
int G_math_psinv(double **, int)
Invert (in place) a symmetric real matrix, V -> Inv(V).
void G_math_f_Ax(float **, float *, float *, int, int)
Compute the matrix - vector product of matrix A and vector x.
double G_math_ddot(double *, double *, int)
Compute the dot product of vector x and y using the CBLAS routine cblas_ddot.
int G_math_solver_sparse_gs(G_math_spvector **, double *, double *, int, int, double, double)
The iterative gauss seidel solver for sparse matrices.
float * G_alloc_fvector(size_t)
Floating point vector memory allocation.
Definition dalloc.c:78
double ** G_math_matrix_to_sband_matrix(double **, int, int)
Convert a symmetrix matrix into a symmetric band matrix.
void G_math_print_spmatrix(G_math_spvector **, int)
print the sparse matrix Asp to stdout
void G_free_ivector(int *)
Vector memory deallocation.
Definition ialloc.c:78
void G_math_eigen(double **, double *, int)
Compute the eigenvalues and eigenvectors of a real symmetric matrix A.
void G_math_saxpy(float *, float *, float, int)
Scale vector x with scalar a and add it to y.
void G_math_daxpy(double *, double *, double, int)
Scale vector x with scalar a and add it to y.
float G_math_rand(void)
Definition rand1.c:15
double b
Definition r_raster.c:39
The row vector of the sparse matrix.
Definition gmath.h:54