home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / math / ols / matalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-28  |  1.2 KB  |  57 lines

  1. /*
  2. Allocate matrix A[rl..rh, cl..ch] in such a way that all the storage
  3. for it is in a contiguous block.
  4.  
  5. E.g., A[2..4, -1..2] is
  6.  
  7.    -1  0  1  2
  8. 2
  9. 3
  10. 4
  11.  
  12. You would get this matrix by calling matrix(2, 4, -1, 2);
  13.  
  14. All the work is done by the file "matalloc.inc", which creates
  15. matrices of type MATTYPE.  In this file, we merely tweak MATTYPE
  16. several times and include matalloc.inc repeatedly.
  17. */
  18.  
  19. #include <stdlib.h>
  20. #include <stdio.h>
  21. #include "utils.h"
  22.  
  23. #define MATTYPE float
  24. /* This makes the (fixed) code behave asif it was written
  25.     with float matrices in mind. */
  26. MATTYPE **
  27. matrix (int rl, int rh, int cl, int ch)
  28. #include "matalloc.inc"
  29. #undef MATTYPE
  30.      /* You'll get warnings about "MATTYPE redefined" otherwise.  */
  31.  
  32. #define MATTYPE double
  33.      MATTYPE **dmatrix (int rl, int rh, int cl, int ch)
  34. #include "matalloc.inc"
  35.      /* That gives us double matrices. */
  36. #undef MATTYPE
  37.  
  38. #define MATTYPE int
  39.      MATTYPE **imatrix (int rl, int rh, int cl, int ch)
  40. #include "matalloc.inc"
  41.      /* That gives us int matrices. */
  42. #undef MATTYPE
  43.  
  44. #ifdef TESTING
  45.      int main ()
  46. {
  47.   float **M;
  48.   int i;
  49.  
  50.   for (i = 1; i < 100000; i++)
  51.     M = matrix (1, 10, 1, 2);
  52.  
  53.   return 0;
  54. }
  55.  
  56. #endif
  57.