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 16 kB

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