gmath.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. #ifndef GRASS_GMATHDEFS_H
  2. #define GRASS_GMATHDEFS_H
  3. /* dalloc.c */
  4. double *G_alloc_vector(size_t);
  5. double **G_alloc_matrix(int, int);
  6. float *G_alloc_fvector(size_t);
  7. float **G_alloc_fmatrix(int, int);
  8. void G_free_vector(double *);
  9. void G_free_matrix(double **);
  10. void G_free_fvector(float *);
  11. void G_free_fmatrix(float **);
  12. /* ialloc.c */
  13. int *G_alloc_ivector(size_t);
  14. int **G_alloc_imatrix(int, int);
  15. void G_free_ivector(int *);
  16. void G_free_imatrix(int **);
  17. /* fft.c */
  18. extern int fft(int, double *[2], int, int, int);
  19. extern int fft2(int, double (*)[2], int, int, int);
  20. /* gauss.c */
  21. extern double G_math_rand_gauss(double);
  22. /* max_pow2.c */
  23. extern long G_math_max_pow2 (long n);
  24. extern long G_math_min_pow2 (long n);
  25. /* rand1.c */
  26. extern void G_math_srand(int);
  27. extern int G_math_srand_auto(void);
  28. extern float G_math_rand(void);
  29. /* del2g.c */
  30. extern int del2g(double *[2], int, double);
  31. /* getg.c */
  32. extern int getg(double, double *[2], int);
  33. /* eigen_tools.c */
  34. extern int G_math_egvorder(double *, double **, long);
  35. /* mult.c */
  36. extern int G_math_complex_mult (double *v1[2], int size1, double *v2[2], int size2, double *v3[2], int size3);
  37. /* lu.c*/
  38. extern int G_ludcmp(double **, int, int *, double *);
  39. extern void G_lubksb(double **a, int n, int *indx, double b[]);
  40. /* findzc.c */
  41. extern int G_math_findzc(double conv[], int size, double zc[], double thresh, int num_orients);
  42. /* *************************************************************** */
  43. /* ***** WRAPPER FOR CCMATH FUNCTIONS USED IN GRASS ************** */
  44. /* *************************************************************** */
  45. extern int G_math_solv(double **,double *,int);
  46. extern int G_math_solvps(double **,double *,int);
  47. extern void G_math_solvtd(double *,double *,double *,double *,int);
  48. extern int G_math_solvru(double **,double *,int);
  49. extern int G_math_minv(double **,int);
  50. extern int G_math_psinv(double **,int);
  51. extern int G_math_ruinv(double **,int);
  52. extern void G_math_eigval(double **,double *,int);
  53. extern void G_math_eigen(double **,double *,int);
  54. extern double G_math_evmax(double **,double *,int);
  55. extern int G_math_svdval(double *,double **,int,int);
  56. extern int G_math_sv2val(double *,double **,int,int);
  57. extern int G_math_svduv(double *,double **,double **, int,double **,int);
  58. extern int G_math_sv2uv(double *,double **,double **,int,double **,int);
  59. extern int G_math_svdu1v(double *,double **,int,double **,int);
  60. /* *************************************************************** */
  61. /* *************** LINEARE EQUATION SYSTEM PART ****************** */
  62. /* *************************************************************** */
  63. /* Sparse matrix and sparse vector functions
  64. * */
  65. extern G_math_spvector *G_math_alloc_spvector(int );
  66. extern G_math_spvector **G_math_alloc_spmatrix(int );
  67. extern void G_math_free_spmatrix(G_math_spvector ** , int );
  68. extern void G_math_free_spvector(G_math_spvector * );
  69. extern int G_math_add_spvector(G_math_spvector **, G_math_spvector * , int );
  70. extern G_math_spvector **G_math_A_to_Asp(double **, int, double);
  71. extern double **G_math_Asp_to_A(G_math_spvector **, int);
  72. extern double **G_math_Asp_to_sband_matrix(G_math_spvector **, int, int);
  73. extern G_math_spvector **G_math_sband_matrix_to_Asp(double **, int, int, double);
  74. extern void G_math_print_spmatrix(G_math_spvector **, int);
  75. extern void G_math_Ax_sparse(G_math_spvector **, double *, double *, int );
  76. /*Symmetric band matrix handling */
  77. extern double **G_math_matrix_to_sband_matrix(double **, int, int);
  78. extern double **G_math_sband_matrix_to_matrix(double **, int, int);
  79. extern void G_math_Ax_sband(double ** A, double *x, double *y, int rows, int bandwidth);
  80. /*linear equation solver, most of them are multithreaded with OpenMP*/
  81. extern int G_math_solver_gauss(double **, double *, double *, int );
  82. extern int G_math_solver_lu(double **, double *, double *, int );
  83. extern int G_math_solver_cholesky(double **, double *, double *, int , int );
  84. extern void G_math_solver_cholesky_sband(double **, double *, double *, int, int);
  85. extern int G_math_solver_jacobi(double **, double *, double *, int , int , double , double );
  86. extern int G_math_solver_gs(double **, double *, double *, int , int , double , double );
  87. extern int G_math_solver_pcg(double **, double *, double *, int , int , double , int );
  88. extern int G_math_solver_cg(double **, double *, double *, int , int , double );
  89. extern int G_math_solver_cg_sband(double **, double *, double *, int, int, int, double);
  90. extern int G_math_solver_bicgstab(double **, double *, double *, int , int , double );
  91. extern int G_math_solver_sparse_jacobi(G_math_spvector **, double *, double *, int , int , double , double );
  92. extern int G_math_solver_sparse_gs(G_math_spvector **, double *, double *, int , int , double , double );
  93. extern int G_math_solver_sparse_pcg(G_math_spvector **, double *, double *, int , int , double , int );
  94. extern int G_math_solver_sparse_cg(G_math_spvector **, double *, double *, int , int , double );
  95. extern int G_math_solver_sparse_bicgstab(G_math_spvector **, double *, double *, int , int , double );
  96. /* solver algoithms and helper functions*/
  97. extern void G_math_gauss_elimination(double **, double *, int );
  98. extern void G_math_lu_decomposition(double **, double *, int );
  99. extern int G_math_cholesky_decomposition(double **, int , int );
  100. extern void G_math_cholesky_sband_decomposition(double **, double **, int, int);
  101. extern void G_math_backward_substitution(double **, double *, double *, int );
  102. extern void G_math_forward_substitution(double **, double *, double *, int );
  103. extern void G_math_cholesky_sband_substitution(double **, double *, double *, int, int);
  104. /*BLAS like level 1,2 and 3 functions*/
  105. /*level 1 vector - vector grass implementation with OpenMP thread support*/
  106. extern void G_math_d_x_dot_y(double *, double *, double *, int );
  107. extern void G_math_d_asum_norm(double *, double *, int );
  108. extern void G_math_d_euclid_norm(double *, double *, int );
  109. extern void G_math_d_max_norm(double *, double *, int );
  110. extern void G_math_d_ax_by(double *, double *, double *, double , double , int );
  111. extern void G_math_d_copy(double *, double *, int );
  112. extern void G_math_f_x_dot_y(float *, float *, float *, int );
  113. extern void G_math_f_asum_norm(float *, float *, int );
  114. extern void G_math_f_euclid_norm(float *, float *, int );
  115. extern void G_math_f_max_norm(float *, float *, int );
  116. extern void G_math_f_ax_by(float *, float *, float *, float , float , int );
  117. extern void G_math_f_copy(float *, float *, int );
  118. extern void G_math_i_x_dot_y(int *, int *, double *, int );
  119. extern void G_math_i_asum_norm(int *, double *, int );
  120. extern void G_math_i_euclid_norm(int *, double *,int );
  121. extern void G_math_i_max_norm(int *, int *, int );
  122. extern void G_math_i_ax_by(int *, int *, int *, int , int , int );
  123. extern void G_math_i_copy(int *, int *, int );
  124. /*ATLAS blas level 1 wrapper*/
  125. extern double G_math_ddot(double *, double *, int );
  126. extern float G_math_sdot(float *, float *, int );
  127. extern float G_math_sdsdot(float *, float *, float , int );
  128. extern double G_math_dnrm2(double *, int );
  129. extern double G_math_dasum(double *, int );
  130. extern double G_math_idamax(double *, int );
  131. extern float G_math_snrm2(float *, int );
  132. extern float G_math_sasum(float *, int );
  133. extern float G_math_isamax(float *, int );
  134. extern void G_math_dscal(double *, double , int );
  135. extern void G_math_sscal(float *, float , int );
  136. extern void G_math_dcopy(double *, double *, int );
  137. extern void G_math_scopy(float *, float *, int );
  138. extern void G_math_daxpy(double *, double *, double , int );
  139. extern void G_math_saxpy(float *, float *, float , int );
  140. /*level 2 matrix - vector grass implementation with OpenMP thread support*/
  141. extern void G_math_d_Ax(double **, double *, double *, int , int );
  142. extern void G_math_f_Ax(float **, float *, float *, int , int );
  143. extern void G_math_d_x_dyad_y(double *, double *, double **, int, int );
  144. extern void G_math_f_x_dyad_y(float *, float *, float **, int, int );
  145. extern void G_math_d_aAx_by(double **, double *, double *, double , double , double *, int , int );
  146. extern void G_math_f_aAx_by(float **, float *, float *, float , float , float *, int , int );
  147. extern int G_math_d_A_T(double **A, int rows);
  148. extern int G_math_f_A_T(float **A, int rows);
  149. /*level 3 matrix - matrix grass implementation with OpenMP thread support*/
  150. extern void G_math_d_aA_B(double **, double **, double , double **, int , int );
  151. extern void G_math_f_aA_B(float **, float **, float , float **, int , int );
  152. extern void G_math_d_AB(double **, double **, double **, int , int , int );
  153. extern void G_math_f_AB(float **, float **, float **, int , int , int );
  154. #endif /* GRASS_GMATHDEFS_H */