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

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