You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

test.h 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #ifndef TEST_H
  2. #define TEST_H
  3. #include "../config.h"
  4. #include "config.h"
  5. #if BLAS_UNDERSCORE
  6. #define BLAS(routine) routine ## _
  7. #else
  8. #define BLAS(routine) routine
  9. #endif
  10. #if LAPACK_UNDERSCORE
  11. #define LAPACK(routine) routine ## _
  12. #else
  13. #define LAPACK(routine) routine
  14. #endif
  15. #include "../inc/relapack.h"
  16. #include "lapack.h"
  17. #include "util.h"
  18. #include <stdlib.h>
  19. #include <stdio.h>
  20. #include <string.h>
  21. // some name mangling macros
  22. #define CAT(A, B) A ## B
  23. #define XCAT(A, B) CAT(A, B)
  24. #define XLAPACK(X) LAPACK(X)
  25. #define XRELAPACK(X) XCAT(RELAPACK_, X)
  26. #define STR(X) #X
  27. #define XSTR(X) STR(X)
  28. // default setup and error computation names: pre() and post()
  29. #define PRE pre
  30. #define POST post
  31. // TEST macro:
  32. // run setup (pre()), ReLAPACK routine (i = 0), LAPACK routine (i = 1), compute
  33. // error (post()), check error bound, and print setup and error
  34. #define TEST(...) \
  35. PRE(); \
  36. i = 0; \
  37. XRELAPACK(ROUTINE)(__VA_ARGS__); \
  38. i = 1; \
  39. XLAPACK(ROUTINE)(__VA_ARGS__); \
  40. POST(); \
  41. fail |= error > ERR_BOUND; \
  42. printf("%s(%s)\t%g\n", XSTR(ROUTINE), #__VA_ARGS__, error);
  43. // generalized datatype treatment: DT_PREFIX determines the type s, d, c, or z
  44. #define XPREF(A) XCAT(DT_PREFIX, A)
  45. // matrix generation and error computation routines
  46. #define x2matgen XPREF(2matgen)
  47. #define x2vecerr XPREF(2vecerr)
  48. // error bounds
  49. #define ERR_BOUND XPREF(ERR_BOUND_)
  50. #define sERR_BOUND_ SINGLE_ERR_BOUND
  51. #define dERR_BOUND_ DOUBLE_ERR_BOUND
  52. #define cERR_BOUND_ SINGLE_ERR_BOUND
  53. #define zERR_BOUND_ DOUBLE_ERR_BOUND
  54. // C datatypes
  55. #define datatype XPREF(datatype_)
  56. #define sdatatype_ float
  57. #define ddatatype_ double
  58. #define cdatatype_ float
  59. #define zdatatype_ double
  60. // number of C datatype elements per element
  61. #define x1 XPREF(DT_MULT)
  62. #define sDT_MULT 1
  63. #define dDT_MULT 1
  64. #define cDT_MULT 2
  65. #define zDT_MULT 2
  66. // typed allocations
  67. #define xmalloc XPREF(malloc)
  68. #define imalloc(S) malloc((S) * sizeof(int))
  69. #define smalloc(S) malloc((S) * sizeof(float))
  70. #define dmalloc(S) malloc((S) * sizeof(double))
  71. #define cmalloc(S) malloc((S) * 2 * sizeof(float))
  72. #define zmalloc(S) malloc((S) * 2 * sizeof(double))
  73. // transpositions
  74. #define xCTRANS XPREF(CTRANS)
  75. #define sCTRANS "T"
  76. #define dCTRANS "T"
  77. #define cCTRANS "C"
  78. #define zCTRANS "C"
  79. // some constants
  80. #define MONE XPREF(MONE)
  81. const float sMONE[] = { -1. };
  82. const double dMONE[] = { -1. };
  83. const float cMONE[] = { -1., 0. };
  84. const double zMONE[] = { -1., 0. };
  85. #define ZERO XPREF(ZERO)
  86. const float sZERO[] = { 0. };
  87. const double dZERO[] = { 0. };
  88. const float cZERO[] = { 0., 0. };
  89. const double zZERO[] = { 0., 0. };
  90. #define ONE XPREF(ONE)
  91. const float sONE[] = { 1. };
  92. const double dONE[] = { 1. };
  93. const float cONE[] = { 1., 0. };
  94. const double zONE[] = { 1., 0. };
  95. const int iMONE[] = { -1 };
  96. const int iZERO[] = { 0 };
  97. const int iONE[] = { 1 };
  98. const int iTWO[] = { 2 };
  99. const int iTHREE[] = { 3 };
  100. const int iFOUR[] = { 4 };
  101. void tests();
  102. // global variables (used in tests(), pre(), and post())
  103. int i, n, n2, fail;
  104. double error;
  105. int main(int argc, char* argv[]) {
  106. n = TEST_SIZE;
  107. n2 = (3 * n) / 4;
  108. fail = 0;
  109. tests();
  110. return fail;
  111. }
  112. #endif /* TEST_H */