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_zaxpyc.c 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*****************************************************************************
  2. Copyright (c) 2023, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written
  16. permission.
  17. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  18. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  21. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  23. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  24. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  25. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27. **********************************************************************************/
  28. #include "utest/openblas_utest.h"
  29. #include "common.h"
  30. #define DATASIZE 100
  31. #define INCREMENT 2
  32. struct DATA_ZAXPYC {
  33. double x_test[DATASIZE * INCREMENT * 2];
  34. double x_verify[DATASIZE * INCREMENT * 2];
  35. double y_test[DATASIZE * INCREMENT * 2];
  36. double y_verify[DATASIZE * INCREMENT * 2];
  37. };
  38. #ifdef BUILD_COMPLEX16
  39. static struct DATA_ZAXPYC data_zaxpyc;
  40. /**
  41. * Test zaxpyc by conjugating vector x and comparing with zaxpy.
  42. * Compare with the following options:
  43. *
  44. * param n - number of elements in vectors x and y
  45. * param alpha - scalar alpha
  46. * param incx - increment for the elements of x
  47. * param incy - increment for the elements of y
  48. * return norm of difference
  49. */
  50. static double check_zaxpyc(blasint n, double *alpha, blasint incx, blasint incy)
  51. {
  52. blasint i;
  53. drand_generate(data_zaxpyc.x_test, n * incx * 2);
  54. drand_generate(data_zaxpyc.y_test, n * incy * 2);
  55. for (i = 0; i < n * incx * 2; i++)
  56. data_zaxpyc.x_verify[i] = data_zaxpyc.x_test[i];
  57. for (i = 0; i < n * incy * 2; i++)
  58. data_zaxpyc.y_verify[i] = data_zaxpyc.y_test[i];
  59. zconjugate_vector(n, incx, data_zaxpyc.x_verify);
  60. BLASFUNC(zaxpy)
  61. (&n, alpha, data_zaxpyc.x_verify, &incx,
  62. data_zaxpyc.y_verify, &incy);
  63. BLASFUNC(zaxpyc)
  64. (&n, alpha, data_zaxpyc.x_test, &incx,
  65. data_zaxpyc.y_test, &incy);
  66. for (i = 0; i < n * incy * 2; i++)
  67. data_zaxpyc.y_verify[i] -= data_zaxpyc.y_test[i];
  68. return BLASFUNC(dznrm2)(&n, data_zaxpyc.y_verify, &incy);
  69. }
  70. /**
  71. * Test zaxpyc by conjugating vector x and comparing with zaxpy.
  72. * Test with the following options:
  73. *
  74. * Size of vectors x, y is 100
  75. * Stride of vector x is 1
  76. * Stride of vector y is 1
  77. */
  78. CTEST(zaxpyc, conj_strides_one)
  79. {
  80. blasint n = DATASIZE, incx = 1, incy = 1;
  81. double alpha[] = {5.0, 2.2};
  82. double norm = check_zaxpyc(n, alpha, incx, incy);
  83. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  84. }
  85. /**
  86. * Test zaxpyc by conjugating vector x and comparing with zaxpy.
  87. * Test with the following options:
  88. *
  89. * Size of vectors x, y is 100
  90. * Stride of vector x is 1
  91. * Stride of vector y is 2
  92. */
  93. CTEST(zaxpyc, conj_incx_one)
  94. {
  95. blasint n = DATASIZE, incx = 1, incy = 2;
  96. double alpha[] = {5.0, 2.2};
  97. double norm = check_zaxpyc(n, alpha, incx, incy);
  98. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  99. }
  100. /**
  101. * Test zaxpyc by conjugating vector x and comparing with zaxpy.
  102. * Test with the following options:
  103. *
  104. * Size of vectors x, y is 100
  105. * Stride of vector x is 2
  106. * Stride of vector y is 1
  107. */
  108. CTEST(zaxpyc, conj_incy_one)
  109. {
  110. blasint n = DATASIZE, incx = 2, incy = 1;
  111. double alpha[] = {5.0, 2.2};
  112. double norm = check_zaxpyc(n, alpha, incx, incy);
  113. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  114. }
  115. /**
  116. * Test zaxpyc by conjugating vector x and comparing with zaxpy.
  117. * Test with the following options:
  118. *
  119. * Size of vectors x, y is 100
  120. * Stride of vector x is 2
  121. * Stride of vector y is 2
  122. */
  123. CTEST(zaxpyc, conj_strides_two)
  124. {
  125. blasint n = DATASIZE, incx = 2, incy = 2;
  126. double alpha[] = {5.0, 2.2};
  127. double norm = check_zaxpyc(n, alpha, incx, incy);
  128. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  129. }
  130. #endif