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