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_caxpyc.c 4.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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_CAXPYC {
  33. float x_test[DATASIZE * INCREMENT * 2];
  34. float x_verify[DATASIZE * INCREMENT * 2];
  35. float y_test[DATASIZE * INCREMENT * 2];
  36. float y_verify[DATASIZE * INCREMENT * 2];
  37. };
  38. #ifdef BUILD_COMPLEX
  39. static struct DATA_CAXPYC data_caxpyc;
  40. /**
  41. * Test caxpyc by conjugating vector x and comparing with caxpy.
  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 float check_caxpyc(blasint n, float *alpha, blasint incx, blasint incy)
  51. {
  52. blasint i;
  53. srand_generate(data_caxpyc.x_test, n * incx * 2);
  54. srand_generate(data_caxpyc.y_test, n * incy * 2);
  55. for (i = 0; i < n * incx * 2; i++)
  56. data_caxpyc.x_verify[i] = data_caxpyc.x_test[i];
  57. for (i = 0; i < n * incy * 2; i++)
  58. data_caxpyc.y_verify[i] = data_caxpyc.y_test[i];
  59. cconjugate_vector(n, incx, data_caxpyc.x_verify);
  60. BLASFUNC(caxpy)(&n, alpha, data_caxpyc.x_verify, &incx,
  61. data_caxpyc.y_verify, &incy);
  62. BLASFUNC(caxpyc)(&n, alpha, data_caxpyc.x_test, &incx,
  63. data_caxpyc.y_test, &incy);
  64. for (i = 0; i < n * incy * 2; i++)
  65. data_caxpyc.y_verify[i] -= data_caxpyc.y_test[i];
  66. return BLASFUNC(scnrm2)(&n, data_caxpyc.y_verify, &incy);
  67. }
  68. /**
  69. * Test caxpyc by conjugating vector x and comparing with caxpy.
  70. * Test with the following options:
  71. *
  72. * Size of vectors x, y is 100
  73. * Stride of vector x is 1
  74. * Stride of vector y is 1
  75. */
  76. CTEST(caxpyc, conj_strides_one)
  77. {
  78. blasint n = DATASIZE, incx = 1, incy = 1;
  79. float alpha[] = {5.0f, 2.2f};
  80. float norm = check_caxpyc(n, alpha, incx, incy);
  81. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  82. }
  83. /**
  84. * Test caxpyc by conjugating vector x and comparing with caxpy.
  85. * Test with the following options:
  86. *
  87. * Size of vectors x, y is 100
  88. * Stride of vector x is 1
  89. * Stride of vector y is 2
  90. */
  91. CTEST(caxpyc, conj_incx_one)
  92. {
  93. blasint n = DATASIZE, incx = 1, incy = 2;
  94. float alpha[] = {5.0f, 2.2f};
  95. float norm = check_caxpyc(n, alpha, incx, incy);
  96. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  97. }
  98. /**
  99. * Test caxpyc by conjugating vector x and comparing with caxpy.
  100. * Test with the following options:
  101. *
  102. * Size of vectors x, y is 100
  103. * Stride of vector x is 2
  104. * Stride of vector y is 1
  105. */
  106. CTEST(caxpyc, conj_incy_one)
  107. {
  108. blasint n = DATASIZE, incx = 2, incy = 1;
  109. float alpha[] = {5.0f, 2.2f};
  110. float norm = check_caxpyc(n, alpha, incx, incy);
  111. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  112. }
  113. /**
  114. * Test caxpyc by conjugating vector x and comparing with caxpy.
  115. * Test with the following options:
  116. *
  117. * Size of vectors x, y is 100
  118. * Stride of vector x is 2
  119. * Stride of vector y is 2
  120. */
  121. CTEST(caxpyc, conj_strides_two)
  122. {
  123. blasint n = DATASIZE, incx = 2, incy = 2;
  124. float alpha[] = {5.0f, 2.2f};
  125. float norm = check_caxpyc(n, alpha, incx, incy);
  126. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  127. }
  128. #endif