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