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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. /**
  192. * C API specific test
  193. * Test drotmg by comparing it against pre-calculated values
  194. */
  195. CTEST(drotmg, c_api_y1_zero)
  196. {
  197. double te_d1, tr_d1;
  198. double te_d2, tr_d2;
  199. double te_x1, tr_x1;
  200. double te_y1, tr_y1;
  201. double te_param[5];
  202. double tr_param[5];
  203. int i = 0;
  204. te_d1 = tr_d1 = 2.0;
  205. te_d2 = tr_d2 = 2.0;
  206. te_x1 = tr_x1 = 8.0;
  207. te_y1 = tr_y1 = 0.0;
  208. for(i=0; i<5; i++){
  209. te_param[i] = tr_param[i] = 0.0;
  210. }
  211. //reference values as calculated by netlib blas
  212. tr_d1 = 2.0;
  213. tr_d2 = 2.0;
  214. tr_x1 = 8.0;
  215. tr_y1 = 0.0;
  216. tr_param[0] = -2.0;
  217. tr_param[1] = 0.0;
  218. tr_param[2] = 0.0;
  219. tr_param[3] = 0.0;
  220. tr_param[4] = 0.0;
  221. //OpenBLAS
  222. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  223. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  224. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  225. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  226. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  227. for(i=0; i<5; i++){
  228. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  229. }
  230. }
  231. /**
  232. * C API specific test
  233. * Test drotmg by comparing it against pre-calculated values
  234. */
  235. CTEST(drotmg, c_api_d1_negative)
  236. {
  237. double te_d1, tr_d1;
  238. double te_d2, tr_d2;
  239. double te_x1, tr_x1;
  240. double te_y1, tr_y1;
  241. double te_param[5];
  242. double tr_param[5];
  243. int i = 0;
  244. te_d1 = tr_d1 = -1.0;
  245. te_d2 = tr_d2 = 2.0;
  246. te_x1 = tr_x1 = 8.0;
  247. te_y1 = tr_y1 = 8.0;
  248. for(i=0; i<5; i++){
  249. te_param[i] = tr_param[i] = 0.0;
  250. }
  251. //reference values as calculated by netlib blas
  252. tr_d1 = 0.0;
  253. tr_d2 = 0.0;
  254. tr_x1 = 0.0;
  255. tr_y1 = 8.0;
  256. tr_param[0] = -1.0;
  257. tr_param[1] = 0.0;
  258. tr_param[2] = 0.0;
  259. tr_param[3] = 0.0;
  260. tr_param[4] = 0.0;
  261. //OpenBLAS
  262. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  263. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  264. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  265. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  266. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  267. for(i=0; i<5; i++){
  268. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  269. }
  270. }
  271. /**
  272. * C API specific test
  273. * Test drotmg by comparing it against pre-calculated values
  274. */
  275. CTEST(drotmg, c_api_d1_positive_d2_positive_x1_zero)
  276. {
  277. double te_d1, tr_d1;
  278. double te_d2, tr_d2;
  279. double te_x1, tr_x1;
  280. double te_y1, tr_y1;
  281. double te_param[5];
  282. double tr_param[5];
  283. int i = 0;
  284. te_d1 = tr_d1 = 2.0;
  285. te_d2 = tr_d2 = 2.0;
  286. te_x1 = tr_x1 = 0.0;
  287. te_y1 = tr_y1 = 8.0;
  288. for(i=0; i<5; i++){
  289. te_param[i] = tr_param[i] = 0.0;
  290. }
  291. //reference values as calculated by netlib blas
  292. tr_d1 = 2.0;
  293. tr_d2 = 2.0;
  294. tr_x1 = 8.0;
  295. tr_y1 = 8.0;
  296. tr_param[0] = 1.0;
  297. tr_param[1] = 0.0;
  298. tr_param[2] = 0.0;
  299. tr_param[3] = 0.0;
  300. tr_param[4] = 0.0;
  301. //OpenBLAS
  302. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  303. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  304. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  305. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  306. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  307. for(i=0; i<5; i++){
  308. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  309. }
  310. }
  311. /**
  312. * C API specific test
  313. * Test drotmg by comparing it against pre-calculated values
  314. */
  315. CTEST(drotmg, c_api_scaled_y_greater_than_scaled_x)
  316. {
  317. double te_d1, tr_d1;
  318. double te_d2, tr_d2;
  319. double te_x1, tr_x1;
  320. double te_y1, tr_y1;
  321. double te_param[5];
  322. double tr_param[5];
  323. int i = 0;
  324. te_d1 = tr_d1 = 1.0;
  325. te_d2 = tr_d2 = -2.0;
  326. te_x1 = tr_x1 = 8.0;
  327. te_y1 = tr_y1 = 8.0;
  328. for(i=0; i<5; i++){
  329. te_param[i] = tr_param[i] = 0.0;
  330. }
  331. //reference values as calculated by netlib blas
  332. tr_d1 = 0.0;
  333. tr_d2 = 0.0;
  334. tr_x1 = 0.0;
  335. tr_y1 = 8.0;
  336. tr_param[0] = -1.0;
  337. tr_param[1] = 0.0;
  338. tr_param[2] = 0.0;
  339. tr_param[3] = 0.0;
  340. tr_param[4] = 0.0;
  341. //OpenBLAS
  342. cblas_drotmg(&te_d1, &te_d2, &te_x1, te_y1, te_param);
  343. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  344. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  345. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  346. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  347. for(i=0; i<5; i++){
  348. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  349. }
  350. }
  351. #endif