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

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