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_crotg.c 9.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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_COMPLEX
  31. /**
  32. * Fortran API specific test
  33. * Test crotg by comparing it against pre-calculated values
  34. */
  35. CTEST(crotg, zero_a)
  36. {
  37. float sa[2] = {0.0f, 0.0f};
  38. float sb[2] = {1.0f, 1.0f};
  39. float ss[2];
  40. float sc;
  41. BLASFUNC(crotg)(sa, sb, &sc, ss);
  42. ASSERT_DBL_NEAR_TOL(0.0f, sc, SINGLE_EPS);
  43. ASSERT_DBL_NEAR_TOL(0.70711f, ss[0], SINGLE_EPS);
  44. ASSERT_DBL_NEAR_TOL(-0.70711f, ss[1], SINGLE_EPS);
  45. ASSERT_DBL_NEAR_TOL(1.41421f, sa[0], SINGLE_EPS);
  46. ASSERT_DBL_NEAR_TOL(0.0f, sa[1], SINGLE_EPS);
  47. }
  48. /**
  49. * Fortran API specific test
  50. * Test crotg by comparing it against pre-calculated values
  51. */
  52. CTEST(crotg, zero_b)
  53. {
  54. float sa[2] = {1.0f, 1.0f};
  55. float sb[2] = {0.0f, 0.0f};
  56. float ss[2];
  57. float sc;
  58. BLASFUNC(crotg)(sa, sb, &sc, ss);
  59. ASSERT_DBL_NEAR_TOL(1.0f, sc, SINGLE_EPS);
  60. ASSERT_DBL_NEAR_TOL(0.0f, ss[0], SINGLE_EPS);
  61. ASSERT_DBL_NEAR_TOL(0.0f, ss[1], SINGLE_EPS);
  62. ASSERT_DBL_NEAR_TOL(1.0f, sa[0], SINGLE_EPS);
  63. ASSERT_DBL_NEAR_TOL(1.0f, sa[1], SINGLE_EPS);
  64. }
  65. /**
  66. * Fortran API specific test
  67. * Test crotg by comparing it against pre-calculated values
  68. */
  69. CTEST(crotg, zero_real)
  70. {
  71. float sa[2] = {0.0f, 1.0f};
  72. float sb[2] = {0.0f, 1.0f};
  73. float ss[2];
  74. float sc;
  75. BLASFUNC(crotg)(sa, sb, &sc, ss);
  76. ASSERT_DBL_NEAR_TOL(0.70711f, sc, SINGLE_EPS);
  77. ASSERT_DBL_NEAR_TOL(0.70711f, ss[0], SINGLE_EPS);
  78. ASSERT_DBL_NEAR_TOL(0.0f, ss[1], SINGLE_EPS);
  79. ASSERT_DBL_NEAR_TOL(0.0f, sa[0], SINGLE_EPS);
  80. ASSERT_DBL_NEAR_TOL(1.41421f, sa[1], SINGLE_EPS);
  81. }
  82. /**
  83. * Fortran API specific test
  84. * Test crotg by comparing it against pre-calculated values
  85. */
  86. CTEST(crotg, positive_real_positive_img)
  87. {
  88. float sa[2] = {3.0f, 4.0f};
  89. float sb[2] = {4.0f, 6.0f};
  90. float ss[2];
  91. float sc;
  92. BLASFUNC(crotg)(sa, sb, &sc, ss);
  93. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  94. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  95. ASSERT_DBL_NEAR_TOL(-0.04558f, ss[1], SINGLE_EPS);
  96. ASSERT_DBL_NEAR_TOL(5.26498f, sa[0], SINGLE_EPS);
  97. ASSERT_DBL_NEAR_TOL(7.01997f, sa[1], SINGLE_EPS);
  98. }
  99. /**
  100. * Fortran API specific test
  101. * Test crotg by comparing it against pre-calculated values
  102. */
  103. CTEST(crotg, negative_real_positive_img)
  104. {
  105. float sa[2] = {-3.0f, 4.0f};
  106. float sb[2] = {-4.0f, 6.0f};
  107. float ss[2];
  108. float sc;
  109. BLASFUNC(crotg)(sa, sb, &sc, ss);
  110. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  111. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  112. ASSERT_DBL_NEAR_TOL(0.04558f, ss[1], SINGLE_EPS);
  113. ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
  114. ASSERT_DBL_NEAR_TOL(7.01997f, sa[1], SINGLE_EPS);
  115. }
  116. /**
  117. * Fortran API specific test
  118. * Test crotg by comparing it against pre-calculated values
  119. */
  120. CTEST(crotg, positive_real_negative_img)
  121. {
  122. float sa[2] = {3.0f, -4.0f};
  123. float sb[2] = {4.0f, -6.0f};
  124. float ss[2];
  125. float sc;
  126. BLASFUNC(crotg)(sa, sb, &sc, ss);
  127. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  128. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  129. ASSERT_DBL_NEAR_TOL(0.04558f, ss[1], SINGLE_EPS);
  130. ASSERT_DBL_NEAR_TOL(5.26498f, sa[0], SINGLE_EPS);
  131. ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
  132. }
  133. /**
  134. * Fortran API specific test
  135. * Test crotg by comparing it against pre-calculated values
  136. */
  137. CTEST(crotg, negative_real_negative_img)
  138. {
  139. float sa[2] = {-3.0f, -4.0f};
  140. float sb[2] = {-4.0f, -6.0f};
  141. float ss[2];
  142. float sc;
  143. BLASFUNC(crotg)(sa, sb, &sc, ss);
  144. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  145. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  146. ASSERT_DBL_NEAR_TOL(-0.04558f, ss[1], SINGLE_EPS);
  147. ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
  148. ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
  149. }
  150. #ifndef NO_CBLAS
  151. /**
  152. * C API specific test
  153. * Test crotg by comparing it against pre-calculated values
  154. */
  155. CTEST(crotg, c_api_zero_a)
  156. {
  157. float sa[2] = {0.0f, 0.0f};
  158. float sb[2] = {1.0f, 1.0f};
  159. float ss[2];
  160. float sc;
  161. cblas_crotg(sa, sb, &sc, ss);
  162. ASSERT_DBL_NEAR_TOL(0.0f, sc, SINGLE_EPS);
  163. ASSERT_DBL_NEAR_TOL(0.70711f, ss[0], SINGLE_EPS);
  164. ASSERT_DBL_NEAR_TOL(-0.70711f, ss[1], SINGLE_EPS);
  165. ASSERT_DBL_NEAR_TOL(1.41421f, sa[0], SINGLE_EPS);
  166. ASSERT_DBL_NEAR_TOL(0.0f, sa[1], SINGLE_EPS);
  167. }
  168. /**
  169. * C API specific test
  170. * Test crotg by comparing it against pre-calculated values
  171. */
  172. CTEST(crotg, c_api_zero_b)
  173. {
  174. float sa[2] = {1.0f, 1.0f};
  175. float sb[2] = {0.0f, 0.0f};
  176. float ss[2];
  177. float sc;
  178. cblas_crotg(sa, sb, &sc, ss);
  179. ASSERT_DBL_NEAR_TOL(1.0f, sc, SINGLE_EPS);
  180. ASSERT_DBL_NEAR_TOL(0.0f, ss[0], SINGLE_EPS);
  181. ASSERT_DBL_NEAR_TOL(0.0f, ss[1], SINGLE_EPS);
  182. ASSERT_DBL_NEAR_TOL(1.0f, sa[0], SINGLE_EPS);
  183. ASSERT_DBL_NEAR_TOL(1.0f, sa[1], SINGLE_EPS);
  184. }
  185. /**
  186. * C API specific test
  187. * Test crotg by comparing it against pre-calculated values
  188. */
  189. CTEST(crotg, c_api_zero_real)
  190. {
  191. float sa[2] = {0.0f, 1.0f};
  192. float sb[2] = {0.0f, 1.0f};
  193. float ss[2];
  194. float sc;
  195. cblas_crotg(sa, sb, &sc, ss);
  196. ASSERT_DBL_NEAR_TOL(0.70711f, sc, SINGLE_EPS);
  197. ASSERT_DBL_NEAR_TOL(0.70711f, ss[0], SINGLE_EPS);
  198. ASSERT_DBL_NEAR_TOL(0.0f, ss[1], SINGLE_EPS);
  199. ASSERT_DBL_NEAR_TOL(0.0f, sa[0], SINGLE_EPS);
  200. ASSERT_DBL_NEAR_TOL(1.41421f, sa[1], SINGLE_EPS);
  201. }
  202. /**
  203. * C API specific test
  204. * Test crotg by comparing it against pre-calculated values
  205. */
  206. CTEST(crotg, c_api_positive_real_positive_img)
  207. {
  208. float sa[2] = {3.0f, 4.0f};
  209. float sb[2] = {4.0f, 6.0f};
  210. float ss[2];
  211. float sc;
  212. cblas_crotg(sa, sb, &sc, ss);
  213. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  214. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  215. ASSERT_DBL_NEAR_TOL(-0.04558f, ss[1], SINGLE_EPS);
  216. ASSERT_DBL_NEAR_TOL(5.26498f, sa[0], SINGLE_EPS);
  217. ASSERT_DBL_NEAR_TOL(7.01997f, sa[1], SINGLE_EPS);
  218. }
  219. /**
  220. * C API specific test
  221. * Test crotg by comparing it against pre-calculated values
  222. */
  223. CTEST(crotg, c_api_negative_real_positive_img)
  224. {
  225. float sa[2] = {-3.0f, 4.0f};
  226. float sb[2] = {-4.0f, 6.0f};
  227. float ss[2];
  228. float sc;
  229. cblas_crotg(sa, sb, &sc, ss);
  230. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  231. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  232. ASSERT_DBL_NEAR_TOL(0.04558f, ss[1], SINGLE_EPS);
  233. ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
  234. ASSERT_DBL_NEAR_TOL(7.01997f, sa[1], SINGLE_EPS);
  235. }
  236. /**
  237. * C API specific test
  238. * Test crotg by comparing it against pre-calculated values
  239. */
  240. CTEST(crotg, c_api_positive_real_negative_img)
  241. {
  242. float sa[2] = {3.0f, -4.0f};
  243. float sb[2] = {4.0f, -6.0f};
  244. float ss[2];
  245. float sc;
  246. cblas_crotg(sa, sb, &sc, ss);
  247. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  248. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  249. ASSERT_DBL_NEAR_TOL(0.04558f, ss[1], SINGLE_EPS);
  250. ASSERT_DBL_NEAR_TOL(5.26498f, sa[0], SINGLE_EPS);
  251. ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
  252. }
  253. /**
  254. * C API specific test
  255. * Test crotg by comparing it against pre-calculated values
  256. */
  257. CTEST(crotg, c_api_negative_real_negative_img)
  258. {
  259. float sa[2] = {-3.0f, -4.0f};
  260. float sb[2] = {-4.0f, -6.0f};
  261. float ss[2];
  262. float sc;
  263. cblas_crotg(sa, sb, &sc, ss);
  264. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  265. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  266. ASSERT_DBL_NEAR_TOL(-0.04558f, ss[1], SINGLE_EPS);
  267. ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
  268. ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
  269. }
  270. #endif
  271. #endif