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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  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_CTRSV {
  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_CTRSV data_ctrsv;
  41. /**
  42. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  43. * and comparing it with the non-conjugate ctrsv.
  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_ctrsv(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_ctrsv.a_test, n * lda * 2);
  60. srand_generate(data_ctrsv.x_test, n * incx * 2);
  61. for (i = 0; i < n * lda * 2; i++)
  62. data_ctrsv.a_verify[i] = data_ctrsv.a_test[i];
  63. for (i = 0; i < n * incx * 2; i++)
  64. data_ctrsv.x_verify[i] = data_ctrsv.x_test[i];
  65. if (trans == 'R'){
  66. BLASFUNC(cimatcopy)(cc, cr, &n, &n,
  67. alpha_conj, data_ctrsv.a_verify, &lda, &lda);
  68. trans_verify = 'N';
  69. }
  70. BLASFUNC(ctrsv)(&uplo, &trans_verify, &diag, &n, data_ctrsv.a_verify,
  71. &lda, data_ctrsv.x_verify, &incx);
  72. BLASFUNC(ctrsv)(&uplo, &trans, &diag, &n, data_ctrsv.a_test, &lda,
  73. data_ctrsv.x_test, &incx);
  74. for (i = 0; i < n * incx * 2; i++)
  75. data_ctrsv.x_verify[i] -= data_ctrsv.x_test[i];
  76. return BLASFUNC(scnrm2)(&n, data_ctrsv.x_verify, &incx);
  77. }
  78. /**
  79. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  80. * and comparing it with the non-conjugate ctrsv.
  81. * Test with the following options:
  82. *
  83. * matrix A is conjugate and not-trans
  84. * matrix A is upper triangular
  85. * matrix A is not unit triangular
  86. */
  87. CTEST(ctrsv, conj_notrans_upper_not_unit_triangular)
  88. {
  89. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  90. char uplo = 'U';
  91. char diag = 'N';
  92. char trans = 'R';
  93. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  94. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  95. }
  96. /**
  97. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  98. * and comparing it with the non-conjugate ctrsv.
  99. * Test with the following options:
  100. *
  101. * matrix A is conjugate and not-trans
  102. * matrix A is upper triangular
  103. * matrix A is unit triangular
  104. */
  105. CTEST(ctrsv, conj_notrans_upper_unit_triangular)
  106. {
  107. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  108. char uplo = 'U';
  109. char diag = 'U';
  110. char trans = 'R';
  111. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  112. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  113. }
  114. /**
  115. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  116. * and comparing it with the non-conjugate ctrsv.
  117. * Test with the following options:
  118. *
  119. * matrix A is conjugate and not-trans
  120. * matrix A is lower triangular
  121. * matrix A is not unit triangular
  122. */
  123. CTEST(ctrsv, conj_notrans_lower_not_triangular)
  124. {
  125. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  126. char uplo = 'L';
  127. char diag = 'N';
  128. char trans = 'R';
  129. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  130. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  131. }
  132. /**
  133. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  134. * and comparing it with the non-conjugate ctrsv.
  135. * Test with the following options:
  136. *
  137. * matrix A is conjugate and not-trans
  138. * matrix A is lower triangular
  139. * matrix A is unit triangular
  140. */
  141. CTEST(ctrsv, conj_notrans_lower_unit_triangular)
  142. {
  143. blasint n = DATASIZE, incx = 1, lda = DATASIZE;
  144. char uplo = 'L';
  145. char diag = 'U';
  146. char trans = 'R';
  147. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  148. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  149. }
  150. /**
  151. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  152. * and comparing it with the non-conjugate ctrsv.
  153. * Test with the following options:
  154. *
  155. * matrix A is conjugate and not-trans
  156. * matrix A is upper triangular
  157. * matrix A is not unit triangular
  158. * vector x stride is 2
  159. */
  160. CTEST(ctrsv, conj_notrans_upper_not_unit_triangular_incx_2)
  161. {
  162. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  163. char uplo = 'U';
  164. char diag = 'N';
  165. char trans = 'R';
  166. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  167. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  168. }
  169. /**
  170. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  171. * and comparing it with the non-conjugate ctrsv.
  172. * Test with the following options:
  173. *
  174. * matrix A is conjugate and not-trans
  175. * matrix A is upper triangular
  176. * matrix A is unit triangular
  177. * vector x stride is 2
  178. */
  179. CTEST(ctrsv, conj_notrans_upper_unit_triangular_incx_2)
  180. {
  181. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  182. char uplo = 'U';
  183. char diag = 'U';
  184. char trans = 'R';
  185. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  186. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  187. }
  188. /**
  189. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  190. * and comparing it with the non-conjugate ctrsv.
  191. * Test with the following options:
  192. *
  193. * matrix A is conjugate and not-trans
  194. * matrix A is lower triangular
  195. * matrix A is not unit triangular
  196. * vector x stride is 2
  197. */
  198. CTEST(ctrsv, conj_notrans_lower_not_triangular_incx_2)
  199. {
  200. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  201. char uplo = 'L';
  202. char diag = 'N';
  203. char trans = 'R';
  204. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  205. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  206. }
  207. /**
  208. * Test ctrsv with the conjugate and not-transposed matrix A by conjugating matrix A
  209. * and comparing it with the non-conjugate ctrsv.
  210. * Test with the following options:
  211. *
  212. * matrix A is conjugate and not-trans
  213. * matrix A is lower triangular
  214. * matrix A is unit triangular
  215. * vector x stride is 2
  216. */
  217. CTEST(ctrsv, conj_notrans_lower_unit_triangular_incx_2)
  218. {
  219. blasint n = DATASIZE, incx = 2, lda = DATASIZE;
  220. char uplo = 'L';
  221. char diag = 'U';
  222. char trans = 'R';
  223. float norm = check_ctrsv(uplo, trans, diag, n, lda, incx);
  224. ASSERT_DBL_NEAR_TOL(0.0f, norm, DOUBLE_EPS);
  225. }
  226. #endif