la.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /**
  2. * \file la.h
  3. *
  4. * \brief Wrapper headers for BLAS/LAPACK.
  5. *
  6. * This program is free software under the GNU General Public License
  7. * (>=v2). Read the file COPYING that comes with GRASS for details.
  8. *
  9. * \author David D. Gray <ddgray AT armacde demon co uk>
  10. * \author GRASS GIS Development Team
  11. *
  12. * \date 2000-2007
  13. */
  14. #ifndef LA_H_
  15. #define LA_H_
  16. /* QUESTION: On some systems there appears to be no default link
  17. to this. Do we create a symlink to
  18. /usr/lib/gcc-lib/<platform>/<vers_num>/include/g2c.h
  19. or link to any old f2c.h that happens to hanging around?
  20. A job for autoconf
  21. [Also a consideration for -lg2c]
  22. */
  23. #include <grass/config.h>
  24. #include <stdio.h>
  25. #ifdef HAVE_G2C_H
  26. #include <g2c.h>
  27. #else /* for gcc4+ */
  28. typedef int integer;
  29. typedef unsigned int uinteger;
  30. typedef char * address;
  31. typedef short shortint;
  32. typedef float real;
  33. typedef double doublereal;
  34. typedef struct {real r, i;} complex;
  35. typedef struct {doublereal r, i;} doublecomplex;
  36. typedef int logical;
  37. typedef short shortlogical;
  38. typedef char logical1;
  39. typedef char integer1;
  40. typedef long longint;
  41. typedef unsigned long ulongint;
  42. /* IO stuff */
  43. typedef int ftnlen;
  44. /* procedure parameter types for -A */
  45. typedef int (*U_fp)();
  46. typedef shortint (*J_fp)();
  47. typedef integer (*I_fp)();
  48. typedef real (*R_fp)();
  49. typedef doublereal (*D_fp)(), (*E_fp)();
  50. typedef void (*C_fp)();
  51. typedef void (*Z_fp)();
  52. typedef logical (*L_fp)();
  53. typedef shortlogical (*K_fp)();
  54. typedef void (*H_fp)();
  55. typedef int (*S_fp)();
  56. /* E_fp is for real functions when -R is not specified */
  57. typedef void C_f; /* complex function */
  58. typedef void H_f; /* character function */
  59. typedef void Z_f; /* double complex function */
  60. typedef doublereal E_f; /* real function with -R not specified */
  61. #endif /* HAVE_G2C_H */
  62. /* The following may have to be selectively installed according
  63. to platform, at least partly
  64. */
  65. #if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK)
  66. #include <grass/blas.h>
  67. #include <grass/lapack.h>
  68. #endif
  69. /* Useful defines */
  70. #define MAX_POS 1 /* Indicates maximum value */
  71. #define MAX_NEG -1 /* Indicates minimum value */
  72. #define MAX_ABS 0 /* Indicates absolute value */
  73. #define DO_COMPACT 0 /* Elliminate unnecessary rows (cols) in matrix */
  74. #define NO_COMPACT 1 /* ... or not */
  75. /* define macros for fortran symbols (called directly). Needed because
  76. of platform invariance on fortran->C symbol translations
  77. */
  78. #if defined(HAVE_LIBBLAS) && defined(HAVE_LIBLAPACK)
  79. #define f77_dgesv dgesv_
  80. #define f77_dgemm dgemm_
  81. #define f77_dnrm2 dnrm2_
  82. #endif
  83. /* Operations should know type of coefficient matrix, so that
  84. they can call the right driver
  85. */
  86. typedef enum { NONSYM, SYM, HERMITIAN } mat_type;
  87. typedef enum { MATRIX_, ROWVEC_, COLVEC_ } mat_spec;
  88. typedef enum { RVEC, CVEC } vtype;
  89. /************************************************************
  90. * *
  91. * A general matrix wrapper for use with BLAS / LAPACK *
  92. * routines, and perhaps elsewhere *
  93. * *
  94. ************************************************************/
  95. typedef struct matrix_ {
  96. mat_spec type; /* matrix, row vector or column vector? */
  97. int v_indx; /* If a vector, which row(column) is active?
  98. * If a matrix this is ignored. If value is < 0,
  99. * the first row(column) is assumed, ie. index 0. */
  100. int rows, cols; /* Rows and columns of matrix */
  101. int ldim; /* Lead dimension of matrix. How many `rows' are
  102. * alloc'ed? May exceed real number of rows `rows' */
  103. doublereal *vals; /* The values (should be dimensioned to lda * cols */
  104. int is_init; /* Is matrix initialised: values array
  105. * is allocated and parameters set ? */
  106. } mat_struct;
  107. typedef mat_struct vec_struct;
  108. /* Prototypes */
  109. /* Matrix routines corresponding to BLAS Level III */
  110. mat_struct *G_matrix_init(int, int, int);
  111. int G_matrix_zero(mat_struct *);
  112. int G_matrix_set(mat_struct *, int, int, int);
  113. mat_struct *G_matrix_copy(const mat_struct *);
  114. mat_struct *G_matrix_add(mat_struct *, mat_struct *);
  115. mat_struct *G_matrix_subtract(mat_struct *, mat_struct *);
  116. mat_struct *G_matrix_scale(mat_struct *, const double);
  117. mat_struct *G__matrix_add(mat_struct *, mat_struct *, const double, const double);
  118. mat_struct *G_matrix_product(mat_struct *, mat_struct *);
  119. mat_struct *G_matrix_transpose(mat_struct *);
  120. int G_matrix_LU_solve(const mat_struct *, mat_struct **, const mat_struct *, mat_type);
  121. mat_struct *G_matrix_inverse(mat_struct *);
  122. void G_matrix_free(mat_struct *);
  123. void G_matrix_print(mat_struct *);
  124. int G_matrix_set_element(mat_struct *, int, int, double);
  125. double G_matrix_get_element(mat_struct *, int, int);
  126. /* Matrix-vector routines corresponding to BLAS Level II */
  127. vec_struct *G_matvect_get_column(mat_struct *, int);
  128. vec_struct *G_matvect_get_row(mat_struct *, int);
  129. int G_matvect_extract_vector( mat_struct *, vtype, int);
  130. int G_matvect_retrieve_matrix(vec_struct *);
  131. /* Vector routines corresponding to BLAS Level I */
  132. vec_struct *G_vector_init(int, int, vtype);
  133. int G_vector_set(vec_struct *, int, int, vtype, int);
  134. double G_vector_norm_euclid(vec_struct *);
  135. double G_vector_norm_maxval(vec_struct *, int);
  136. vec_struct *G_vector_copy(const vec_struct *, int);
  137. /* Matrix and vector routines corresponding to ?? */
  138. void G_vector_free(vec_struct *);
  139. vec_struct *G_vector_sub(vec_struct *, vec_struct *, vec_struct *);
  140. double G_vector_norm1(vec_struct *);
  141. int G_matrix_read(FILE *, mat_struct *);
  142. int G_matrix_stdin(mat_struct *);
  143. int G_matrix_eigen_sort(vec_struct *, mat_struct *);
  144. #endif /* LA_H_ */