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_scsum.c 11 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  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. #define ELEMENTS 50
  31. #define INCREMENT 2
  32. #ifdef BUILD_COMPLEX
  33. /**
  34. * Fortran API specific test
  35. * Test scsum by comparing it against pre-calculated values
  36. */
  37. CTEST(scsum, bad_args_N_0){
  38. blasint i;
  39. blasint N = 0, inc = 1;
  40. float x[ELEMENTS * 2];
  41. for (i = 0; i < ELEMENTS * inc * 2; i ++) {
  42. x[i] = 1000 - i;
  43. }
  44. float sum = BLASFUNC(scsum)(&N, x, &inc);
  45. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  46. }
  47. /**
  48. * Fortran API specific test
  49. * Test scsum by comparing it against pre-calculated values
  50. */
  51. CTEST(scsum, step_zero){
  52. blasint i;
  53. blasint N = ELEMENTS, inc = 0;
  54. float x[ELEMENTS];
  55. for (i = 0; i < N * inc * 2; i ++) {
  56. x[i] = i + 1000;
  57. }
  58. x[8] = 0.0f;
  59. float sum = BLASFUNC(scsum)(&N, x, &inc);
  60. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  61. }
  62. /**
  63. * Fortran API specific test
  64. * Test scsum by comparing it against pre-calculated values
  65. */
  66. CTEST(scsum, step_1_N_1){
  67. blasint N = 1, inc = 1;
  68. float x[] = {1.1f, -1.0f};
  69. float sum = BLASFUNC(scsum)(&N, x, &inc);
  70. ASSERT_DBL_NEAR_TOL(0.1f, sum, SINGLE_EPS);
  71. }
  72. /**
  73. * Fortran API specific test
  74. * Test scsum by comparing it against pre-calculated values
  75. */
  76. CTEST(scsum, step_2_N_1){
  77. blasint N = 1, inc = 2;
  78. float x[] = {1.1f, 0.0f, 2.3f, -1.0f};
  79. float sum = BLASFUNC(scsum)(&N, x, &inc);
  80. ASSERT_DBL_NEAR_TOL(1.1f, sum, SINGLE_EPS);
  81. }
  82. /**
  83. * Fortran API specific test
  84. * Test scsum by comparing it against pre-calculated values
  85. */
  86. CTEST(scsum, step_1_N_2){
  87. blasint N = 2, inc = 1;
  88. float x[] = {1.1f, -1.0f, 2.3f, -1.0f};
  89. float sum = BLASFUNC(scsum)(&N, x, &inc);
  90. ASSERT_DBL_NEAR_TOL(1.4f, sum, SINGLE_EPS);
  91. }
  92. /**
  93. * Fortran API specific test
  94. * Test scsum by comparing it against pre-calculated values
  95. */
  96. CTEST(scsum, step_2_N_2){
  97. blasint N = 2, inc = 2;
  98. float x[] = {1.1f, -1.5f, 1.1f, -1.0f, 1.0f, 1.0f, 1.1f, -1.0f};
  99. float sum = BLASFUNC(scsum)(&N, x, &inc);
  100. ASSERT_DBL_NEAR_TOL(1.6f, sum, SINGLE_EPS);
  101. }
  102. /**
  103. * Fortran API specific test
  104. * Test scsum by comparing it against pre-calculated values
  105. */
  106. CTEST(scsum, step_1_N_3){
  107. blasint N = 3, inc = 1;
  108. float x[] = {1.1f, 1.0f, 2.2f, 1.1f, -1.0f, 0.0f};
  109. float sum = BLASFUNC(scsum)(&N, x, &inc);
  110. ASSERT_DBL_NEAR_TOL(4.4f, sum, SINGLE_EPS);
  111. }
  112. /**
  113. * Fortran API specific test
  114. * Test scsum by comparing it against pre-calculated values
  115. */
  116. CTEST(scsum, step_2_N_3){
  117. blasint N = 3, inc = 2;
  118. float x[] = {1.1f, 0.0f, -1.0f, 0.0f, -1.0f, -3.0f, -1.0f, 0.0f, 2.2f, 3.0f, -1.0f, 0.0f};
  119. float sum = BLASFUNC(scsum)(&N, x, &inc);
  120. ASSERT_DBL_NEAR_TOL(2.3f, sum, SINGLE_EPS);
  121. }
  122. /**
  123. * Fortran API specific test
  124. * Test scsum by comparing it against pre-calculated values
  125. */
  126. CTEST(scsum, step_1_N_4){
  127. blasint N = 4, inc = 1;
  128. float x[] = {1.1f, 1.0f, -2.2f, 3.3f, 1.1f, 1.0f, -2.2f, 3.3f};
  129. float sum = BLASFUNC(scsum)(&N, x, &inc);
  130. ASSERT_DBL_NEAR_TOL(6.4f, sum, SINGLE_EPS);
  131. }
  132. /**
  133. * Fortran API specific test
  134. * Test scsum by comparing it against pre-calculated values
  135. */
  136. CTEST(scsum, step_2_N_4){
  137. blasint N = 4, inc = 2;
  138. float x[] = {1.1f, 0.0f, 1.1f, 1.0f, 1.0f, 2.0f, 1.1f, 1.0f, 2.2f, 2.7f, 1.1f, 1.0f, -3.3f, -5.9f};
  139. float sum = BLASFUNC(scsum)(&N, x, &inc);
  140. ASSERT_DBL_NEAR_TOL(-0.2f, sum, SINGLE_EPS);
  141. }
  142. /**
  143. * Fortran API specific test
  144. * Test scsum by comparing it against pre-calculated values
  145. */
  146. CTEST(scsum, step_1_N_5){
  147. blasint N = 5, inc = 1;
  148. float x[] = {0.0f, 1.0f, 2.2f, 3.3f, 0.0f, 0.0f, 1.0f, 2.2f, 3.3f, 0.0f};
  149. float sum = BLASFUNC(scsum)(&N, x, &inc);
  150. ASSERT_DBL_NEAR_TOL(13.0f, sum, SINGLE_EPS);
  151. }
  152. /**
  153. * Fortran API specific test
  154. * Test scsum by comparing it against pre-calculated values
  155. */
  156. CTEST(scsum, step_2_N_5){
  157. blasint N = 5, inc = 2;
  158. float x[] = {0.0f, 3.0f, 1.0f, 2.2f, 1.0f, -2.2f, 1.0f, 2.2f, 2.2f, -1.7f, 1.0f, 2.2f, 3.3f, 14.5f, 1.0f, 2.2f, 0.0f, -9.0f, 1.0f, 2.2f};
  159. float sum = BLASFUNC(scsum)(&N, x, &inc);
  160. ASSERT_DBL_NEAR_TOL(11.1f, sum, SINGLE_EPS);
  161. }
  162. /**
  163. * Fortran API specific test
  164. * Test scsum by comparing it against pre-calculated values
  165. */
  166. CTEST(scsum, step_1_N_50){
  167. blasint i;
  168. blasint N = ELEMENTS, inc = 1;
  169. float x[ELEMENTS * 2];
  170. for (i = 0; i < N * inc * 2; i ++) {
  171. x[i] = (i & 1) ? -1.0f : 1.0f;
  172. }
  173. float sum = BLASFUNC(scsum)(&N, x, &inc);
  174. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  175. }
  176. /**
  177. * Fortran API specific test
  178. * Test scsum by comparing it against pre-calculated values
  179. */
  180. CTEST(scsum, step_2_N_50){
  181. blasint i;
  182. blasint N = ELEMENTS, inc = INCREMENT;
  183. float x[ELEMENTS * INCREMENT * 2];
  184. for (i = 0; i < N * inc * 2; i ++) {
  185. x[i] = (i & 1) ? -1.0f : 1.0f;
  186. }
  187. float sum = BLASFUNC(scsum)(&N, x, &inc);
  188. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  189. }
  190. /**
  191. * C API specific test
  192. * Test scsum by comparing it against pre-calculated values
  193. */
  194. CTEST(scsum, c_api_bad_args_N_0){
  195. blasint i;
  196. blasint N = 0, inc = 1;
  197. float x[ELEMENTS * 2];
  198. for (i = 0; i < ELEMENTS * inc * 2; i ++) {
  199. x[i] = 1000 - i;
  200. }
  201. float sum = cblas_scsum(N, x, inc);
  202. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  203. }
  204. /**
  205. * C API specific test
  206. * Test scsum by comparing it against pre-calculated values
  207. */
  208. CTEST(scsum, c_api_step_zero){
  209. blasint i;
  210. blasint N = ELEMENTS, inc = 0;
  211. float x[ELEMENTS];
  212. for (i = 0; i < N * inc * 2; i ++) {
  213. x[i] = i + 1000;
  214. }
  215. x[8] = 0.0f;
  216. float sum = cblas_scsum(N, x, inc);
  217. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  218. }
  219. /**
  220. * C API specific test
  221. * Test scsum by comparing it against pre-calculated values
  222. */
  223. CTEST(scsum, c_api_step_1_N_1){
  224. blasint N = 1, inc = 1;
  225. float x[] = {1.1f, -1.0f};
  226. float sum = cblas_scsum(N, x, inc);
  227. ASSERT_DBL_NEAR_TOL(0.1f, sum, SINGLE_EPS);
  228. }
  229. /**
  230. * C API specific test
  231. * Test scsum by comparing it against pre-calculated values
  232. */
  233. CTEST(scsum, c_api_step_2_N_1){
  234. blasint N = 1, inc = 2;
  235. float x[] = {1.1f, 0.0f, 2.3f, -1.0f};
  236. float sum = cblas_scsum(N, x, inc);
  237. ASSERT_DBL_NEAR_TOL(1.1f, sum, SINGLE_EPS);
  238. }
  239. /**
  240. * C API specific test
  241. * Test scsum by comparing it against pre-calculated values
  242. */
  243. CTEST(scsum, c_api_step_1_N_2){
  244. blasint N = 2, inc = 1;
  245. float x[] = {1.1f, -1.0f, 2.3f, -1.0f};
  246. float sum = cblas_scsum(N, x, inc);
  247. ASSERT_DBL_NEAR_TOL(1.4f, sum, SINGLE_EPS);
  248. }
  249. /**
  250. * C API specific test
  251. * Test scsum by comparing it against pre-calculated values
  252. */
  253. CTEST(scsum, c_api_step_2_N_2){
  254. blasint N = 2, inc = 2;
  255. float x[] = {1.1f, -1.5f, 1.1f, -1.0f, 1.0f, 1.0f, 1.1f, -1.0f};
  256. float sum = cblas_scsum(N, x, inc);
  257. ASSERT_DBL_NEAR_TOL(1.6f, sum, SINGLE_EPS);
  258. }
  259. /**
  260. * C API specific test
  261. * Test scsum by comparing it against pre-calculated values
  262. */
  263. CTEST(scsum, c_api_step_1_N_3){
  264. blasint N = 3, inc = 1;
  265. float x[] = {1.1f, 1.0f, 2.2f, 1.1f, -1.0f, 0.0f};
  266. float sum = cblas_scsum(N, x, inc);
  267. ASSERT_DBL_NEAR_TOL(4.4f, sum, SINGLE_EPS);
  268. }
  269. /**
  270. * C API specific test
  271. * Test scsum by comparing it against pre-calculated values
  272. */
  273. CTEST(scsum, c_api_step_2_N_3){
  274. blasint N = 3, inc = 2;
  275. float x[] = {1.1f, 0.0f, -1.0f, 0.0f, -1.0f, -3.0f, -1.0f, 0.0f, 2.2f, 3.0f, -1.0f, 0.0f};
  276. float sum = cblas_scsum(N, x, inc);
  277. ASSERT_DBL_NEAR_TOL(2.3f, sum, SINGLE_EPS);
  278. }
  279. /**
  280. * C API specific test
  281. * Test scsum by comparing it against pre-calculated values
  282. */
  283. CTEST(scsum, c_api_step_1_N_4){
  284. blasint N = 4, inc = 1;
  285. float x[] = {1.1f, 1.0f, -2.2f, 3.3f, 1.1f, 1.0f, -2.2f, 3.3f};
  286. float sum = cblas_scsum(N, x, inc);
  287. ASSERT_DBL_NEAR_TOL(6.4f, sum, SINGLE_EPS);
  288. }
  289. /**
  290. * C API specific test
  291. * Test scsum by comparing it against pre-calculated values
  292. */
  293. CTEST(scsum, c_api_step_2_N_4){
  294. blasint N = 4, inc = 2;
  295. float x[] = {1.1f, 0.0f, 1.1f, 1.0f, 1.0f, 2.0f, 1.1f, 1.0f, 2.2f, 2.7f, 1.1f, 1.0f, -3.3f, -5.9f};
  296. float sum = cblas_scsum(N, x, inc);
  297. ASSERT_DBL_NEAR_TOL(-0.2f, sum, SINGLE_EPS);
  298. }
  299. /**
  300. * C API specific test
  301. * Test scsum by comparing it against pre-calculated values
  302. */
  303. CTEST(scsum, c_api_step_1_N_5){
  304. blasint N = 5, inc = 1;
  305. float x[] = {0.0f, 1.0f, 2.2f, 3.3f, 0.0f, 0.0f, 1.0f, 2.2f, 3.3f, 0.0f};
  306. float sum = cblas_scsum(N, x, inc);
  307. ASSERT_DBL_NEAR_TOL(13.0f, sum, SINGLE_EPS);
  308. }
  309. /**
  310. * C API specific test
  311. * Test scsum by comparing it against pre-calculated values
  312. */
  313. CTEST(scsum, c_api_step_2_N_5){
  314. blasint N = 5, inc = 2;
  315. float x[] = {0.0f, 3.0f, 1.0f, 2.2f, 1.0f, -2.2f, 1.0f, 2.2f, 2.2f, -1.7f, 1.0f, 2.2f, 3.3f, 14.5f, 1.0f, 2.2f, 0.0f, -9.0f, 1.0f, 2.2f};
  316. float sum = cblas_scsum(N, x, inc);
  317. ASSERT_DBL_NEAR_TOL(11.1f, sum, SINGLE_EPS);
  318. }
  319. /**
  320. * C API specific test
  321. * Test scsum by comparing it against pre-calculated values
  322. */
  323. CTEST(scsum, c_api_step_1_N_50){
  324. blasint i;
  325. blasint N = ELEMENTS, inc = 1;
  326. float x[ELEMENTS * 2];
  327. for (i = 0; i < N * inc * 2; i ++) {
  328. x[i] = (i & 1) ? -1.0f : 1.0f;
  329. }
  330. float sum = cblas_scsum(N, x, inc);
  331. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  332. }
  333. /**
  334. * C API specific test
  335. * Test scsum by comparing it against pre-calculated values
  336. */
  337. CTEST(scsum, c_api_step_2_N_50){
  338. blasint i;
  339. blasint N = ELEMENTS, inc = INCREMENT;
  340. float x[ELEMENTS * INCREMENT * 2];
  341. for (i = 0; i < N * inc * 2; i ++) {
  342. x[i] = (i & 1) ? -1.0f : 1.0f;
  343. }
  344. float sum = cblas_scsum(N, x, inc);
  345. ASSERT_DBL_NEAR_TOL(0.0f, sum, SINGLE_EPS);
  346. }
  347. #endif