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_ctrmv.c 8.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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 <cblas.h>
  30. #include "common.h"
  31. #define DATASIZE 300
  32. #define INCREMENT 2
  33. struct DATA_CTRMV {
  34. float a_test[DATASIZE * DATASIZE * 2];
  35. float a_verify[DATASIZE * DATASIZE * 2];
  36. float x_test[DATASIZE * INCREMENT * 2];
  37. float x_verify[DATASIZE * INCREMENT * 2];
  38. };
  39. #ifdef BUILD_COMPLEX
  40. static struct DATA_CTRMV data_ctrmv;
  41. /**
  42. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  43. * and comparing it with the non-conjugate ctrmv.
  44. *
  45. * param uplo specifies whether A is upper or lower triangular
  46. * param trans specifies op(A), the transposition (conjugation) operation applied to A
  47. * param diag specifies whether the matrix A is unit triangular or not.
  48. * param n - numbers of rows and columns of A
  49. * param lda - leading dimension of matrix A
  50. * param incx - increment for the elements of x
  51. * return norm of difference
  52. */
  53. static float check_ctrmv(char uplo, char trans, char diag, blasint n, blasint lda, blasint incx)
  54. {
  55. blasint i;
  56. float alpha_conj[] = {1.0f, 0.0f};
  57. char trans_verify = trans;
  58. char cc[2]="C", cr[2]="R";
  59. srand_generate(data_ctrmv.a_test, n * lda * 2);
  60. srand_generate(data_ctrmv.x_test, n * incx * 2);
  61. for (i = 0; i < n * lda * 2; i++)
  62. data_ctrmv.a_verify[i] = data_ctrmv.a_test[i];
  63. for (i = 0; i < n * incx * 2; i++)
  64. data_ctrmv.x_verify[i] = data_ctrmv.x_test[i];
  65. if (trans == 'R'){
  66. BLASFUNC(cimatcopy)(cc, cr, &n, &n, alpha_conj, data_ctrmv.a_verify, &lda, &lda);
  67. trans_verify = 'N';
  68. }
  69. BLASFUNC(ctrmv)(&uplo, &trans_verify, &diag, &n, data_ctrmv.a_verify, &lda,
  70. data_ctrmv.x_verify, &incx);
  71. BLASFUNC(ctrmv)(&uplo, &trans, &diag, &n, data_ctrmv.a_test, &lda,
  72. data_ctrmv.x_test, &incx);
  73. for (i = 0; i < n * incx * 2; i++)
  74. data_ctrmv.x_verify[i] -= data_ctrmv.x_test[i];
  75. return BLASFUNC(scnrm2)(&n, data_ctrmv.x_verify, &incx);
  76. }
  77. /**
  78. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  79. * and comparing it with the non-conjugate ctrmv.
  80. * Test with the following options:
  81. *
  82. * matrix A is conjugate and not-trans
  83. * matrix A is upper triangular
  84. * matrix A is not unit triangular
  85. */
  86. CTEST(ctrmv, conj_notrans_upper_not_unit_triangular)
  87. {
  88. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  89. char uplo = 'U';
  90. char diag = 'N';
  91. char trans = 'R';
  92. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  93. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  94. }
  95. /**
  96. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  97. * and comparing it with the non-conjugate ctrmv.
  98. * Test with the following options:
  99. *
  100. * matrix A is conjugate and not-trans
  101. * matrix A is upper triangular
  102. * matrix A is unit triangular
  103. */
  104. CTEST(ctrmv, conj_notrans_upper_unit_triangular)
  105. {
  106. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  107. char uplo = 'U';
  108. char diag = 'U';
  109. char trans = 'R';
  110. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  111. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  112. }
  113. /**
  114. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  115. * and comparing it with the non-conjugate ctrmv.
  116. * Test with the following options:
  117. *
  118. * matrix A is conjugate and not-trans
  119. * matrix A is lower triangular
  120. * matrix A is not unit triangular
  121. */
  122. CTEST(ctrmv, conj_notrans_lower_not_triangular)
  123. {
  124. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  125. char uplo = 'L';
  126. char diag = 'N';
  127. char trans = 'R';
  128. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  129. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  130. }
  131. /**
  132. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  133. * and comparing it with the non-conjugate ctrmv.
  134. * Test with the following options:
  135. *
  136. * matrix A is conjugate and not-trans
  137. * matrix A is lower triangular
  138. * matrix A is unit triangular
  139. */
  140. CTEST(ctrmv, conj_notrans_lower_unit_triangular)
  141. {
  142. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  143. char uplo = 'L';
  144. char diag = 'U';
  145. char trans = 'R';
  146. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  147. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  148. }
  149. /**
  150. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  151. * and comparing it with the non-conjugate ctrmv.
  152. * Test with the following options:
  153. *
  154. * matrix A is conjugate and not-trans
  155. * matrix A is upper triangular
  156. * matrix A is not unit triangular
  157. * vector x stride is 2
  158. */
  159. CTEST(ctrmv, conj_notrans_upper_not_unit_triangular_incx_2)
  160. {
  161. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  162. char uplo = 'U';
  163. char diag = 'N';
  164. char trans = 'R';
  165. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  166. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  167. }
  168. /**
  169. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  170. * and comparing it with the non-conjugate ctrmv.
  171. * Test with the following options:
  172. *
  173. * matrix A is conjugate and not-trans
  174. * matrix A is upper triangular
  175. * matrix A is unit triangular
  176. * vector x stride is 2
  177. */
  178. CTEST(ctrmv, conj_notrans_upper_unit_triangular_incx_2)
  179. {
  180. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  181. char uplo = 'U';
  182. char diag = 'U';
  183. char trans = 'R';
  184. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  185. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  186. }
  187. /**
  188. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  189. * and comparing it with the non-conjugate ctrmv.
  190. * Test with the following options:
  191. *
  192. * matrix A is conjugate and not-trans
  193. * matrix A is lower triangular
  194. * matrix A is not unit triangular
  195. * vector x stride is 2
  196. */
  197. CTEST(ctrmv, conj_notrans_lower_not_triangular_incx_2)
  198. {
  199. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  200. char uplo = 'L';
  201. char diag = 'N';
  202. char trans = 'R';
  203. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  204. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  205. }
  206. /**
  207. * Test ctrmv with the conjugate and not-transposed matrix A by conjugating matrix A
  208. * and comparing it with the non-conjugate ctrmv.
  209. * Test with the following options:
  210. *
  211. * matrix A is conjugate and not-trans
  212. * matrix A is lower triangular
  213. * matrix A is unit triangular
  214. * vector x stride is 2
  215. */
  216. CTEST(ctrmv, conj_notrans_lower_unit_triangular_incx_2)
  217. {
  218. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  219. char uplo = 'L';
  220. char diag = 'U';
  221. char trans = 'R';
  222. float norm = check_ctrmv(uplo, trans, diag, n, lda, incx);
  223. ASSERT_DBL_NEAR_TOL(0.0f, norm, SINGLE_EPS);
  224. }
  225. #endif