GRASS GIS 8 Programmer's Manual  8.5.0dev(2024)-36359e2344
defs/gmath.h
Go to the documentation of this file.
1 #ifndef GRASS_GMATHDEFS_H
2 #define GRASS_GMATHDEFS_H
3 
4 /* dalloc.c */
5 double *G_alloc_vector(size_t);
6 double **G_alloc_matrix(int, int);
7 float *G_alloc_fvector(size_t);
8 float **G_alloc_fmatrix(int, int);
9 void G_free_vector(double *);
10 void G_free_matrix(double **);
11 void G_free_fvector(float *);
12 void G_free_fmatrix(float **);
13 
14 /* ialloc.c */
15 int *G_alloc_ivector(size_t);
16 int **G_alloc_imatrix(int, int);
17 void G_free_ivector(int *);
18 void G_free_imatrix(int **);
19 
20 /* fft.c */
21 extern int fft(int, double *[2], int, int, int);
22 extern int fft2(int, double (*)[2], int, int, int);
23 
24 /* gauss.c */
25 extern double G_math_rand_gauss(double);
26 
27 /* max_pow2.c */
28 extern long G_math_max_pow2(long n);
29 extern long G_math_min_pow2(long n);
30 
31 /* rand1.c */
32 extern void G_math_srand(int);
33 extern int G_math_srand_auto(void);
34 extern float G_math_rand(void);
35 
36 /* del2g.c */
37 extern int del2g(double *[2], int, double);
38 
39 /* getg.c */
40 extern int getg(double, double *[2], int);
41 
42 /* eigen_tools.c */
43 extern int G_math_egvorder(double *, double **, long);
44 
45 /* mult.c */
46 extern 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 */
50 extern int G_ludcmp(double **, int, int *, double *);
51 extern void G_lubksb(double **a, int n, int *indx, double b[]);
52 
53 /* findzc.c */
54 extern 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 /* *************************************************************** */
60 extern int G_math_solv(double **, double *, int);
61 extern int G_math_solvps(double **, double *, int);
62 extern void G_math_solvtd(double *, double *, double *, double *, int);
63 extern int G_math_solvru(double **, double *, int);
64 extern int G_math_minv(double **, int);
65 extern int G_math_psinv(double **, int);
66 extern int G_math_ruinv(double **, int);
67 extern void G_math_eigval(double **, double *, int);
68 extern void G_math_eigen(double **, double *, int);
69 extern double G_math_evmax(double **, double *, int);
70 extern int G_math_svdval(double *, double **, int, int);
71 extern int G_math_sv2val(double *, double **, int, int);
72 extern int G_math_svduv(double *, double **, double **, int, double **, int);
73 extern int G_math_sv2uv(double *, double **, double **, int, double **, int);
74 extern 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  * */
84 extern void G_math_free_spmatrix(G_math_spvector **, int);
87 extern G_math_spvector **G_math_A_to_Asp(double **, int, double);
88 extern double **G_math_Asp_to_A(G_math_spvector **, int);
89 extern double **G_math_Asp_to_sband_matrix(G_math_spvector **, int, int);
90 extern G_math_spvector **G_math_sband_matrix_to_Asp(double **, int, int,
91  double);
92 extern void G_math_print_spmatrix(G_math_spvector **, int);
93 extern void G_math_Ax_sparse(G_math_spvector **, double *, double *, int);
94 
95 /*Symmetric band matrix handling */
96 extern double **G_math_matrix_to_sband_matrix(double **, int, int);
97 extern double **G_math_sband_matrix_to_matrix(double **, int, int);
98 extern 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 */
102 extern int G_math_solver_gauss(double **, double *, double *, int);
103 extern int G_math_solver_lu(double **, double *, double *, int);
104 extern int G_math_solver_cholesky(double **, double *, double *, int, int);
105 extern void G_math_solver_cholesky_sband(double **, double *, double *, int,
106  int);
107 extern int G_math_solver_jacobi(double **, double *, double *, int, int, double,
108  double);
109 extern int G_math_solver_gs(double **, double *, double *, int, int, double,
110  double);
111 
112 extern int G_math_solver_pcg(double **, double *, double *, int, int, double,
113  int);
114 extern int G_math_solver_cg(double **, double *, double *, int, int, double);
115 extern int G_math_solver_cg_sband(double **, double *, double *, int, int, int,
116  double);
117 extern int G_math_solver_bicgstab(double **, double *, double *, int, int,
118  double);
119 extern int G_math_solver_sparse_jacobi(G_math_spvector **, double *, double *,
120  int, int, double, double);
121 extern int G_math_solver_sparse_gs(G_math_spvector **, double *, double *, int,
122  int, double, double);
123 extern int G_math_solver_sparse_pcg(G_math_spvector **, double *, double *, int,
124  int, double, int);
125 extern int G_math_solver_sparse_cg(G_math_spvector **, double *, double *, int,
126  int, double);
127 extern int G_math_solver_sparse_bicgstab(G_math_spvector **, double *, double *,
128  int, int, double);
129 
130 /* solver algorithms and helper functions */
131 extern void G_math_gauss_elimination(double **, double *, int);
132 extern void G_math_lu_decomposition(double **, double *, int);
133 extern int G_math_cholesky_decomposition(double **, int, int);
134 extern void G_math_cholesky_sband_decomposition(double **, double **, int, int);
135 extern void G_math_backward_substitution(double **, double *, double *, int);
136 extern void G_math_forward_substitution(double **, double *, double *, int);
137 extern 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 */
143 extern void G_math_d_x_dot_y(double *, double *, double *, int);
144 extern void G_math_d_asum_norm(double *, double *, int);
145 extern void G_math_d_euclid_norm(double *, double *, int);
146 extern void G_math_d_max_norm(double *, double *, int);
147 extern void G_math_d_ax_by(double *, double *, double *, double, double, int);
148 extern void G_math_d_copy(double *, double *, int);
149 
150 extern void G_math_f_x_dot_y(float *, float *, float *, int);
151 extern void G_math_f_asum_norm(float *, float *, int);
152 extern void G_math_f_euclid_norm(float *, float *, int);
153 extern void G_math_f_max_norm(float *, float *, int);
154 extern void G_math_f_ax_by(float *, float *, float *, float, float, int);
155 extern void G_math_f_copy(float *, float *, int);
156 
157 extern void G_math_i_x_dot_y(int *, int *, double *, int);
158 extern void G_math_i_asum_norm(int *, double *, int);
159 extern void G_math_i_euclid_norm(int *, double *, int);
160 extern void G_math_i_max_norm(int *, int *, int);
161 extern void G_math_i_ax_by(int *, int *, int *, int, int, int);
162 extern void G_math_i_copy(int *, int *, int);
163 
164 /*ATLAS blas level 1 wrapper */
165 extern double G_math_ddot(double *, double *, int);
166 extern float G_math_sdot(float *, float *, int);
167 extern float G_math_sdsdot(float *, float *, float, int);
168 extern double G_math_dnrm2(double *, int);
169 extern double G_math_dasum(double *, int);
170 extern double G_math_idamax(double *, int);
171 extern float G_math_snrm2(float *, int);
172 extern float G_math_sasum(float *, int);
173 extern float G_math_isamax(float *, int);
174 extern void G_math_dscal(double *, double, int);
175 extern void G_math_sscal(float *, float, int);
176 extern void G_math_dcopy(double *, double *, int);
177 extern void G_math_scopy(float *, float *, int);
178 extern void G_math_daxpy(double *, double *, double, int);
179 extern void G_math_saxpy(float *, float *, float, int);
180 
181 /*level 2 matrix - vector grass implementation with OpenMP thread support */
182 extern void G_math_d_Ax(double **, double *, double *, int, int);
183 extern void G_math_f_Ax(float **, float *, float *, int, int);
184 extern void G_math_d_x_dyad_y(double *, double *, double **, int, int);
185 extern void G_math_f_x_dyad_y(float *, float *, float **, int, int);
186 extern void G_math_d_aAx_by(double **, double *, double *, double, double,
187  double *, int, int);
188 extern void G_math_f_aAx_by(float **, float *, float *, float, float, float *,
189  int, int);
190 extern int G_math_d_A_T(double **A, int rows);
191 extern int G_math_f_A_T(float **A, int rows);
192 
193 /*level 3 matrix - matrix grass implementation with OpenMP thread support */
194 extern void G_math_d_aA_B(double **, double **, double, double **, int, int);
195 extern void G_math_f_aA_B(float **, float **, float, float **, int, int);
196 extern void G_math_d_AB(double **, double **, double **, int, int, int);
197 extern 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.
Definition: blas_level_2.c:342
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.
Definition: blas_level_2.c:182
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.
Definition: blas_level_1.c:173
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:99
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
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.
Definition: blas_level_1.c:390
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.
Definition: blas_level_3.c:214
double G_math_rand_gauss(double)
Definition: gauss.c:16
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.
Definition: blas_level_2.c:265
G_math_spvector * G_math_alloc_spvector(int)
Allocate memory for a sparse vector.
Definition: sparse_matrix.c:77
long G_math_max_pow2(long n)
Finds least power of 2 >= n
Definition: max_pow2.c:15
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.
Definition: blas_level_2.c:147
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:38
void G_free_matrix(double **)
Matrix memory deallocation.
Definition: dalloc.c:161
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.
Definition: blas_level_1.c:574
void G_free_fmatrix(float **)
Floating point matrix memory deallocation.
Definition: dalloc.c:181
int G_math_cholesky_decomposition(double **, int, int)
cholesky decomposition for symmetric, positive definite matrices with bandwidth optimization
G_math_spvector ** G_math_A_to_Asp(double **, int, double)
Convert a quadratic matrix into a sparse matrix.
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.
Definition: blas_level_1.c:358
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.
Definition: blas_level_1.c:512
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_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:53
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.
void G_math_free_spvector(G_math_spvector *)
Release the memory of the sparse vector.
Definition: sparse_matrix.c:99
int G_math_solver_bicgstab(double **, double *, double *, int, int, double)
The iterative biconjugate gradients solver with stabilization for unsymmetric non-definite matrices.
int G_math_complex_mult(double *v1[2], int size1, double *v2[2], int size2, double *v3[2], int size3)
Definition: mult.c:23
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.
Definition: blas_level_1.c:606
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:39
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.
Definition: blas_level_1.c:47
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.
Definition: blas_level_1.c:328
void G_math_f_copy(float *, float *, int)
Copy the vector x to y.
Definition: blas_level_1.c:453
int fft2(int, double(*)[2], int, int, int)
Fast Fourier Transform for two-dimensional array.
Definition: fft.c:65
void G_free_fvector(float *)
Vector memory deallocation.
Definition: dalloc.c:142
long G_math_min_pow2(long n)
Finds largest power of 2 <= n
Definition: max_pow2.c:42
int fft(int, double *[2], int, int, int)
Fast Fourier Transform for two-dimensional array.
Definition: fft.c:122
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.
Definition: blas_level_1.c:544
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:43
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.
Definition: sparse_matrix.c:35
void G_math_d_AB(double **, double **, double **, int, int, int)
Matrix multiplication.
Definition: blas_level_3.c:172
int G_math_svdval(double *, double **, int, int)
Compute the singular values of a real m by n matrix A.
double ** G_math_sband_matrix_to_matrix(double **, int, int)
Convert a symmetric band matrix into a symmetric matrix.
void G_math_f_aA_B(float **, float **, float, float **, int, int)
Add two matrices and scale matrix A with the scalar a.
Definition: blas_level_3.c:112
void G_math_lu_decomposition(double **, double *, int)
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.
Definition: blas_level_1.c:79
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.
Definition: blas_level_2.c:116
void G_math_f_x_dot_y(float *, float *, float *, int)
Compute the dot product of vector x and y.
Definition: blas_level_1.c:264
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.
G_math_spvector ** G_math_alloc_spmatrix(int)
Allocate memory for a sparse matrix.
Definition: sparse_matrix.c:59
void G_math_i_copy(int *, int *, int)
Copy the vector x to y.
Definition: blas_level_1.c:669
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:57
void G_math_d_asum_norm(double *, double *, int)
Compute the asum norm of vector x.
Definition: blas_level_1.c:111
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:123
void G_math_d_aA_B(double **, double **, double, double **, int, int)
Add two matrices and scale matrix A with the scalar a.
Definition: blas_level_3.c:49
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:27
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.
Definition: blas_level_1.c:480
int G_math_minv(double **, int)
Invert (in place) a general real matrix A -> Inv(A).
int G_math_f_A_T(float **A, int rows)
Compute the transposition of matrix A. Matrix A will be overwritten.
Definition: blas_level_2.c:376
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.
Definition: blas_level_2.c:46
int G_math_solver_cholesky(double **, double *, double *, int, int)
The choleksy decomposition solver for quardatic, symmetric positive definite matrices.
void G_math_d_max_norm(double *, double *, int)
Compute the maximum norm of vector x.
Definition: blas_level_1.c:141
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.
Definition: blas_level_1.c:237
double ** G_math_Asp_to_A(G_math_spvector **, int)
Convert a sparse matrix into a quadratic matrix.
double ** G_math_matrix_to_sband_matrix(double **, int, int)
Convert a symmetrix matrix into a symmetric band matrix.
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.
Definition: blas_level_1.c:296
int G_math_psinv(double **, int)
Invert (in place) a symmetric real matrix, V -> Inv(V).
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_f_Ax(float **, float *, float *, int, int)
Compute the matrix - vector product of matrix A and vector x.
Definition: blas_level_2.c:81
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:81
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:16
double b
Definition: r_raster.c:39
The row vector of the sparse matrix.
Definition: gmath.h:54
#define x