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.

utest_main2.c 18 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712
  1. /*****************************************************************************
  2. Copyright (c) 2011-2016, 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 <stdio.h>
  29. #include <complex.h>
  30. #define CTEST_MAIN
  31. #define CTEST_SEGFAULT
  32. #define CTEST_ADD_TESTS_MANUALLY
  33. #include "cblas.h"
  34. #include "openblas_utest.h"
  35. #if 1
  36. CTEST(amax, samax){
  37. blasint N=3, inc=1;
  38. float te_max=0.0, tr_max=0.0;
  39. float x[]={-1.1, 2.2, -3.3};
  40. fprintf(stderr,"testing samax\n");
  41. te_max=BLASFUNC(samax)(&N, x, &inc);
  42. tr_max=3.3;
  43. ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
  44. }
  45. CTEST(amax, damax){
  46. blasint N=3, inc=1;
  47. double te_max=0.0, tr_max=0.0;
  48. double x[]={-1.1, 2.2, -3.3};
  49. fprintf(stderr,"testing damax\n");
  50. te_max=BLASFUNC(damax)(&N, x, &inc);
  51. tr_max=3.3;
  52. ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
  53. }
  54. CTEST (drotmg,rotmg)
  55. {
  56. double te_d1, tr_d1;
  57. double te_d2, tr_d2;
  58. double te_x1, tr_x1;
  59. double te_y1, tr_y1;
  60. double te_param[5];
  61. double tr_param[5];
  62. int i=0;
  63. // original test case for libGoto bug fixed by feb2014 rewrite
  64. te_d1= 0.21149573940783739;
  65. te_d2= 0.046892057172954082;
  66. te_x1= -0.42272687517106533;
  67. te_y1= 0.42211309121921659;
  68. for(i=0; i<5; i++){
  69. te_param[i]=tr_param[i]=0.0;
  70. }
  71. //reference values as calculated by netlib blas
  72. tr_d1= 0.1732048;
  73. tr_d2= 0.03840234;
  74. tr_x1= -0.516180;
  75. tr_y1= 0.422113;
  76. tr_d1= 0.17320483687975;
  77. tr_d2= 0.03840233915037;
  78. tr_x1= -0.51618034832329;
  79. tr_y1= 0.42211309121922;
  80. tr_param[0]= 0.0;
  81. tr_param[1]= 0.0;
  82. tr_param[2]= 0.99854803659786;
  83. tr_param[3]= -0.22139439665872;
  84. tr_param[4]= 0.0;
  85. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  86. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  87. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  88. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  89. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  90. for(i=0; i<5; i++){
  91. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  92. }
  93. }
  94. CTEST (drotmg,rotmg_issue1452)
  95. {
  96. double te_d1, tr_d1;
  97. double te_d2, tr_d2;
  98. double te_x1, tr_x1;
  99. double te_y1, tr_y1;
  100. double te_param[5];
  101. double tr_param[5];
  102. int i=0;
  103. // from issue #1452
  104. te_d1 = 5.9e-8;
  105. te_d2 = 5.960464e-8;
  106. te_x1 = 1.0;
  107. te_y1 = 150.0;
  108. for(i=0; i<5; i++){
  109. te_param[i]=tr_param[i]=0.0;
  110. }
  111. te_param[3]=1./4096.;
  112. //reference values as calculated by gonum blas with rotmg rewritten to Hopkins' algorithm
  113. tr_d1= 0.99995592822897;
  114. tr_d2= 0.98981219860583;
  115. tr_x1= 0.03662270484346;
  116. tr_y1= 150.000000000000;
  117. tr_param[0]= -1.0;
  118. tr_param[1]= 0.00000161109346;
  119. tr_param[2]= -0.00024414062500;
  120. tr_param[3]= 0.00024414062500;
  121. tr_param[4]= 0.00000162760417;
  122. //OpenBLAS
  123. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  124. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  125. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  126. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  127. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  128. for(i=0; i<5; i++){
  129. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  130. }
  131. }
  132. CTEST(drotmg, rotmg_D1eqD2_X1eqX2)
  133. {
  134. double te_d1, tr_d1;
  135. double te_d2, tr_d2;
  136. double te_x1, tr_x1;
  137. double te_y1, tr_y1;
  138. double te_param[5];
  139. double tr_param[5];
  140. int i=0;
  141. te_d1= tr_d1=2.;
  142. te_d2= tr_d2=2.;
  143. te_x1= tr_x1=8.;
  144. te_y1= tr_y1=8.;
  145. for(i=0; i<5; i++){
  146. te_param[i]=tr_param[i]=0.0;
  147. }
  148. //reference values as calculated by netlib blas
  149. tr_d1= 1.0;
  150. tr_d2= 1.0;
  151. tr_x1= 16.0;
  152. tr_y1= 8.0;
  153. tr_param[0]=1.0;
  154. tr_param[1]=1.0;
  155. tr_param[2]=0.0;
  156. tr_param[3]=0.0;
  157. tr_param[4]=1.0;
  158. //OpenBLAS
  159. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  160. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  161. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  162. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  163. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  164. for(i=0; i<5; i++){
  165. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  166. }
  167. }
  168. CTEST(drotmg, drotmg_D1_big_D2_big_flag_zero)
  169. {
  170. double te_d1, tr_d1;
  171. double te_d2, tr_d2;
  172. double te_x1, tr_x1;
  173. double te_y1, tr_y1;
  174. double te_param[5]={1.,4096.,-4096.,1.,4096.};
  175. double tr_param[5]={-1.,4096.,-3584.,1792.,4096.};
  176. int i=0;
  177. te_d1= tr_d1=1600000000.;
  178. te_d2= tr_d2=800000000.;
  179. te_x1= tr_x1=8.;
  180. te_y1= tr_y1=7.;
  181. //reference values as calculated by gonum
  182. tr_d1= 68.96627824858757;
  183. tr_d2= 34.483139124293785;
  184. tr_x1= 45312.;
  185. tr_y1= 7.0;
  186. //OpenBLAS
  187. BLASFUNC(drotmg)(&te_d1, &te_d2, &te_x1, &te_y1, te_param);
  188. ASSERT_DBL_NEAR_TOL(tr_d1, te_d1, DOUBLE_EPS);
  189. ASSERT_DBL_NEAR_TOL(tr_d2, te_d2, DOUBLE_EPS);
  190. ASSERT_DBL_NEAR_TOL(tr_x1, te_x1, DOUBLE_EPS);
  191. ASSERT_DBL_NEAR_TOL(tr_y1, te_y1, DOUBLE_EPS);
  192. for(i=0; i<5; i++){
  193. ASSERT_DBL_NEAR_TOL(tr_param[i], te_param[i], DOUBLE_EPS);
  194. }
  195. }
  196. CTEST(axpy,daxpy_inc_0)
  197. {
  198. blasint i;
  199. blasint N=8,incX=0,incY=0;
  200. double a=0.25;
  201. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  202. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  203. double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  204. double y2[]={4.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  205. //OpenBLAS
  206. BLASFUNC(daxpy)(&N,&a,x1,&incX,y1,&incY);
  207. for(i=0; i<N; i++){
  208. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  209. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  210. }
  211. }
  212. CTEST(axpy,zaxpy_inc_0)
  213. {
  214. blasint i;
  215. blasint N=4,incX=0,incY=0;
  216. double a[2]={0.25,0.5};
  217. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  218. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  219. double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  220. double y2[]={-3.0,9.0,6.0,8.0,2.0,4.0,6.0,8.0};
  221. //OpenBLAS
  222. BLASFUNC(zaxpy)(&N,a,x1,&incX,y1,&incY);
  223. for(i=0; i<2*N; i++){
  224. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  225. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  226. }
  227. }
  228. CTEST(axpy,saxpy_inc_0)
  229. {
  230. blasint i;
  231. blasint N=8,incX=0,incY=0;
  232. float a=0.25;
  233. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  234. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  235. float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  236. float y2[]={4.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  237. //OpenBLAS
  238. BLASFUNC(saxpy)(&N,&a,x1,&incX,y1,&incY);
  239. for(i=0; i<N; i++){
  240. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  241. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  242. }
  243. }
  244. CTEST(axpy,caxpy_inc_0)
  245. {
  246. blasint i;
  247. blasint N=4,incX=0,incY=0;
  248. float a[2]={0.25,0.5};
  249. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  250. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  251. float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  252. float y2[]={-3.0,9.0,6.0,8.0,2.0,4.0,6.0,8.0};
  253. //OpenBLAS
  254. BLASFUNC(caxpy)(&N,a,x1,&incX,y1,&incY);
  255. for(i=0; i<2*N; i++){
  256. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  257. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  258. }
  259. }
  260. CTEST( zdotu,zdotu_n_1)
  261. {
  262. blasint N=1,incX=1,incY=1;
  263. double x1[]={1.0,1.0};
  264. double y1[]={1.0,2.0};
  265. openblas_complex_double result1=openblas_make_complex_double(0.0,0.0);
  266. openblas_complex_double result2=openblas_make_complex_double(-1.0,3.0);
  267. #ifdef RETURN_BY_STACK
  268. BLASFUNC(zdotu)(&result1,&N,x1,&incX,y1,&incY);
  269. #else
  270. result1=BLASFUNC(zdotu)(&N,x1,&incX,y1,&incY);
  271. #endif
  272. #ifdef OPENBLAS_COMPLEX_STRUCT
  273. ASSERT_DBL_NEAR_TOL(result2.real, result1.real, DOUBLE_EPS);
  274. ASSERT_DBL_NEAR_TOL(result2.imag, result1.imag, DOUBLE_EPS);
  275. #else
  276. ASSERT_DBL_NEAR_TOL(creal(result2), creal(result1), DOUBLE_EPS);
  277. ASSERT_DBL_NEAR_TOL(cimag(result2), cimag(result1), DOUBLE_EPS);
  278. #endif
  279. }
  280. CTEST(zdotu, zdotu_offset_1)
  281. {
  282. blasint N=1,incX=1,incY=1;
  283. double x1[]={1.0,2.0,3.0,4.0};
  284. double y1[]={5.0,6.0,7.0,8.0};
  285. openblas_complex_double result1=openblas_make_complex_double(0.0,0.0);
  286. openblas_complex_double result2=openblas_make_complex_double(-9.0,32.0);
  287. #ifdef RETURN_BY_STACK
  288. BLASFUNC(zdotu)(&result1,&N,x1+1,&incX,y1+1,&incY);
  289. #else
  290. result1=BLASFUNC(zdotu)(&N,x1+1,&incX,y1+1,&incY);
  291. #endif
  292. #ifdef OPENBLAS_COMPLEX_STRUCT
  293. ASSERT_DBL_NEAR_TOL(result2.real, result1.real, DOUBLE_EPS);
  294. ASSERT_DBL_NEAR_TOL(result2.imag, result1.imag, DOUBLE_EPS);
  295. #else
  296. ASSERT_DBL_NEAR_TOL(creal(result2), creal(result1), DOUBLE_EPS);
  297. ASSERT_DBL_NEAR_TOL(cimag(result2), cimag(result1), DOUBLE_EPS);
  298. #endif
  299. }
  300. CTEST(dsdot,dsdot_n_1)
  301. {
  302. float x= 0.172555164F;
  303. float y= -0.0138700781F;
  304. blasint incx=1;
  305. blasint incy=1;
  306. blasint n=1;
  307. double res1=0.0f, res2=-0.00239335360107;
  308. res1=BLASFUNC(dsdot)(&n, &x, &incx, &y, &incy);
  309. ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
  310. }
  311. #if defined(BUILD_DOUBLE)
  312. CTEST(dnrm2,dnrm2_inf)
  313. {
  314. #ifndef INFINITY
  315. #define INFINITY HUGE_VAL
  316. #endif
  317. int i;
  318. double x[29];
  319. blasint incx=1;
  320. blasint n=28;
  321. double res1=0.0f, res2=INFINITY;
  322. for (i=0;i<n;i++)x[i]=0.0f;
  323. x[10]=-INFINITY;
  324. res1=BLASFUNC(dnrm2)(&n, x, &incx);
  325. ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
  326. }
  327. CTEST(dnrm2,dnrm2_tiny)
  328. {
  329. int i;
  330. double x[29];
  331. blasint incx=1;
  332. blasint n=28;
  333. double res1=0.0f, res2=0.0f;
  334. for (i=0;i<n;i++)x[i]=7.457008414e-310;
  335. res1=BLASFUNC(dnrm2)(&n, x, &incx);
  336. ASSERT_DBL_NEAR_TOL(res2, res1, DOUBLE_EPS);
  337. }
  338. #endif
  339. CTEST(rot,drot_inc_0)
  340. {
  341. blasint i=0;
  342. blasint N=4,incX=0,incY=0;
  343. double c=0.25,s=0.5;
  344. double x1[]={1.0,3.0,5.0,7.0};
  345. double y1[]={2.0,4.0,6.0,8.0};
  346. double x2[]={-0.21484375000000,3.0,5.0,7.0};
  347. double y2[]={ 0.03906250000000,4.0,6.0,8.0};
  348. //OpenBLAS
  349. BLASFUNC(drot)(&N,x1,&incX,y1,&incY,&c,&s);
  350. for(i=0; i<N; i++){
  351. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  352. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  353. }
  354. }
  355. CTEST(rot,zdrot_inc_0)
  356. {
  357. blasint i=0;
  358. blasint N=4,incX=0,incY=0;
  359. double c=0.25,s=0.5;
  360. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  361. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  362. double x2[]={-0.21484375000000,-0.45703125000000 ,5.0,7.0,1.0,3.0,5.0,7.0};
  363. double y2[]={ 0.03906250000000, 0.17187500000000 ,6.0,8.0,2.0,4.0,6.0,8.0};
  364. //OpenBLAS
  365. BLASFUNC(zdrot)(&N,x1,&incX,y1,&incY,&c,&s);
  366. for(i=0; i<2*N; i++){
  367. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  368. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  369. }
  370. }
  371. CTEST(rot,srot_inc_0)
  372. {
  373. blasint i=0;
  374. blasint N=4,incX=0,incY=0;
  375. float c=0.25,s=0.5;
  376. float x1[]={1.0,3.0,5.0,7.0};
  377. float y1[]={2.0,4.0,6.0,8.0};
  378. float x2[]={-0.21484375000000,3.0,5.0,7.0};
  379. float y2[]={ 0.03906250000000,4.0,6.0,8.0};
  380. //OpenBLAS
  381. BLASFUNC(srot)(&N,x1,&incX,y1,&incY,&c,&s);
  382. for(i=0; i<N; i++){
  383. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  384. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  385. }
  386. }
  387. CTEST(rot, csrot_inc_0)
  388. {
  389. blasint i=0;
  390. blasint N=4,incX=0,incY=0;
  391. float c=0.25,s=0.5;
  392. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  393. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  394. float x2[]={-0.21484375000000,-0.45703125000000 ,5.0,7.0,1.0,3.0,5.0,7.0};
  395. float y2[]={ 0.03906250000000, 0.17187500000000 ,6.0,8.0,2.0,4.0,6.0,8.0};
  396. //OpenBLAS
  397. BLASFUNC(csrot)(&N,x1,&incX,y1,&incY,&c,&s);
  398. for(i=0; i<2*N; i++){
  399. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  400. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  401. }
  402. }
  403. CTEST(swap,dswap_inc_0)
  404. {
  405. blasint i=0;
  406. blasint N=4,incX=0,incY=0;
  407. double x1[]={1.0,3.0,5.0,7.0};
  408. double y1[]={2.0,4.0,6.0,8.0};
  409. double x2[]={1.0,3.0,5.0,7.0};
  410. double y2[]={2.0,4.0,6.0,8.0};
  411. //OpenBLAS
  412. BLASFUNC(dswap)(&N,x1,&incX,y1,&incY);
  413. for(i=0; i<N; i++){
  414. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  415. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  416. }
  417. }
  418. CTEST(swap,zswap_inc_0)
  419. {
  420. blasint i=0;
  421. blasint N=4,incX=0,incY=0;
  422. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  423. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  424. double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  425. double y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  426. //OpenBLAS
  427. BLASFUNC(zswap)(&N,x1,&incX,y1,&incY);
  428. for(i=0; i<2*N; i++){
  429. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  430. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  431. }
  432. }
  433. CTEST(swap,sswap_inc_0)
  434. {
  435. blasint i=0;
  436. blasint N=4,incX=0,incY=0;
  437. float x1[]={1.0,3.0,5.0,7.0};
  438. float y1[]={2.0,4.0,6.0,8.0};
  439. float x2[]={1.0,3.0,5.0,7.0};
  440. float y2[]={2.0,4.0,6.0,8.0};
  441. //OpenBLAS
  442. BLASFUNC(sswap)(&N,x1,&incX,y1,&incY);
  443. for(i=0; i<N; i++){
  444. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  445. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  446. }
  447. }
  448. CTEST(swap,cswap_inc_0)
  449. {
  450. blasint i=0;
  451. blasint N=4,incX=0,incY=0;
  452. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  453. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  454. float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  455. float y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  456. //OpenBLAS
  457. BLASFUNC(cswap)(&N,x1,&incX,y1,&incY);
  458. for(i=0; i<2*N; i++){
  459. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  460. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  461. }
  462. }
  463. CTEST(min, smin_negative){
  464. blasint N=3, inc=1;
  465. float te_min=0.0, tr_min=0.0;
  466. float x[]={-1.1, -2.2, -3.3};
  467. te_min=BLASFUNC(smin)(&N, x, &inc);
  468. tr_min=-3.3;
  469. ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
  470. }
  471. CTEST(min, dmin_positive){
  472. blasint N=3, inc=1;
  473. double te_min=0.0, tr_min=0.0;
  474. double x[]={1.1, 0.0, 3.3};
  475. te_min=BLASFUNC(dmin)(&N, x, &inc);
  476. tr_min=0.0;
  477. ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), DOUBLE_EPS);
  478. }
  479. CTEST(min, smin_zero){
  480. blasint N=3, inc=1;
  481. float te_min=0.0, tr_min=0.0;
  482. float x[]={1.1, 2.2, 0.0};
  483. te_min=BLASFUNC(smin)(&N, x, &inc);
  484. tr_min=0.0;
  485. ASSERT_DBL_NEAR_TOL((double)(tr_min), (double)(te_min), SINGLE_EPS);
  486. }
  487. CTEST(max, smax_negative){
  488. blasint N=3, inc=1;
  489. float te_max=0.0, tr_max=0.0;
  490. float x[]={-1.1, -2.2, -3.3};
  491. te_max=BLASFUNC(smax)(&N, x, &inc);
  492. tr_max=-1.1;
  493. ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
  494. }
  495. CTEST(max, dmax_positive){
  496. blasint N=3, inc=1;
  497. double te_max=0.0, tr_max=0.0;
  498. double x[]={1.1, 0.0, 3.3};
  499. te_max=BLASFUNC(dmax)(&N, x, &inc);
  500. tr_max=3.3;
  501. ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), DOUBLE_EPS);
  502. }
  503. CTEST(max, smax_zero){
  504. blasint N=3, inc=1;
  505. float te_max=0.0, tr_max=0.0;
  506. float x[]={-1.1, -2.2, 0.0};
  507. te_max=BLASFUNC(smax)(&N, x, &inc);
  508. tr_max=0.0;
  509. ASSERT_DBL_NEAR_TOL((double)(tr_max), (double)(te_max), SINGLE_EPS);
  510. }
  511. CTEST(zscal, i_nan)
  512. {
  513. double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
  514. double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
  515. cblas_zscal(9, i, &nan, 1);
  516. ASSERT_TRUE(isnan(nan[0]));
  517. ASSERT_TRUE(isnan(nan[1]));
  518. ASSERT_TRUE(isnan(nan[16]));
  519. ASSERT_TRUE(isnan(nan[17]));
  520. }
  521. CTEST(zscal, nan_i)
  522. {
  523. double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
  524. double nan[] = {NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0, NAN,0};
  525. cblas_zscal(9, &nan, &i, 1);
  526. ASSERT_TRUE(isnan(i[0]));
  527. ASSERT_TRUE(isnan(i[1]));
  528. ASSERT_TRUE(isnan(i[16]));
  529. ASSERT_TRUE(isnan(i[17]));
  530. }
  531. CTEST(zscal, i_inf)
  532. {
  533. double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
  534. double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
  535. cblas_zscal(9, i, &inf, 1);
  536. ASSERT_TRUE(isnan(inf[0]));
  537. ASSERT_TRUE(isinf(inf[1]));
  538. ASSERT_TRUE(isnan(inf[16]));
  539. ASSERT_TRUE(isinf(inf[17]));
  540. }
  541. CTEST(zscal, inf_i)
  542. {
  543. double i[] = {0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1, 0,1 };
  544. double inf[] = {INFINITY, 0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0, INFINITY,0};
  545. cblas_zscal(9, &inf, &i, 1);
  546. ASSERT_TRUE(isnan(i[0]));
  547. ASSERT_TRUE(isinf(i[1]));
  548. ASSERT_TRUE(isnan(i[16]));
  549. ASSERT_TRUE(isinf(i[17]));
  550. }
  551. #endif
  552. int main(int argc, const char ** argv){
  553. fprintf(stderr,"adding tests...\n");
  554. #if 1
  555. CTEST_ADD (amax, samax);
  556. CTEST_ADD (amax, damax);
  557. CTEST_ADD (min, smin_negative);
  558. CTEST_ADD (min, dmin_positive);
  559. CTEST_ADD (min, smin_zero);
  560. CTEST_ADD (max, smax_negative);
  561. CTEST_ADD (max, dmax_positive);
  562. CTEST_ADD (max, smax_zero);
  563. CTEST_ADD (drotmg,rotmg);
  564. CTEST_ADD (drotmg,rotmg_issue1452);
  565. CTEST_ADD (drotmg,rotmg_D1eqD2_X1eqX2);
  566. CTEST_ADD (drotmg,drotmg_D1_big_D2_big_flag_zero);
  567. CTEST_ADD (axpy,daxpy_inc_0);
  568. CTEST_ADD (axpy,zaxpy_inc_0);
  569. CTEST_ADD (axpy,saxpy_inc_0);
  570. CTEST_ADD (axpy,caxpy_inc_0);
  571. CTEST_ADD (zdotu,zdotu_n_1);
  572. CTEST_ADD (zdotu,zdotu_offset_1);
  573. CTEST_ADD (dsdot,dsdot_n_1);
  574. // CTEST_ADD (dnrm2,dnrm2_inf);
  575. // CTEST_ADD (dnrm2,dnrm2_tiny);
  576. CTEST_ADD (rot,drot_inc_0);
  577. CTEST_ADD (rot,zdrot_inc_0);
  578. CTEST_ADD (rot,srot_inc_0);
  579. CTEST_ADD (rot,csrot_inc_0);
  580. CTEST_ADD (swap,dswap_inc_0);
  581. CTEST_ADD (swap,zswap_inc_0);
  582. CTEST_ADD (swap,sswap_inc_0);
  583. CTEST_ADD (swap,cswap_inc_0);
  584. CTEST_ADD (zscal, i_nan);
  585. CTEST_ADD (zscal, nan_i);
  586. CTEST_ADD (zscal, i_inf);
  587. CTEST_ADD (zscal, inf_i);
  588. #endif
  589. int num_fail=0;
  590. fprintf(stderr,"running tests from ctest_main\n");
  591. num_fail=ctest_main(argc, argv);
  592. fprintf(stderr,"running tests from ctest_main completed\n");
  593. return num_fail;
  594. }