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

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