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_gemv.c 2.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include "openblas_utest.h"
  2. #include <cblas.h>
  3. #ifndef NAN
  4. #define NAN 0.0/0.0
  5. #endif
  6. #ifndef INFINITY
  7. #define INFINITY 1.0/0.0
  8. #endif
  9. #ifdef BUILD_SINGLE
  10. CTEST(sgemv, 0_nan_inf)
  11. {
  12. blasint N = 17;
  13. blasint incX = 1;
  14. blasint incY = 1;
  15. float alpha = 0.0;
  16. float beta = 0.0;
  17. char trans = 'N';
  18. float A[N * N];
  19. float X[N];
  20. float Y[N];
  21. memset(A, 0, sizeof(A));
  22. memset(X, 0, sizeof(X));
  23. for (int i = 0; i < (N - 1); i += 2)
  24. {
  25. Y[i] = NAN;
  26. Y[i + 1] = INFINITY;
  27. }
  28. Y[N - 1] = NAN;
  29. BLASFUNC(sgemv)(&trans, &N, &N, &alpha, A, &N, X, &incX, &beta, Y, &incY);
  30. for (int i = 0; i < N; i ++)
  31. ASSERT_TRUE(Y[i] == 0.0);
  32. }
  33. CTEST(sgemv, 0_nan_inf_incy_2)
  34. {
  35. blasint N = 17;
  36. blasint Ny = 33;
  37. blasint incX = 1;
  38. blasint incY = 2;
  39. float alpha = 0.0;
  40. float beta = 0.0;
  41. char trans = 'N';
  42. float A[N * N];
  43. float X[N];
  44. float Y[Ny];
  45. float *ay = Y;
  46. memset(A, 0, sizeof(A));
  47. memset(X, 0, sizeof(X));
  48. memset(Y, 0, sizeof(Y));
  49. for (int i = 0; i < (N - 1); i += 2)
  50. {
  51. ay[0] = NAN;
  52. ay += 2;
  53. ay[0] = INFINITY;
  54. ay += 2;
  55. }
  56. Y[Ny - 1] = NAN;
  57. BLASFUNC(sgemv)(&trans, &N, &N, &alpha, A, &N, X, &incX, &beta, Y, &incY);
  58. for (int i = 0; i < Ny; i ++)
  59. ASSERT_TRUE(Y[i] == 0.0);
  60. }
  61. #endif
  62. #ifdef BUILD_DOUBLE
  63. CTEST(dgemv, 0_nan_inf)
  64. {
  65. blasint N = 17;
  66. blasint incX = 1;
  67. blasint incY = 1;
  68. double alpha = 0.0;
  69. double beta = 0.0;
  70. char trans = 'N';
  71. double A[N * N];
  72. double X[N];
  73. double Y[N];
  74. memset(A, 0, sizeof(A));
  75. memset(X, 0, sizeof(X));
  76. for (int i = 0; i < (N - 1); i += 2)
  77. {
  78. Y[i] = NAN;
  79. Y[i + 1] = INFINITY;
  80. }
  81. Y[N - 1] = NAN;
  82. BLASFUNC(dgemv)(&trans, &N, &N, &alpha, A, &N, X, &incX, &beta, Y, &incY);
  83. for (int i = 0; i < N; i ++)
  84. ASSERT_TRUE(Y[i] == 0.0);
  85. }
  86. CTEST(dgemv, 0_nan_inf_incy_2)
  87. {
  88. blasint N = 17;
  89. blasint Ny = 33;
  90. blasint incX = 1;
  91. blasint incY = 2;
  92. double alpha = 0.0;
  93. double beta = 0.0;
  94. char trans = 'N';
  95. double A[N * N];
  96. double X[N];
  97. double Y[Ny];
  98. double *ay = Y;
  99. memset(A, 0, sizeof(A));
  100. memset(X, 0, sizeof(X));
  101. memset(Y, 0, sizeof(Y));
  102. for (int i = 0; i < (N - 1); i += 2)
  103. {
  104. ay[0] = NAN;
  105. ay += 2;
  106. ay[0] = INFINITY;
  107. ay += 2;
  108. }
  109. Y[Ny - 1] = NAN;
  110. BLASFUNC(dgemv)(&trans, &N, &N, &alpha, A, &N, X, &incX, &beta, Y, &incY);
  111. for (int i = 0; i < Ny; i ++)
  112. ASSERT_TRUE(Y[i] == 0.0);
  113. }
  114. #endif