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