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_zgeadd.c 22 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880
  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. struct DATA_ZGEADD {
  33. double a_test[M * N * 2];
  34. double c_test[M * N * 2];
  35. double c_verify[M * N * 2];
  36. };
  37. #ifdef BUILD_COMPLEX16
  38. static struct DATA_ZGEADD data_zgeadd;
  39. /**
  40. * zgeadd reference implementation
  41. *
  42. * param m - number of rows of A and C
  43. * param n - number of columns of A and C
  44. * param alpha - scaling factor for matrix A
  45. * param aptr - refer to matrix A
  46. * param lda - leading dimension of A
  47. * param beta - scaling factor for matrix C
  48. * param cptr - refer to matrix C
  49. * param ldc - leading dimension of C
  50. */
  51. static void zgeadd_trusted(blasint m, blasint n, double *alpha, double *aptr,
  52. blasint lda, double *beta, double *cptr, blasint ldc)
  53. {
  54. blasint i;
  55. lda *= 2;
  56. ldc *= 2;
  57. for (i = 0; i < n; i++)
  58. {
  59. cblas_zaxpby(m, alpha, aptr, 1, beta, cptr, 1);
  60. aptr += lda;
  61. cptr += ldc;
  62. }
  63. }
  64. /**
  65. * Test zgeadd by comparing it against reference
  66. * Compare with the following options:
  67. *
  68. * param api - specifies Fortran or C API
  69. * param order - specifies whether A and C stored in
  70. * row-major order or column-major order
  71. * param m - number of rows of A and C
  72. * param n - number of columns of A and C
  73. * param alpha - scaling factor for matrix A
  74. * param lda - leading dimension of A
  75. * param beta - scaling factor for matrix C
  76. * param ldc - leading dimension of C
  77. * return norm of differences
  78. */
  79. static double check_zgeadd(char api, OPENBLAS_CONST enum CBLAS_ORDER order,
  80. blasint m, blasint n, double *alpha, blasint lda,
  81. double *beta, blasint ldc)
  82. {
  83. blasint i;
  84. blasint cols = m, rows = n;
  85. if (order == CblasRowMajor)
  86. {
  87. rows = m;
  88. cols = n;
  89. }
  90. // Fill matrix A, C
  91. drand_generate(data_zgeadd.a_test, lda * rows * 2);
  92. drand_generate(data_zgeadd.c_test, ldc * rows * 2);
  93. // Copy matrix C for zgeadd
  94. for (i = 0; i < ldc * rows * 2; i++)
  95. data_zgeadd.c_verify[i] = data_zgeadd.c_test[i];
  96. zgeadd_trusted(cols, rows, alpha, data_zgeadd.a_test, lda,
  97. beta, data_zgeadd.c_verify, ldc);
  98. if (api == 'F')
  99. BLASFUNC(zgeadd)(&m, &n, alpha, data_zgeadd.a_test, &lda,
  100. beta, data_zgeadd.c_test, &ldc);
  101. else
  102. cblas_zgeadd(order, m, n, alpha, data_zgeadd.a_test, lda,
  103. beta, data_zgeadd.c_test, ldc);
  104. // Find the differences between output matrix caculated by zgeadd and sgemm
  105. return dmatrix_difference(data_zgeadd.c_test, data_zgeadd.c_verify, cols, rows, ldc * 2);
  106. }
  107. /**
  108. * Check if error function was called with expected function name
  109. * and param info
  110. *
  111. * param api - specifies Fortran or C API
  112. * param order - specifies whether A and C stored in
  113. * row-major order or column-major order
  114. * param m - number of rows of A and C
  115. * param n - number of columns of A and C
  116. * param lda - leading dimension of A
  117. * param ldc - leading dimension of C
  118. * param expected_info - expected invalid parameter number in zgeadd
  119. * return TRUE if everything is ok, otherwise FALSE
  120. */
  121. static int check_badargs(char api, OPENBLAS_CONST enum CBLAS_ORDER order,
  122. blasint m, blasint n, blasint lda,
  123. blasint ldc, int expected_info)
  124. {
  125. double alpha[] = {1.0, 1.0};
  126. double beta[] = {1.0, 1.0};
  127. set_xerbla("ZGEADD ", expected_info);
  128. if (api == 'F')
  129. BLASFUNC(zgeadd)(&m, &n, alpha, data_zgeadd.a_test, &lda,
  130. beta, data_zgeadd.c_test, &ldc);
  131. else
  132. cblas_zgeadd(order, m, n, alpha, data_zgeadd.a_test, lda,
  133. beta, data_zgeadd.c_test, ldc);
  134. return check_error();
  135. }
  136. /**
  137. * Fortran API specific test
  138. * Test zgeadd by comparing it against reference
  139. * with the following options:
  140. *
  141. * For A number of rows is 100, number of colums is 100
  142. * For C number of rows is 100, number of colums is 100
  143. */
  144. CTEST(zgeadd, matrix_n_100_m_100)
  145. {
  146. CBLAS_ORDER order = CblasColMajor;
  147. blasint n = N;
  148. blasint m = M;
  149. blasint lda = m;
  150. blasint ldc = m;
  151. double alpha[] = {3.0, 2.0};
  152. double beta[] = {1.0, 3.0};
  153. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  154. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  155. }
  156. /**
  157. * Fortran API specific test
  158. * Test zgeadd by comparing it against reference
  159. * with the following options:
  160. *
  161. * For A number of rows is 100, number of colums is 100
  162. * For C number of rows is 100, number of colums is 100
  163. * Scalar alpha is zero (operation is C:=beta*C)
  164. */
  165. CTEST(zgeadd, matrix_n_100_m_100_alpha_zero)
  166. {
  167. CBLAS_ORDER order = CblasColMajor;
  168. blasint n = N;
  169. blasint m = M;
  170. blasint lda = m;
  171. blasint ldc = m;
  172. double alpha[] = {0.0, 0.0};
  173. double beta[] = {1.0, 1.0};
  174. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  175. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  176. }
  177. /**
  178. * Fortran API specific test
  179. * Test zgeadd by comparing it against reference
  180. * with the following options:
  181. *
  182. * For A number of rows is 100, number of colums is 100
  183. * For C number of rows is 100, number of colums is 100
  184. * Scalar beta is zero (operation is C:=alpha*A)
  185. */
  186. CTEST(zgeadd, matrix_n_100_m_100_beta_zero)
  187. {
  188. CBLAS_ORDER order = CblasColMajor;
  189. blasint n = N;
  190. blasint m = M;
  191. blasint lda = m;
  192. blasint ldc = m;
  193. double alpha[] = {3.0, 1.5};
  194. double beta[] = {0.0, 0.0};
  195. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  196. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  197. }
  198. /**
  199. * Fortran API specific test
  200. * Test zgeadd by comparing it against reference
  201. * with the following options:
  202. *
  203. * For A number of rows is 100, number of colums is 100
  204. * For C number of rows is 100, number of colums is 100
  205. * Scalars alpha, beta is zero (operation is C:= 0)
  206. */
  207. CTEST(zgeadd, matrix_n_100_m_100_alpha_beta_zero)
  208. {
  209. CBLAS_ORDER order = CblasColMajor;
  210. blasint n = N;
  211. blasint m = M;
  212. blasint lda = m;
  213. blasint ldc = m;
  214. double alpha[] = {0.0, 0.0};
  215. double beta[] = {0.0, 0.0};
  216. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  217. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  218. }
  219. /**
  220. * Fortran API specific test
  221. * Test zgeadd by comparing it against reference
  222. * with the following options:
  223. *
  224. * For A number of rows is 50, number of colums is 100
  225. * For C number of rows is 50, number of colums is 100
  226. */
  227. CTEST(zgeadd, matrix_n_100_m_50)
  228. {
  229. CBLAS_ORDER order = CblasColMajor;
  230. blasint n = N;
  231. blasint m = M / 2;
  232. blasint lda = m;
  233. blasint ldc = m;
  234. double alpha[] = {1.0, 1.0};
  235. double beta[] = {1.0, 1.0};
  236. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  237. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  238. }
  239. /**
  240. * Fortran API specific test
  241. * Test error function for an invalid param n -
  242. * number of columns of A and C
  243. * Must be at least zero.
  244. */
  245. CTEST(zgeadd, xerbla_n_invalid)
  246. {
  247. CBLAS_ORDER order = CblasColMajor;
  248. blasint n = INVALID;
  249. blasint m = 1;
  250. blasint lda = m;
  251. blasint ldc = m;
  252. int expected_info = 2;
  253. int passed = check_badargs('F', order, m, n, lda, ldc, expected_info);
  254. ASSERT_EQUAL(TRUE, passed);
  255. }
  256. /**
  257. * Fortran API specific test
  258. * Test error function for an invalid param m -
  259. * number of rows of A and C
  260. * Must be at least zero.
  261. */
  262. CTEST(zgeadd, xerbla_m_invalid)
  263. {
  264. CBLAS_ORDER order = CblasColMajor;
  265. blasint n = 1;
  266. blasint m = INVALID;
  267. blasint lda = 1;
  268. blasint ldc = 1;
  269. int expected_info = 1;
  270. int passed = check_badargs('F', order, m, n, lda, ldc, expected_info);
  271. ASSERT_EQUAL(TRUE, passed);
  272. }
  273. /**
  274. * Fortran API specific test
  275. * Test error function for an invalid param lda -
  276. * specifies the leading dimension of A. Must be at least MAX(1, m).
  277. */
  278. CTEST(zgeadd, xerbla_lda_invalid)
  279. {
  280. CBLAS_ORDER order = CblasColMajor;
  281. blasint n = 1;
  282. blasint m = 1;
  283. blasint lda = INVALID;
  284. blasint ldc = 1;
  285. int expected_info = 5;
  286. int passed = check_badargs('F', order, m, n, lda, ldc, expected_info);
  287. ASSERT_EQUAL(TRUE, passed);
  288. }
  289. /**
  290. * Fortran API specific test
  291. * Test error function for an invalid param ldc -
  292. * specifies the leading dimension of C. Must be at least MAX(1, m).
  293. */
  294. CTEST(zgeadd, xerbla_ldc_invalid)
  295. {
  296. CBLAS_ORDER order = CblasColMajor;
  297. blasint n = 1;
  298. blasint m = 1;
  299. blasint lda = 1;
  300. blasint ldc = INVALID;
  301. int expected_info = 8;
  302. int passed = check_badargs('F', order, m, n, lda, ldc, expected_info);
  303. ASSERT_EQUAL(TRUE, passed);
  304. }
  305. /**
  306. * Fortran API specific test
  307. * Check if n - number of columns of A, C equal zero.
  308. */
  309. CTEST(zgeadd, n_zero)
  310. {
  311. CBLAS_ORDER order = CblasColMajor;
  312. blasint n = 0;
  313. blasint m = 1;
  314. blasint lda = 1;
  315. blasint ldc = 1;
  316. double alpha[] = {1.0, 1.0};
  317. double beta[] = {1.0, 1.0};
  318. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  319. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  320. }
  321. /**
  322. * Fortran API specific test
  323. * Check if m - number of rows of A and C equal zero.
  324. */
  325. CTEST(zgeadd, m_zero)
  326. {
  327. CBLAS_ORDER order = CblasColMajor;
  328. blasint n = 1;
  329. blasint m = 0;
  330. blasint lda = 1;
  331. blasint ldc = 1;
  332. double alpha[] = {1.0, 1.0};
  333. double beta[] = {1.0, 1.0};
  334. double norm = check_zgeadd('F', order, m, n, alpha, lda, beta, ldc);
  335. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  336. }
  337. /**
  338. * C API specific test
  339. * Test zgeadd by comparing it against reference
  340. * with the following options:
  341. *
  342. * c api option order is column-major order
  343. * For A number of rows is 100, number of colums is 100
  344. * For C number of rows is 100, number of colums is 100
  345. */
  346. CTEST(zgeadd, c_api_matrix_n_100_m_100)
  347. {
  348. CBLAS_ORDER order = CblasColMajor;
  349. blasint n = N;
  350. blasint m = M;
  351. blasint lda = m;
  352. blasint ldc = m;
  353. double alpha[] = {2.0, 1.0};
  354. double beta[] = {1.0, 3.0};
  355. double norm = check_zgeadd('C', order, m, n, alpha,
  356. lda, beta, ldc);
  357. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  358. }
  359. /**
  360. * C API specific test
  361. * Test zgeadd by comparing it against reference
  362. * with the following options:
  363. *
  364. * c api option order is row-major order
  365. * For A number of rows is 100, number of colums is 100
  366. * For C number of rows is 100, number of colums is 100
  367. */
  368. CTEST(zgeadd, c_api_matrix_n_100_m_100_row_major)
  369. {
  370. CBLAS_ORDER order = CblasRowMajor;
  371. blasint n = N;
  372. blasint m = M;
  373. blasint lda = m;
  374. blasint ldc = m;
  375. double alpha[] = {4.0, 1.5};
  376. double beta[] = {2.0, 1.0};
  377. double norm = check_zgeadd('C', order, m, n, alpha,
  378. lda, beta, ldc);
  379. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  380. }
  381. /**
  382. * C API specific test
  383. * Test zgeadd by comparing it against reference
  384. * with the following options:
  385. *
  386. * c api option order is row-major order
  387. * For A number of rows is 50, number of colums is 100
  388. * For C number of rows is 50, number of colums is 100
  389. */
  390. CTEST(zgeadd, c_api_matrix_n_50_m_100_row_major)
  391. {
  392. CBLAS_ORDER order = CblasRowMajor;
  393. blasint n = N / 2;
  394. blasint m = M;
  395. blasint lda = n;
  396. blasint ldc = n;
  397. double alpha[] = {3.0, 2.5};
  398. double beta[] = {1.0, 2.0};
  399. double norm = check_zgeadd('C', order, m, n, alpha,
  400. lda, beta, ldc);
  401. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  402. }
  403. /**
  404. * C API specific test
  405. * Test zgeadd by comparing it against reference
  406. * with the following options:
  407. *
  408. * c api option order is column-major order
  409. * For A number of rows is 100, number of colums is 100
  410. * For C number of rows is 100, number of colums is 100
  411. * Scalar alpha is zero (operation is C:=beta*C)
  412. */
  413. CTEST(zgeadd, c_api_matrix_n_100_m_100_alpha_zero)
  414. {
  415. CBLAS_ORDER order = CblasColMajor;
  416. blasint n = N;
  417. blasint m = M;
  418. blasint lda = m;
  419. blasint ldc = m;
  420. double alpha[] = {0.0, 0.0};
  421. double beta[] = {1.0, 1.0};
  422. double norm = check_zgeadd('C', order, m, n, alpha,
  423. lda, beta, ldc);
  424. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  425. }
  426. /**
  427. * C API specific test
  428. * Test zgeadd by comparing it against reference
  429. * with the following options:
  430. *
  431. * c api option order is column-major order
  432. * For A number of rows is 100, number of colums is 100
  433. * For C number of rows is 100, number of colums is 100
  434. * Scalar beta is zero (operation is C:=alpha*A)
  435. */
  436. CTEST(zgeadd, c_api_matrix_n_100_m_100_beta_zero)
  437. {
  438. CBLAS_ORDER order = CblasColMajor;
  439. blasint n = N;
  440. blasint m = M;
  441. blasint lda = m;
  442. blasint ldc = m;
  443. double alpha[] = {3.0, 1.5};
  444. double beta[] = {0.0, 0.0};
  445. double norm = check_zgeadd('C', order, m, n, alpha,
  446. lda, beta, ldc);
  447. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  448. }
  449. /**
  450. * C API specific test
  451. * Test zgeadd by comparing it against reference
  452. * with the following options:
  453. *
  454. * c api option order is column-major order
  455. * For A number of rows is 100, number of colums is 100
  456. * For C number of rows is 100, number of colums is 100
  457. * Scalars alpha, beta is zero (operation is C:= 0)
  458. */
  459. CTEST(zgeadd, c_api_matrix_n_100_m_100_alpha_beta_zero)
  460. {
  461. CBLAS_ORDER order = CblasColMajor;
  462. blasint n = N;
  463. blasint m = M;
  464. blasint lda = m;
  465. blasint ldc = m;
  466. double alpha[] = {0.0, 0.0};
  467. double beta[] = {0.0, 0.0};
  468. double norm = check_zgeadd('C', order, m, n, alpha,
  469. lda, beta, ldc);
  470. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  471. }
  472. /**
  473. * C API specific test
  474. * Test zgeadd by comparing it against reference
  475. * with the following options:
  476. *
  477. * For A number of rows is 50, number of colums is 100
  478. * For C number of rows is 50, number of colums is 100
  479. */
  480. CTEST(zgeadd, c_api_matrix_n_100_m_50)
  481. {
  482. CBLAS_ORDER order = CblasColMajor;
  483. blasint n = N;
  484. blasint m = M / 2;
  485. blasint lda = m;
  486. blasint ldc = m;
  487. double alpha[] = {2.0, 3.0};
  488. double beta[] = {2.0, 4.0};
  489. double norm = check_zgeadd('C', order, m, n, alpha,
  490. lda, beta, ldc);
  491. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  492. }
  493. /**
  494. * C API specific test
  495. * Test error function for an invalid param order -
  496. * specifies whether A and C stored in
  497. * row-major order or column-major order
  498. */
  499. CTEST(zgeadd, c_api_xerbla_invalid_order)
  500. {
  501. CBLAS_ORDER order = INVALID;
  502. blasint n = 1;
  503. blasint m = 1;
  504. blasint lda = 1;
  505. blasint ldc = 1;
  506. int expected_info = 0;
  507. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  508. ASSERT_EQUAL(TRUE, passed);
  509. }
  510. /**
  511. * C API specific test
  512. * Test error function for an invalid param n -
  513. * number of columns of A and C.
  514. * Must be at least zero.
  515. *
  516. * c api option order is column-major order
  517. */
  518. CTEST(zgeadd, c_api_xerbla_n_invalid)
  519. {
  520. CBLAS_ORDER order = CblasColMajor;
  521. blasint n = INVALID;
  522. blasint m = 1;
  523. blasint lda = 1;
  524. blasint ldc = 1;
  525. int expected_info = 2;
  526. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  527. ASSERT_EQUAL(TRUE, passed);
  528. }
  529. /**
  530. * C API specific test
  531. * Test error function for an invalid param n -
  532. * number of columns of A and C.
  533. * Must be at least zero.
  534. *
  535. * c api option order is row-major order
  536. */
  537. CTEST(zgeadd, c_api_xerbla_n_invalid_row_major)
  538. {
  539. CBLAS_ORDER order = CblasRowMajor;
  540. blasint n = INVALID;
  541. blasint m = 1;
  542. blasint lda = 1;
  543. blasint ldc = 1;
  544. int expected_info = 2;
  545. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  546. ASSERT_EQUAL(TRUE, passed);
  547. }
  548. /**
  549. * C API specific test
  550. * Test error function for an invalid param m -
  551. * number of rows of A and C
  552. * Must be at least zero.
  553. *
  554. * c api option order is column-major order
  555. */
  556. CTEST(zgeadd, c_api_xerbla_m_invalid)
  557. {
  558. CBLAS_ORDER order = CblasColMajor;
  559. blasint n = 1;
  560. blasint m = INVALID;
  561. blasint lda = 1;
  562. blasint ldc = 1;
  563. int expected_info = 1;
  564. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  565. ASSERT_EQUAL(TRUE, passed);
  566. }
  567. /**
  568. * C API specific test
  569. * Test error function for an invalid param m -
  570. * number of rows of A and C
  571. * Must be at least zero.
  572. *
  573. * c api option order is row-major order
  574. */
  575. CTEST(zgeadd, c_api_xerbla_m_invalid_row_major)
  576. {
  577. CBLAS_ORDER order = CblasRowMajor;
  578. blasint n = 1;
  579. blasint m = INVALID;
  580. blasint lda = 1;
  581. blasint ldc = 1;
  582. int expected_info = 1;
  583. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  584. ASSERT_EQUAL(TRUE, passed);
  585. }
  586. /**
  587. * C API specific test
  588. * Test error function for an invalid param lda -
  589. * specifies the leading dimension of A. Must be at least MAX(1, m).
  590. *
  591. * c api option order is column-major order
  592. */
  593. CTEST(zgeadd, c_api_xerbla_lda_invalid)
  594. {
  595. CBLAS_ORDER order = CblasColMajor;
  596. blasint n = 1;
  597. blasint m = 1;
  598. blasint lda = INVALID;
  599. blasint ldc = 1;
  600. int expected_info = 5;
  601. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  602. ASSERT_EQUAL(TRUE, passed);
  603. }
  604. /**
  605. * C API specific test
  606. * Test error function for an invalid param lda -
  607. * specifies the leading dimension of A. Must be at least MAX(1, m).
  608. *
  609. * c api option order is row-major order
  610. */
  611. CTEST(zgeadd, c_api_xerbla_lda_invalid_row_major)
  612. {
  613. CBLAS_ORDER order = CblasRowMajor;
  614. blasint n = 1;
  615. blasint m = 1;
  616. blasint lda = INVALID;
  617. blasint ldc = 1;
  618. int expected_info = 5;
  619. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  620. ASSERT_EQUAL(TRUE, passed);
  621. }
  622. /**
  623. * C API specific test
  624. * Test error function for an invalid param ldc -
  625. * specifies the leading dimension of C. Must be at least MAX(1, m).
  626. *
  627. * c api option order is column-major order
  628. */
  629. CTEST(zgeadd, c_api_xerbla_ldc_invalid)
  630. {
  631. CBLAS_ORDER order = CblasColMajor;
  632. blasint n = 1;
  633. blasint m = 1;
  634. blasint lda = 1;
  635. blasint ldc = INVALID;
  636. int expected_info = 8;
  637. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  638. ASSERT_EQUAL(TRUE, passed);
  639. }
  640. /**
  641. * C API specific test
  642. * Test error function for an invalid param ldc -
  643. * specifies the leading dimension of C. Must be at least MAX(1, m).
  644. *
  645. * c api option order is row-major order
  646. */
  647. CTEST(zgeadd, c_api_xerbla_ldc_invalid_row_major)
  648. {
  649. CBLAS_ORDER order = CblasRowMajor;
  650. blasint n = 1;
  651. blasint m = 1;
  652. blasint lda = 1;
  653. blasint ldc = INVALID;
  654. int expected_info = 8;
  655. int passed = check_badargs('C', order, m, n, lda, ldc, expected_info);
  656. ASSERT_EQUAL(TRUE, passed);
  657. }
  658. /**
  659. * C API specific test
  660. * Check if n - number of columns of A, C equal zero.
  661. *
  662. * c api option order is column-major order
  663. */
  664. CTEST(zgeadd, c_api_n_zero)
  665. {
  666. CBLAS_ORDER order = CblasColMajor;
  667. blasint n = 0;
  668. blasint m = 1;
  669. blasint lda = 1;
  670. blasint ldc = 1;
  671. double alpha[] = {1.0, 1.0};
  672. double beta[] = {1.0, 1.0};
  673. double norm = check_zgeadd('C', order, m, n, alpha,
  674. lda, beta, ldc);
  675. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  676. }
  677. /**
  678. * C API specific test
  679. * Check if m - number of rows of A and C equal zero.
  680. *
  681. * c api option order is column-major order
  682. */
  683. CTEST(zgeadd, c_api_m_zero)
  684. {
  685. CBLAS_ORDER order = CblasColMajor;
  686. blasint n = 1;
  687. blasint m = 0;
  688. blasint lda = 1;
  689. blasint ldc = 1;
  690. double alpha[] = {1.0, 1.0};
  691. double beta[] = {1.0, 1.0};
  692. double norm = check_zgeadd('C', order, m, n, alpha,
  693. lda, beta, ldc);
  694. ASSERT_DBL_NEAR_TOL(0.0, norm, DOUBLE_EPS);
  695. }
  696. #endif