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_zgemv_t.c 29 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144
  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 N 100
  31. #define M 100
  32. #define INCREMENT 2
  33. struct DATA_ZGEMV_T {
  34. double a_test[N * M * 2];
  35. double a_verify[N * M * 2];
  36. double y_test[M * INCREMENT * 2];
  37. double y_verify[M * INCREMENT * 2];
  38. double x_test[M * INCREMENT * 2];
  39. double x_verify[M * INCREMENT * 2];
  40. };
  41. // DOUBLE_EPS_ZGEMV = MAX_VAL * NUMBER OF OPERATIONS * DBL_EPSILON
  42. // DOUBLE_EPS_ZGEMV = 5.0 * O(100 * 100) * 2.2e-16 = 1e-11
  43. #define DOUBLE_EPS_ZGEMV 1e-11
  44. #ifdef BUILD_COMPLEX16
  45. static struct DATA_ZGEMV_T data_zgemv_t;
  46. /**
  47. * Find product of matrix-vector multiplication
  48. *
  49. * param n specifies number of columns of A
  50. * param m specifies number of rows of A and size of vector x
  51. * param lda specifies leading dimension of A
  52. * param inc_x specifies increment of vector x
  53. */
  54. static void matrix_vector_product(blasint n, blasint m, blasint lda, blasint inc_x)
  55. {
  56. blasint i;
  57. blasint one=1;
  58. double *a_ptr = data_zgemv_t.a_verify;
  59. double *x_ptr = data_zgemv_t.x_test;
  60. double *x_res = data_zgemv_t.x_verify;
  61. openblas_complex_double result;
  62. for (i = 0; i < n * inc_x; i += inc_x)
  63. {
  64. #ifdef RETURN_BY_STACK
  65. BLASFUNC(zdotu)(&result, &lda, a_ptr, &one, x_ptr, &inc_x);
  66. #else
  67. result = BLASFUNC(zdotu)(&lda, a_ptr, &one, x_ptr, &inc_x);
  68. #endif
  69. x_res[0] = CREAL(result);
  70. x_res[1] = CIMAG(result);
  71. a_ptr += lda * 2;
  72. x_res += 2 * inc_x;
  73. }
  74. }
  75. /**
  76. * Test zgemv by comparing it against zomatcopy, zaxpby and
  77. * reference func matrix_vector_product
  78. *
  79. * zomatcopy perform operation: op(A)
  80. * matrix_vector_product perform operation: A*x
  81. * zaxpby perform operation: alpha*x + beta*y
  82. *
  83. * param api specifies tested api (C or Fortran)
  84. * param order specifies row or column major order
  85. * param trans specifies op(A), the transposition operation
  86. * applied to the matrix A
  87. * param m specifies number of rows of A
  88. * param n specifies number of columns of A
  89. * param alpha specifies scalar alpha
  90. * param lda specifies leading dimension of the matrix A
  91. * param inc_x specifies increment for vector x
  92. * param beta specifies scalar beta
  93. * param inc_y specifies increment for vector y
  94. * return norm of difference between zgemv and result of reference funcs
  95. */
  96. static double check_zgemv(char api, char order, char trans, blasint m, blasint n, double *alpha,
  97. blasint lda, blasint inc_x, double *beta, blasint inc_y)
  98. {
  99. blasint i;
  100. enum CBLAS_ORDER corder;
  101. enum CBLAS_TRANSPOSE ctrans;
  102. // Transpose parameters for zomatcopy
  103. // zgemv_t perform operation on transposed matrix, no need to transpose a_verify
  104. char trans_copy;
  105. char ctrans_copy;
  106. // Param alpha for zomatcopy, scale on alpha perform zaxpby
  107. double alpha_one[] = {1.0, 0.0};
  108. memset(data_zgemv_t.x_verify, 0.0, m * inc_x * 2 * sizeof(double));
  109. // Fill matrix A, vectors x, y
  110. drand_generate(data_zgemv_t.a_test, lda * n * 2);
  111. drand_generate(data_zgemv_t.x_test, m * inc_x * 2);
  112. drand_generate(data_zgemv_t.y_test, m * inc_y * 2);
  113. // Copy vector y for reference funcs
  114. for (i = 0; i < m * inc_y * 2; i++)
  115. {
  116. data_zgemv_t.y_verify[i] = data_zgemv_t.y_test[i];
  117. }
  118. if (api == 'F') {
  119. if (trans == 'T') trans_copy = 'N';
  120. if (trans == 'C') trans_copy = 'R';
  121. if (trans == 'U') trans_copy = 'R';
  122. if (trans == 'D') trans_copy = 'N';
  123. // Perform operation: op(A)
  124. BLASFUNC(zomatcopy)(&order, &trans_copy, &m, &n, alpha_one,
  125. data_zgemv_t.a_test, &lda, data_zgemv_t.a_verify, &lda);
  126. // Find A*x
  127. matrix_vector_product(n, m, lda, inc_x);
  128. // Find conj(x)
  129. if (trans == 'U' || trans == 'D')
  130. {
  131. zconjugate_vector(m, inc_x, data_zgemv_t.x_verify);
  132. }
  133. // Find alpha*x+beta*y
  134. BLASFUNC(zaxpby)(&n, alpha, data_zgemv_t.x_verify, &inc_x, beta,
  135. data_zgemv_t.y_verify, &inc_y);
  136. BLASFUNC(zgemv)(&trans, &m, &n, alpha, data_zgemv_t.a_test, &lda,
  137. data_zgemv_t.x_test, &inc_x, beta, data_zgemv_t.y_test, &inc_y);
  138. }
  139. #ifndef NO_CBLAS
  140. else {
  141. if (order == 'C') corder = CblasColMajor;
  142. if (order == 'R') corder = CblasRowMajor;
  143. if (trans == 'T') {ctrans = CblasTrans; ctrans_copy = (corder == CblasRowMajor) ? CblasTrans : CblasNoTrans;}
  144. if (trans == 'N') {ctrans = CblasNoTrans; ctrans_copy = (corder == CblasRowMajor) ? CblasNoTrans : CblasTrans;}
  145. if (trans == 'C') {ctrans = CblasConjTrans; ctrans_copy = (corder == CblasRowMajor) ? CblasConjTrans : CblasConjNoTrans;}
  146. if (trans == 'R') {ctrans = CblasConjNoTrans; ctrans_copy = (corder == CblasRowMajor) ? CblasConjNoTrans : CblasConjTrans;}
  147. // Perform operation: op(A)
  148. cblas_zomatcopy(corder, ctrans_copy, m, n, alpha_one, data_zgemv_t.a_test, lda, data_zgemv_t.a_verify, lda);
  149. // Find A*x
  150. matrix_vector_product(n, m, lda, inc_x);
  151. // Find alpha*x+beta*y
  152. cblas_zaxpby(n, alpha, data_zgemv_t.x_verify, inc_x, beta, data_zgemv_t.y_verify, inc_y);
  153. cblas_zgemv(corder, ctrans, m, n, alpha, data_zgemv_t.a_test,
  154. lda, data_zgemv_t.x_test, inc_x, beta, data_zgemv_t.y_test, inc_y);
  155. }
  156. #endif
  157. // Find the differences between output vector caculated by zgemv and reference funcs
  158. for (i = 0; i < m * inc_y * 2; i++)
  159. data_zgemv_t.y_test[i] -= data_zgemv_t.y_verify[i];
  160. // Find the norm of differences
  161. return BLASFUNC(dznrm2)(&m, data_zgemv_t.y_test, &inc_y);
  162. }
  163. /**
  164. * Check if error function was called with expected function name
  165. * and param info
  166. *
  167. * param order specifies row or column major order
  168. * param trans specifies op(A), the transposition operation
  169. * applied to the matrix A
  170. * param m specifies number of rows of A
  171. * param n specifies number of columns of A
  172. * param lda specifies leading dimension of the matrix A
  173. * param inc_x specifies increment for vector x
  174. * param inc_y specifies increment for vector y
  175. * param expected_info - expected invalid parameter number
  176. * return TRUE if everything is ok, otherwise FALSE
  177. */
  178. static int check_badargs(char order, char trans, blasint m, blasint n,
  179. blasint lda, blasint inc_x, blasint inc_y, int expected_info)
  180. {
  181. double alpha[] = {1.0, 1.0};
  182. double a[] = {1.0, 1.0};
  183. double x[] = {1.0, 1.0};
  184. double beta[] = {1.0, 1.0};
  185. double y[] = {1.0, 1.0};
  186. set_xerbla("ZGEMV ", expected_info);
  187. BLASFUNC(zgemv)(&trans, &m, &n, alpha, a, &lda, x,
  188. &inc_x, beta, y, &inc_y);
  189. return check_error();
  190. }
  191. #ifndef NO_CBLAS
  192. /**
  193. * C API specific function
  194. * Check if error function was called with expected function name
  195. * and param info
  196. *
  197. * param order specifies row or column major order
  198. * param trans specifies op(A), the transposition operation
  199. * applied to the matrix A
  200. * param m specifies number of rows of A
  201. * param n specifies number of columns of A
  202. * param lda specifies leading dimension of the matrix A
  203. * param inc_x specifies increment for vector x
  204. * param inc_y specifies increment for vector y
  205. * param expected_info - expected invalid parameter number
  206. * return TRUE if everything is ok, otherwise FALSE
  207. */
  208. static int c_api_check_badargs(CBLAS_ORDER corder, CBLAS_TRANSPOSE ctrans, blasint m, blasint n,
  209. blasint lda, blasint inc_x, blasint inc_y, int expected_info)
  210. {
  211. double alpha[] = {1.0, 1.0};
  212. double a[] = {1.0, 1.0};
  213. double x[] = {1.0, 1.0};
  214. double beta[] = {1.0, 1.0};
  215. double y[] = {1.0, 1.0};
  216. set_xerbla("ZGEMV ", expected_info);
  217. cblas_zgemv(corder, ctrans, m, n, alpha, a, lda, x, inc_x, beta, y, inc_y);
  218. return check_error();
  219. }
  220. /**
  221. * Fortran API specific test
  222. * Test zgemv by comparing it against reference
  223. * with the following options:
  224. *
  225. * Column Major
  226. * Transposition
  227. * Square matrix
  228. * inc x = 2, inc y = 1
  229. * alpha_r = 1.0, alpha_i = 1.0
  230. * beta_r = 2.0, beta_i = 2.0
  231. */
  232. CTEST(zgemv, colmajor_trans_col_100_row_100_inc_x_1_y_1)
  233. {
  234. blasint m = 100, n = 100;
  235. blasint lda = 100;
  236. char order = 'C';
  237. char trans = 'T';
  238. double alpha[] = {2.0, 1.0};
  239. double beta[] = {1.0, 2.0};
  240. blasint inc_x = 1;
  241. blasint inc_y = 1;
  242. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  243. inc_x, beta, inc_y);
  244. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  245. }
  246. /**
  247. * Fortran API specific test
  248. * Test zgemv by comparing it against reference
  249. * with the following options:
  250. *
  251. * Column Major
  252. * Transposition
  253. * Square matrix
  254. * inc x = 2, inc y = 1
  255. * alpha_r = 1.0, alpha_i = 1.0
  256. * beta_r = 2.0, beta_i = 2.0
  257. */
  258. CTEST(zgemv, colmajor_trans_col_100_row_100_inc_x_2_y_1)
  259. {
  260. blasint m = 100, n = 100;
  261. blasint lda = 100;
  262. char order = 'C';
  263. char trans = 'T';
  264. double alpha[] = {1.0, 1.0};
  265. double beta[] = {2.0, 2.0};
  266. blasint inc_x = 2;
  267. blasint inc_y = 1;
  268. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  269. inc_x, beta, inc_y);
  270. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  271. }
  272. /**
  273. * Fortran API specific test
  274. * Test zgemv by comparing it against reference
  275. * with the following options:
  276. *
  277. * Column Major
  278. * Transposition and conjugate A
  279. * Square matrix
  280. * inc x = 1, inc y = 1
  281. * alpha_r = 2.0, alpha_i = 1.0
  282. * beta_r = 2.0, beta_i = 1.0
  283. */
  284. CTEST(zgemv, colmajor_conjtrans_col_100_row_100_inc_x_1_y_1)
  285. {
  286. blasint m = 100, n = 100;
  287. blasint lda = 100;
  288. char order = 'C';
  289. char trans = 'C';
  290. double alpha[] = {2.0, 1.0};
  291. double beta[] = {2.0, 1.0};
  292. blasint inc_x = 1;
  293. blasint inc_y = 1;
  294. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  295. inc_x, beta, inc_y);
  296. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  297. }
  298. /**
  299. * Fortran API specific test
  300. * Test zgemv by comparing it against reference
  301. * with the following options:
  302. *
  303. * Column Major
  304. * Transposition and conjugate A
  305. * Square matrix
  306. * inc x = 1, inc y = 2
  307. * alpha_r = 2.0, alpha_i = 1.0
  308. * beta_r = 2.0, beta_i = 1.0
  309. */
  310. CTEST(zgemv, colmajor_conjtrans_col_100_row_100_inc_x_1_y_2)
  311. {
  312. blasint m = 100, n = 100;
  313. blasint lda = 100;
  314. char order = 'C';
  315. char trans = 'C';
  316. double alpha[] = {1.0, 1.0};
  317. double beta[] = {1.0, 1.0};
  318. blasint inc_x = 1;
  319. blasint inc_y = 2;
  320. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  321. inc_x, beta, inc_y);
  322. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  323. }
  324. /**
  325. * Fortran API specific test
  326. * Test zgemv by comparing it against reference
  327. * with the following options:
  328. *
  329. * Column Major
  330. * Transposition and x conjugate
  331. * Square matrix
  332. * inc x = 1, inc y = 1
  333. * alpha_r = 2.0, alpha_i = 1.0
  334. * beta_r = 2.0, beta_i = 1.0
  335. */
  336. CTEST(zgemv, colmajor_trans_x_conj_col_100_row_100_inc_x_1_y_1)
  337. {
  338. blasint m = 100, n = 100;
  339. blasint lda = 100;
  340. char order = 'C';
  341. char trans = 'U';
  342. double alpha[] = {1.0, 1.0};
  343. double beta[] = {1.0, 1.0};
  344. blasint inc_x = 1;
  345. blasint inc_y = 1;
  346. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  347. inc_x, beta, inc_y);
  348. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  349. }
  350. /**
  351. * Fortran API specific test
  352. * Test zgemv by comparing it against reference
  353. * with the following options:
  354. *
  355. * Column Major
  356. * Transposition and x conjugate
  357. * Square matrix
  358. * inc x = 2, inc y = 2
  359. * alpha_r = 1.0, alpha_i = 2.0
  360. * beta_r = 1.0, beta_i = 1.0
  361. */
  362. CTEST(zgemv, colmajor_trans_x_conj_col_100_row_100_inc_x_2_y_2)
  363. {
  364. blasint m = 100, n = 100;
  365. blasint lda = 100;
  366. char order = 'C';
  367. char trans = 'U';
  368. double alpha[] = {1.0, 2.0};
  369. double beta[] = {1.0, 1.0};
  370. blasint inc_x = 2;
  371. blasint inc_y = 2;
  372. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  373. inc_x, beta, inc_y);
  374. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  375. }
  376. /**
  377. * Fortran API specific test
  378. * Test zgemv by comparing it against reference
  379. * with the following options:
  380. *
  381. * Column Major
  382. * Transposition, conjugate A, conjugate x
  383. * Square matrix
  384. * inc x = 2, inc y = 2
  385. * alpha_r = 2.0, alpha_i = 1.0
  386. * beta_r = 1.0, beta_i = 2.0
  387. */
  388. CTEST(zgemv, colmajor_conjtrans_x_conj_col_100_row_100_inc_x_1_y_2)
  389. {
  390. blasint m = 100, n = 100;
  391. blasint lda = 100;
  392. char order = 'C';
  393. char trans = 'D';
  394. double alpha[] = {2.0, 1.0};
  395. double beta[] = {1.0, 2.0};
  396. blasint inc_x = 1;
  397. blasint inc_y = 2;
  398. double norm = check_zgemv('F', order, trans, m, n, alpha, lda,
  399. inc_x, beta, inc_y);
  400. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  401. }
  402. /**
  403. * C API specific test
  404. * Test zgemv by comparing it against reference
  405. * with the following options:
  406. *
  407. * Column Major
  408. * Transposition, conjugate A, conjugate x
  409. * Square matrix
  410. * inc x = 2, inc y = 1
  411. * alpha_r = 2.0, alpha_i = 1.0
  412. * beta_r = 1.0, beta_i = 2.0
  413. */
  414. CTEST(zgemv, c_api_colmajor_trans_col_100_row_100_inc_x_1_y_1)
  415. {
  416. blasint m = 100, n = 100;
  417. blasint lda = 100;
  418. char order = 'C';
  419. char trans = 'T';
  420. double alpha[] = {2.0, 1.0};
  421. double beta[] = {1.0, 2.0};
  422. blasint inc_x = 1;
  423. blasint inc_y = 1;
  424. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  425. inc_x, beta, inc_y);
  426. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  427. }
  428. /**
  429. * C API specific test
  430. * Test zgemv by comparing it against reference
  431. * with the following options:
  432. *
  433. * Column Major
  434. * Transposition and conjugate A
  435. * Square matrix
  436. * inc x = 2, inc y = 1
  437. * alpha_r = 1.0, alpha_i = 1.0
  438. * beta_r = 1.0, beta_i = 2.0
  439. */
  440. CTEST(zgemv, c_api_colmajor_conjtrans_col_100_row_100_inc_x_1_y_1)
  441. {
  442. blasint m = 100, n = 100;
  443. blasint lda = 100;
  444. char order = 'C';
  445. char trans = 'C';
  446. double alpha[] = {1.0, 1.0};
  447. double beta[] = {1.0, 2.0};
  448. blasint inc_x = 1;
  449. blasint inc_y = 1;
  450. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  451. inc_x, beta, inc_y);
  452. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  453. }
  454. /**
  455. * C API specific test
  456. * Test zgemv by comparing it against reference
  457. * with the following options:
  458. *
  459. * Column Major
  460. * Transposition and conjugate A
  461. * Square matrix
  462. * inc x = 1, inc y = 2
  463. * alpha_r = 1.0, alpha_i = 1.0
  464. * beta_r = 1.0, beta_i = 2.0
  465. */
  466. CTEST(zgemv, c_api_colmajor_conjtrans_col_100_row_100_inc_x_1_y_2)
  467. {
  468. blasint m = 100, n = 100;
  469. blasint lda = 100;
  470. char order = 'C';
  471. char trans = 'C';
  472. double alpha[] = {1.0, 1.0};
  473. double beta[] = {1.0, 2.0};
  474. blasint inc_x = 1;
  475. blasint inc_y = 2;
  476. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  477. inc_x, beta, inc_y);
  478. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  479. }
  480. /**
  481. * C API specific test
  482. * Test zgemv by comparing it against reference
  483. * with the following options:
  484. *
  485. * Row Major
  486. * Square matrix
  487. * inc x = 1, inc y = 1
  488. * alpha_r = 2.0, alpha_i = 1.0
  489. * beta_r = 1.0, beta_i = 1.0
  490. */
  491. CTEST(zgemv, c_api_rowmajor_notrans_col_100_row_100_inc_x_1_y_1)
  492. {
  493. blasint m = 100, n = 100;
  494. blasint lda = 100;
  495. char order = 'R';
  496. char trans = 'N';
  497. double alpha[] = {2.0, 1.0};
  498. double beta[] = {1.0, 1.0};
  499. blasint inc_x = 1;
  500. blasint inc_y = 1;
  501. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  502. inc_x, beta, inc_y);
  503. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  504. }
  505. /**
  506. * C API specific test
  507. * Test zgemv by comparing it against reference
  508. * with the following options:
  509. *
  510. * Row Major
  511. * No trans
  512. * Square matrix
  513. * inc x = 2, inc y = 2
  514. * alpha_r = 1.0, alpha_i = 1.0
  515. * beta_r = 3.0, beta_i = 2.0
  516. */
  517. CTEST(zgemv, c_api_rowmajor_notrans_col_100_row_100_inc_x_2_y_2)
  518. {
  519. blasint m = 100, n = 100;
  520. blasint lda = 100;
  521. char order = 'R';
  522. char trans = 'N';
  523. double alpha[] = {1.0, 1.0};
  524. double beta[] = {3.0, 1.0};
  525. blasint inc_x = 2;
  526. blasint inc_y = 2;
  527. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  528. inc_x, beta, inc_y);
  529. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  530. }
  531. /**
  532. * C API specific test
  533. * Test zgemv by comparing it against reference
  534. * with the following options:
  535. *
  536. * Column Major
  537. * Conjugate
  538. * Square matrix
  539. * inc x = 1, inc y = 1
  540. * alpha_r = 1.0, alpha_i = 3.0
  541. * beta_r = 1.0, beta_i = 2.5
  542. */
  543. CTEST(zgemv, c_api_rowmajor_conj_col_100_row_100_inc_x_1_y_1)
  544. {
  545. blasint m = 100, n = 100;
  546. blasint lda = 100;
  547. char order = 'R';
  548. char trans = 'R';
  549. double alpha[] = {1.0, 3.0};
  550. double beta[] = {1.0, 2.5};
  551. blasint inc_x = 1;
  552. blasint inc_y = 1;
  553. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  554. inc_x, beta, inc_y);
  555. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  556. }
  557. /**
  558. * C API specific test
  559. * Test zgemv by comparing it against reference
  560. * with the following options:
  561. *
  562. * Row Major
  563. * Conjugate
  564. * Square matrix
  565. * inc x = 2, inc y = 1
  566. * alpha_r = 1.0, alpha_i = 1.0
  567. * beta_r = 1.0, beta_i = 1.5
  568. */
  569. CTEST(zgemv, c_api_rowmajor_conj_col_100_row_100_inc_x_2_y_1)
  570. {
  571. blasint m = 100, n = 100;
  572. blasint lda = 100;
  573. char order = 'R';
  574. char trans = 'R';
  575. double alpha[] = {1.0, 1.0};
  576. double beta[] = {1.0, 1.5};
  577. blasint inc_x = 2;
  578. blasint inc_y = 1;
  579. double norm = check_zgemv('C', order, trans, m, n, alpha, lda,
  580. inc_x, beta, inc_y);
  581. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS_ZGEMV);
  582. }
  583. /**
  584. * Fortran API specific test
  585. * Test error function for an invalid param inc_y.
  586. * Must be positive
  587. *
  588. * Column major
  589. */
  590. CTEST(zgemv, xerbla_invalid_inc_y)
  591. {
  592. char order = 'C';
  593. char trans = 'T';
  594. blasint m = 1, n = 1;
  595. blasint lda = 1;
  596. blasint inc_x = 1;
  597. blasint inc_y = 0;
  598. int expected_info = 11;
  599. int passed = check_badargs(order, trans, m, n, lda, inc_x, inc_y, expected_info);
  600. ASSERT_EQUAL(TRUE, passed);
  601. }
  602. /**
  603. * C API specific test
  604. * Test error function for an invalid param inc_y.
  605. * Must be positive
  606. *
  607. * Column major
  608. */
  609. CTEST(zgemv, c_api_xerbla_invalid_inc_y_col_major)
  610. {
  611. enum CBLAS_ORDER corder = CblasColMajor;
  612. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  613. blasint m = 1, n = 1;
  614. blasint lda = 1;
  615. blasint inc_x = 1;
  616. blasint inc_y = 0;
  617. int expected_info = 11;
  618. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  619. ASSERT_EQUAL(TRUE, passed);
  620. }
  621. /**
  622. * C API specific test
  623. * Test error function for an invalid param inc_y.
  624. * Must be positive
  625. *
  626. * Row major
  627. */
  628. CTEST(zgemv, c_api_xerbla_invalid_inc_y_row_major)
  629. {
  630. enum CBLAS_ORDER corder = CblasRowMajor;
  631. enum CBLAS_TRANSPOSE ctrans = CblasNoTrans;
  632. blasint m = 1, n = 1;
  633. blasint lda = 1;
  634. blasint inc_x = 1;
  635. blasint inc_y = 0;
  636. int expected_info = 11;
  637. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  638. ASSERT_EQUAL(TRUE, passed);
  639. }
  640. /**
  641. * Fortran API specific test
  642. * Test error function for an invalid param inc_x.
  643. * Must be positive
  644. *
  645. * Column major
  646. */
  647. CTEST(zgemv, xerbla_invalid_inc_x)
  648. {
  649. char order = 'C';
  650. char trans = 'T';
  651. blasint m = 1, n = 1;
  652. blasint lda = 1;
  653. blasint inc_x = 0;
  654. blasint inc_y = 1;
  655. int expected_info = 8;
  656. int passed = check_badargs(order, trans, m, n, lda, inc_x, inc_y, expected_info);
  657. ASSERT_EQUAL(TRUE, passed);
  658. }
  659. /**
  660. * C API specific test
  661. * Test error function for an invalid param inc_x.
  662. * Must be positive
  663. *
  664. * Column major
  665. */
  666. CTEST(zgemv, c_api_xerbla_invalid_inc_x_col_major)
  667. {
  668. enum CBLAS_ORDER corder = CblasColMajor;
  669. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  670. blasint m = 1, n = 1;
  671. blasint lda = 1;
  672. blasint inc_x = 0;
  673. blasint inc_y = 1;
  674. int expected_info = 8;
  675. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  676. ASSERT_EQUAL(TRUE, passed);
  677. }
  678. /**
  679. * C API specific test
  680. * Test error function for an invalid param inc_x.
  681. * Must be positive
  682. *
  683. * Row major
  684. */
  685. CTEST(zgemv, c_api_xerbla_invalid_inc_x_row_major)
  686. {
  687. enum CBLAS_ORDER corder = CblasColMajor;
  688. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  689. blasint m = 1, n = 1;
  690. blasint lda = 1;
  691. blasint inc_x = 0;
  692. blasint inc_y = 1;
  693. int expected_info = 8;
  694. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  695. ASSERT_EQUAL(TRUE, passed);
  696. }
  697. /**
  698. * Fortran API specific test
  699. * Test error function for an invalid param n.
  700. * Must be positive.
  701. *
  702. * Column major
  703. */
  704. CTEST(zgemv, xerbla_invalid_n)
  705. {
  706. char order = 'C';
  707. char trans = 'T';
  708. blasint m = 1, n = INVALID;
  709. blasint lda = 1;
  710. blasint inc_x = 1;
  711. blasint inc_y = 1;
  712. int expected_info = 3;
  713. int passed = check_badargs(order, trans, m, n, lda, inc_x, inc_y, expected_info);
  714. ASSERT_EQUAL(TRUE, passed);
  715. }
  716. /**
  717. * C API specific test
  718. * Test error function for an invalid param n.
  719. * Must be positive.
  720. *
  721. * Column major
  722. */
  723. CTEST(zgemv, c_api_xerbla_invalid_n_col_major)
  724. {
  725. enum CBLAS_ORDER corder = CblasColMajor;
  726. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  727. blasint m = 1, n = INVALID;
  728. blasint lda = 1;
  729. blasint inc_x = 1;
  730. blasint inc_y = 1;
  731. int expected_info = 3;
  732. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  733. ASSERT_EQUAL(TRUE, passed);
  734. }
  735. /**
  736. * C API specific test
  737. * Test error function for an invalid param n.
  738. * Must be positive.
  739. *
  740. * Row major
  741. */
  742. CTEST(zgemv, c_api_xerbla_invalid_n_row_major)
  743. {
  744. enum CBLAS_ORDER corder = CblasRowMajor;
  745. enum CBLAS_TRANSPOSE ctrans = CblasNoTrans;
  746. blasint m = INVALID, n = 1;
  747. blasint lda = 1;
  748. blasint inc_x = 1;
  749. blasint inc_y = 1;
  750. int expected_info = 3;
  751. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  752. ASSERT_EQUAL(TRUE, passed);
  753. }
  754. /**
  755. * Fortran API specific test
  756. * Test error function for an invalid param m.
  757. * Must be positive.
  758. *
  759. * Column major
  760. */
  761. CTEST(zgemv, xerbla_invalid_m)
  762. {
  763. char order = 'C';
  764. char trans = 'T';
  765. blasint m = INVALID, n = 1;
  766. blasint lda = 1;
  767. blasint inc_x = 1;
  768. blasint inc_y = 1;
  769. int expected_info = 2;
  770. int passed = check_badargs(order, trans, m, n, lda, inc_x, inc_y, expected_info);
  771. ASSERT_EQUAL(TRUE, passed);
  772. }
  773. /**
  774. * C API specific test
  775. * Test error function for an invalid param m.
  776. * Must be positive.
  777. *
  778. * Column major
  779. */
  780. CTEST(zgemv, c_api_xerbla_invalid_m_col_major)
  781. {
  782. enum CBLAS_ORDER corder = CblasColMajor;
  783. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  784. blasint m = INVALID, n = 1;
  785. blasint lda = 1;
  786. blasint inc_x = 1;
  787. blasint inc_y = 1;
  788. int expected_info = 2;
  789. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  790. ASSERT_EQUAL(TRUE, passed);
  791. }
  792. /**
  793. * C API specific test
  794. * Test error function for an invalid param m.
  795. * Must be positive.
  796. *
  797. * Row major
  798. */
  799. CTEST(zgemv, c_api_xerbla_invalid_m_row_major)
  800. {
  801. enum CBLAS_ORDER corder = CblasRowMajor;
  802. enum CBLAS_TRANSPOSE ctrans = CblasNoTrans;
  803. blasint m = 1, n = INVALID;
  804. blasint lda = 1;
  805. blasint inc_x = 1;
  806. blasint inc_y = 1;
  807. int expected_info = 2;
  808. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  809. ASSERT_EQUAL(TRUE, passed);
  810. }
  811. /**
  812. * Fortran API specific test
  813. * Test error function for an invalid param lda.
  814. * lda must be at least n.
  815. *
  816. * Column major
  817. */
  818. CTEST(zgemv, xerbla_invalid_lda)
  819. {
  820. char order = 'C';
  821. char trans = 'T';
  822. blasint m = 1, n = 1;
  823. blasint lda = INVALID;
  824. blasint inc_x = 1;
  825. blasint inc_y = 1;
  826. int expected_info = 6;
  827. int passed = check_badargs(order, trans, m, n, lda, inc_x, inc_y, expected_info);
  828. ASSERT_EQUAL(TRUE, passed);
  829. }
  830. /**
  831. * C API specific test
  832. * Test error function for an invalid param lda.
  833. * If matrices are stored using col major layout,
  834. * lda must be at least m.
  835. *
  836. * Column major
  837. */
  838. CTEST(zgemv, c_api_xerbla_invalid_lda_col_major)
  839. {
  840. enum CBLAS_ORDER corder = CblasColMajor;
  841. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  842. blasint m = 1, n = 1;
  843. blasint lda = INVALID;
  844. blasint inc_x = 1;
  845. blasint inc_y = 1;
  846. int expected_info = 6;
  847. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  848. ASSERT_EQUAL(TRUE, passed);
  849. }
  850. /**
  851. * C API specific test
  852. * Test error function for an invalid param lda.
  853. * If matrices are stored using col major layout,
  854. * lda must be at least n.
  855. *
  856. * Column major
  857. */
  858. CTEST(zgemv, c_api_xerbla_invalid_lda_row_major)
  859. {
  860. enum CBLAS_ORDER corder = CblasRowMajor;
  861. enum CBLAS_TRANSPOSE ctrans = CblasNoTrans;
  862. blasint m = 1, n = 1;
  863. blasint lda = INVALID;
  864. blasint inc_x = 1;
  865. blasint inc_y = 1;
  866. int expected_info = 6;
  867. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  868. ASSERT_EQUAL(TRUE, passed);
  869. }
  870. /**
  871. * Fortran API specific test
  872. * Test error function for an invalid param trans.
  873. *
  874. * Column major
  875. */
  876. CTEST(zgemv, xerbla_invalid_trans)
  877. {
  878. char order = 'C';
  879. char trans = 'Z';
  880. blasint m = 1, n = 1;
  881. blasint lda = 1;
  882. blasint inc_x = 1;
  883. blasint inc_y = 1;
  884. int expected_info = 1;
  885. int passed = check_badargs(order, trans, m, n, lda, inc_x, inc_y, expected_info);
  886. ASSERT_EQUAL(TRUE, passed);
  887. }
  888. /**
  889. * C API specific test
  890. * Test error function for an invalid param trans.
  891. *
  892. * Column major
  893. */
  894. CTEST(zgemv, c_api_xerbla_invalid_trans_col_major)
  895. {
  896. enum CBLAS_ORDER corder = CblasColMajor;
  897. enum CBLAS_TRANSPOSE ctrans = INVALID;
  898. blasint m = 1, n = 1;
  899. blasint lda = 1;
  900. blasint inc_x = 1;
  901. blasint inc_y = 1;
  902. int expected_info = 1;
  903. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  904. ASSERT_EQUAL(TRUE, passed);
  905. }
  906. /**
  907. * C API specific test
  908. * Test error function for an invalid param trans.
  909. *
  910. * Row major
  911. */
  912. CTEST(zgemv, c_api_xerbla_invalid_trans_row_major)
  913. {
  914. enum CBLAS_ORDER corder = CblasRowMajor;
  915. enum CBLAS_TRANSPOSE ctrans = INVALID;
  916. blasint m = 1, n = 1;
  917. blasint lda = 1;
  918. blasint inc_x = 1;
  919. blasint inc_y = 1;
  920. int expected_info = 1;
  921. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  922. ASSERT_EQUAL(TRUE, passed);
  923. }
  924. /**
  925. * C API specific test
  926. * Test error function for an invalid param order.
  927. */
  928. CTEST(zgemv, c_api_xerbla_invalid_order_col_major)
  929. {
  930. enum CBLAS_ORDER corder = INVALID;
  931. enum CBLAS_TRANSPOSE ctrans = CblasTrans;
  932. blasint m = 1, n = 1;
  933. blasint lda = 1;
  934. blasint inc_x = 1;
  935. blasint inc_y = 1;
  936. int expected_info = 0;
  937. int passed = c_api_check_badargs(corder, ctrans, m, n, lda, inc_x, inc_y, expected_info);
  938. ASSERT_EQUAL(TRUE, passed);
  939. }
  940. #endif
  941. #endif