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