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_dgeadd.c 21 kB

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