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_drotmg.c 9.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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 <cblas.h>
  30. #ifdef BUILD_DOUBLE
  31. /**
  32. * Fortran API specific test
  33. * Test drotmg by comparing it against pre-calculated values
  34. */
  35. CTEST(drotmg, y1_zero)
  36. {
  37. double te_d1, tr_d1;
  38. double te_d2, tr_d2;
  39. double te_x1, tr_x1;
  40. double te_y1, tr_y1;
  41. double te_param[5];
  42. double tr_param[5];
  43. int i = 0;
  44. te_d1 = tr_d1 = 2.0;
  45. te_d2 = tr_d2 = 2.0;
  46. te_x1 = tr_x1 = 8.0;
  47. te_y1 = tr_y1 = 0.0;
  48. for(i=0; i<5; i++){
  49. te_param[i] = tr_param[i] = 0.0;
  50. }
  51. //reference values as calculated by netlib blas
  52. tr_d1 = 2.0;
  53. tr_d2 = 2.0;
  54. tr_x1 = 8.0;
  55. tr_y1 = 0.0;
  56. tr_param[0] = -2.0;
  57. tr_param[1] = 0.0;
  58. tr_param[2] = 0.0;
  59. tr_param[3] = 0.0;
  60. tr_param[4] = 0.0;
  61. //OpenBLAS
  62. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  63. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  64. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  65. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  66. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  67. for(i=0; i<5; i++){
  68. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  69. }
  70. }
  71. /**
  72. * Fortran API specific test
  73. * Test drotmg by comparing it against pre-calculated values
  74. */
  75. CTEST(drotmg, d1_negative)
  76. {
  77. double te_d1, tr_d1;
  78. double te_d2, tr_d2;
  79. double te_x1, tr_x1;
  80. double te_y1, tr_y1;
  81. double te_param[5];
  82. double tr_param[5];
  83. int i = 0;
  84. te_d1 = tr_d1 = -1.0;
  85. te_d2 = tr_d2 = 2.0;
  86. te_x1 = tr_x1 = 8.0;
  87. te_y1 = tr_y1 = 8.0;
  88. for(i=0; i<5; i++){
  89. te_param[i] = tr_param[i] = 0.0;
  90. }
  91. //reference values as calculated by netlib blas
  92. tr_d1 = 0.0;
  93. tr_d2 = 0.0;
  94. tr_x1 = 0.0;
  95. tr_y1 = 8.0;
  96. tr_param[0] = -1.0;
  97. tr_param[1] = 0.0;
  98. tr_param[2] = 0.0;
  99. tr_param[3] = 0.0;
  100. tr_param[4] = 0.0;
  101. //OpenBLAS
  102. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  103. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  104. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  105. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  106. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  107. for(i=0; i<5; i++){
  108. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  109. }
  110. }
  111. /**
  112. * Fortran API specific test
  113. * Test drotmg by comparing it against pre-calculated values
  114. */
  115. CTEST(drotmg, d1_positive_d2_positive_x1_zero)
  116. {
  117. double te_d1, tr_d1;
  118. double te_d2, tr_d2;
  119. double te_x1, tr_x1;
  120. double te_y1, tr_y1;
  121. double te_param[5];
  122. double tr_param[5];
  123. int i = 0;
  124. te_d1 = tr_d1 = 2.0;
  125. te_d2 = tr_d2 = 2.0;
  126. te_x1 = tr_x1 = 0.0;
  127. te_y1 = tr_y1 = 8.0;
  128. for(i=0; i<5; i++){
  129. te_param[i] = tr_param[i] = 0.0;
  130. }
  131. //reference values as calculated by netlib blas
  132. tr_d1 = 2.0;
  133. tr_d2 = 2.0;
  134. tr_x1 = 8.0;
  135. tr_y1 = 8.0;
  136. tr_param[0] = 1.0;
  137. tr_param[1] = 0.0;
  138. tr_param[2] = 0.0;
  139. tr_param[3] = 0.0;
  140. tr_param[4] = 0.0;
  141. //OpenBLAS
  142. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  143. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  144. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  145. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  146. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  147. for(i=0; i<5; i++){
  148. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  149. }
  150. }
  151. /**
  152. * Fortran API specific test
  153. * Test drotmg by comparing it against pre-calculated values
  154. */
  155. CTEST(drotmg, scaled_y_greater_than_scaled_x)
  156. {
  157. double te_d1, tr_d1;
  158. double te_d2, tr_d2;
  159. double te_x1, tr_x1;
  160. double te_y1, tr_y1;
  161. double te_param[5];
  162. double tr_param[5];
  163. int i = 0;
  164. te_d1 = tr_d1 = 1.0;
  165. te_d2 = tr_d2 = -2.0;
  166. te_x1 = tr_x1 = 8.0;
  167. te_y1 = tr_y1 = 8.0;
  168. for(i=0; i<5; i++){
  169. te_param[i] = tr_param[i] = 0.0;
  170. }
  171. //reference values as calculated by netlib blas
  172. tr_d1 = 0.0;
  173. tr_d2 = 0.0;
  174. tr_x1 = 0.0;
  175. tr_y1 = 8.0;
  176. tr_param[0] = -1.0;
  177. tr_param[1] = 0.0;
  178. tr_param[2] = 0.0;
  179. tr_param[3] = 0.0;
  180. tr_param[4] = 0.0;
  181. //OpenBLAS
  182. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  183. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  184. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  185. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  186. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  187. for(i=0; i<5; i++){
  188. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  189. }
  190. }
  191. #ifndef NO_CBLAS
  192. /**
  193. * C API specific test
  194. * Test drotmg by comparing it against pre-calculated values
  195. */
  196. CTEST(drotmg, c_api_y1_zero)
  197. {
  198. double te_d1, tr_d1;
  199. double te_d2, tr_d2;
  200. double te_x1, tr_x1;
  201. double te_y1, tr_y1;
  202. double te_param[5];
  203. double tr_param[5];
  204. int i = 0;
  205. te_d1 = tr_d1 = 2.0;
  206. te_d2 = tr_d2 = 2.0;
  207. te_x1 = tr_x1 = 8.0;
  208. te_y1 = tr_y1 = 0.0;
  209. for(i=0; i<5; i++){
  210. te_param[i] = tr_param[i] = 0.0;
  211. }
  212. //reference values as calculated by netlib blas
  213. tr_d1 = 2.0;
  214. tr_d2 = 2.0;
  215. tr_x1 = 8.0;
  216. tr_y1 = 0.0;
  217. tr_param[0] = -2.0;
  218. tr_param[1] = 0.0;
  219. tr_param[2] = 0.0;
  220. tr_param[3] = 0.0;
  221. tr_param[4] = 0.0;
  222. //OpenBLAS
  223. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  224. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  225. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  226. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  227. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  228. for(i=0; i<5; i++){
  229. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  230. }
  231. }
  232. /**
  233. * C API specific test
  234. * Test drotmg by comparing it against pre-calculated values
  235. */
  236. CTEST(drotmg, c_api_d1_negative)
  237. {
  238. double te_d1, tr_d1;
  239. double te_d2, tr_d2;
  240. double te_x1, tr_x1;
  241. double te_y1, tr_y1;
  242. double te_param[5];
  243. double tr_param[5];
  244. int i = 0;
  245. te_d1 = tr_d1 = -1.0;
  246. te_d2 = tr_d2 = 2.0;
  247. te_x1 = tr_x1 = 8.0;
  248. te_y1 = tr_y1 = 8.0;
  249. for(i=0; i<5; i++){
  250. te_param[i] = tr_param[i] = 0.0;
  251. }
  252. //reference values as calculated by netlib blas
  253. tr_d1 = 0.0;
  254. tr_d2 = 0.0;
  255. tr_x1 = 0.0;
  256. tr_y1 = 8.0;
  257. tr_param[0] = -1.0;
  258. tr_param[1] = 0.0;
  259. tr_param[2] = 0.0;
  260. tr_param[3] = 0.0;
  261. tr_param[4] = 0.0;
  262. //OpenBLAS
  263. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  264. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  265. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  266. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  267. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  268. for(i=0; i<5; i++){
  269. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  270. }
  271. }
  272. /**
  273. * C API specific test
  274. * Test drotmg by comparing it against pre-calculated values
  275. */
  276. CTEST(drotmg, c_api_d1_positive_d2_positive_x1_zero)
  277. {
  278. double te_d1, tr_d1;
  279. double te_d2, tr_d2;
  280. double te_x1, tr_x1;
  281. double te_y1, tr_y1;
  282. double te_param[5];
  283. double tr_param[5];
  284. int i = 0;
  285. te_d1 = tr_d1 = 2.0;
  286. te_d2 = tr_d2 = 2.0;
  287. te_x1 = tr_x1 = 0.0;
  288. te_y1 = tr_y1 = 8.0;
  289. for(i=0; i<5; i++){
  290. te_param[i] = tr_param[i] = 0.0;
  291. }
  292. //reference values as calculated by netlib blas
  293. tr_d1 = 2.0;
  294. tr_d2 = 2.0;
  295. tr_x1 = 8.0;
  296. tr_y1 = 8.0;
  297. tr_param[0] = 1.0;
  298. tr_param[1] = 0.0;
  299. tr_param[2] = 0.0;
  300. tr_param[3] = 0.0;
  301. tr_param[4] = 0.0;
  302. //OpenBLAS
  303. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  304. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  305. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  306. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  307. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  308. for(i=0; i<5; i++){
  309. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  310. }
  311. }
  312. /**
  313. * C API specific test
  314. * Test drotmg by comparing it against pre-calculated values
  315. */
  316. CTEST(drotmg, c_api_scaled_y_greater_than_scaled_x)
  317. {
  318. double te_d1, tr_d1;
  319. double te_d2, tr_d2;
  320. double te_x1, tr_x1;
  321. double te_y1, tr_y1;
  322. double te_param[5];
  323. double tr_param[5];
  324. int i = 0;
  325. te_d1 = tr_d1 = 1.0;
  326. te_d2 = tr_d2 = -2.0;
  327. te_x1 = tr_x1 = 8.0;
  328. te_y1 = tr_y1 = 8.0;
  329. for(i=0; i<5; i++){
  330. te_param[i] = tr_param[i] = 0.0;
  331. }
  332. //reference values as calculated by netlib blas
  333. tr_d1 = 0.0;
  334. tr_d2 = 0.0;
  335. tr_x1 = 0.0;
  336. tr_y1 = 8.0;
  337. tr_param[0] = -1.0;
  338. tr_param[1] = 0.0;
  339. tr_param[2] = 0.0;
  340. tr_param[3] = 0.0;
  341. tr_param[4] = 0.0;
  342. //OpenBLAS
  343. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  344. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  345. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  346. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  347. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  348. for(i=0; i<5; i++){
  349. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  350. }
  351. }
  352. #endif
  353. #endif