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

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