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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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. /**
  151. * C API specific test
  152. * Test crotg by comparing it against pre-calculated values
  153. */
  154. CTEST(crotg, c_api_zero_a)
  155. {
  156. float sa[2] = {0.0f, 0.0f};
  157. float sb[2] = {1.0f, 1.0f};
  158. float ss[2];
  159. float sc;
  160. cblas_crotg(sa, sb, &sc, ss);
  161. ASSERT_DBL_NEAR_TOL(0.0f, sc, SINGLE_EPS);
  162. ASSERT_DBL_NEAR_TOL(0.70711f, ss[0], SINGLE_EPS);
  163. ASSERT_DBL_NEAR_TOL(-0.70711f, ss[1], SINGLE_EPS);
  164. ASSERT_DBL_NEAR_TOL(1.41421f, sa[0], SINGLE_EPS);
  165. ASSERT_DBL_NEAR_TOL(0.0f, sa[1], SINGLE_EPS);
  166. }
  167. /**
  168. * C API specific test
  169. * Test crotg by comparing it against pre-calculated values
  170. */
  171. CTEST(crotg, c_api_zero_b)
  172. {
  173. float sa[2] = {1.0f, 1.0f};
  174. float sb[2] = {0.0f, 0.0f};
  175. float ss[2];
  176. float sc;
  177. cblas_crotg(sa, sb, &sc, ss);
  178. ASSERT_DBL_NEAR_TOL(1.0f, sc, SINGLE_EPS);
  179. ASSERT_DBL_NEAR_TOL(0.0f, ss[0], SINGLE_EPS);
  180. ASSERT_DBL_NEAR_TOL(0.0f, ss[1], SINGLE_EPS);
  181. ASSERT_DBL_NEAR_TOL(1.0f, sa[0], SINGLE_EPS);
  182. ASSERT_DBL_NEAR_TOL(1.0f, sa[1], SINGLE_EPS);
  183. }
  184. /**
  185. * C API specific test
  186. * Test crotg by comparing it against pre-calculated values
  187. */
  188. CTEST(crotg, c_api_zero_real)
  189. {
  190. float sa[2] = {0.0f, 1.0f};
  191. float sb[2] = {0.0f, 1.0f};
  192. float ss[2];
  193. float sc;
  194. cblas_crotg(sa, sb, &sc, ss);
  195. ASSERT_DBL_NEAR_TOL(0.70711f, sc, SINGLE_EPS);
  196. ASSERT_DBL_NEAR_TOL(0.70711f, ss[0], SINGLE_EPS);
  197. ASSERT_DBL_NEAR_TOL(0.0f, ss[1], SINGLE_EPS);
  198. ASSERT_DBL_NEAR_TOL(0.0f, sa[0], SINGLE_EPS);
  199. ASSERT_DBL_NEAR_TOL(1.41421f, sa[1], SINGLE_EPS);
  200. }
  201. /**
  202. * C API specific test
  203. * Test crotg by comparing it against pre-calculated values
  204. */
  205. CTEST(crotg, c_api_positive_real_positive_img)
  206. {
  207. float sa[2] = {3.0f, 4.0f};
  208. float sb[2] = {4.0f, 6.0f};
  209. float ss[2];
  210. float sc;
  211. cblas_crotg(sa, sb, &sc, ss);
  212. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  213. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  214. ASSERT_DBL_NEAR_TOL(-0.04558f, ss[1], SINGLE_EPS);
  215. ASSERT_DBL_NEAR_TOL(5.26498f, sa[0], SINGLE_EPS);
  216. ASSERT_DBL_NEAR_TOL(7.01997f, sa[1], SINGLE_EPS);
  217. }
  218. /**
  219. * C API specific test
  220. * Test crotg by comparing it against pre-calculated values
  221. */
  222. CTEST(crotg, c_api_negative_real_positive_img)
  223. {
  224. float sa[2] = {-3.0f, 4.0f};
  225. float sb[2] = {-4.0f, 6.0f};
  226. float ss[2];
  227. float sc;
  228. cblas_crotg(sa, sb, &sc, ss);
  229. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  230. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  231. ASSERT_DBL_NEAR_TOL(0.04558f, ss[1], SINGLE_EPS);
  232. ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
  233. ASSERT_DBL_NEAR_TOL(7.01997f, sa[1], SINGLE_EPS);
  234. }
  235. /**
  236. * C API specific test
  237. * Test crotg by comparing it against pre-calculated values
  238. */
  239. CTEST(crotg, c_api_positive_real_negative_img)
  240. {
  241. float sa[2] = {3.0f, -4.0f};
  242. float sb[2] = {4.0f, -6.0f};
  243. float ss[2];
  244. float sc;
  245. cblas_crotg(sa, sb, &sc, ss);
  246. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  247. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  248. ASSERT_DBL_NEAR_TOL(0.04558f, ss[1], SINGLE_EPS);
  249. ASSERT_DBL_NEAR_TOL(5.26498f, sa[0], SINGLE_EPS);
  250. ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
  251. }
  252. /**
  253. * C API specific test
  254. * Test crotg by comparing it against pre-calculated values
  255. */
  256. CTEST(crotg, c_api_negative_real_negative_img)
  257. {
  258. float sa[2] = {-3.0f, -4.0f};
  259. float sb[2] = {-4.0f, -6.0f};
  260. float ss[2];
  261. float sc;
  262. cblas_crotg(sa, sb, &sc, ss);
  263. ASSERT_DBL_NEAR_TOL(0.5698f, sc, SINGLE_EPS);
  264. ASSERT_DBL_NEAR_TOL(0.82052f, ss[0], SINGLE_EPS);
  265. ASSERT_DBL_NEAR_TOL(-0.04558f, ss[1], SINGLE_EPS);
  266. ASSERT_DBL_NEAR_TOL(-5.26498f, sa[0], SINGLE_EPS);
  267. ASSERT_DBL_NEAR_TOL(-7.01997f, sa[1], SINGLE_EPS);
  268. }
  269. #endif