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_swap.c 3.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*****************************************************************************
  2. Copyright (c) 2011, Lab of Parallel Software and Computational Science,ICSAS
  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 ISCAS nor the names of its contributors may
  14. be used to endorse or promote products derived from this software
  15. without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. **********************************************************************************/
  27. #include "common_utest.h"
  28. void test_dswap_inc_0(void)
  29. {
  30. int i=0;
  31. int N=4,incX=0,incY=0;
  32. double x1[]={1.0,3.0,5.0,7.0};
  33. double y1[]={2.0,4.0,6.0,8.0};
  34. double x2[]={1.0,3.0,5.0,7.0};
  35. double y2[]={2.0,4.0,6.0,8.0};
  36. //OpenBLAS
  37. BLASFUNC(dswap)(&N,x1,&incX,y1,&incY);
  38. //reference
  39. BLASFUNC_REF(dswap)(&N,x2,&incX,y2,&incY);
  40. for(i=0; i<N; i++){
  41. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  42. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  43. }
  44. }
  45. void test_zswap_inc_0(void)
  46. {
  47. int i=0;
  48. int N=4,incX=0,incY=0;
  49. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  50. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  51. double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  52. double y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  53. //OpenBLAS
  54. BLASFUNC(zswap)(&N,x1,&incX,y1,&incY);
  55. //reference
  56. BLASFUNC_REF(zswap)(&N,x2,&incX,y2,&incY);
  57. for(i=0; i<2*N; i++){
  58. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  59. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  60. }
  61. }
  62. void test_sswap_inc_0(void)
  63. {
  64. int i=0;
  65. int N=4,incX=0,incY=0;
  66. float x1[]={1.0,3.0,5.0,7.0};
  67. float y1[]={2.0,4.0,6.0,8.0};
  68. float x2[]={1.0,3.0,5.0,7.0};
  69. float y2[]={2.0,4.0,6.0,8.0};
  70. //OpenBLAS
  71. BLASFUNC(sswap)(&N,x1,&incX,y1,&incY);
  72. //reference
  73. BLASFUNC_REF(sswap)(&N,x2,&incX,y2,&incY);
  74. for(i=0; i<N; i++){
  75. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  76. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  77. }
  78. }
  79. void test_cswap_inc_0(void)
  80. {
  81. int i=0;
  82. int N=4,incX=0,incY=0;
  83. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  84. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  85. float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  86. float y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  87. //OpenBLAS
  88. BLASFUNC(cswap)(&N,x1,&incX,y1,&incY);
  89. //reference
  90. BLASFUNC_REF(cswap)(&N,x2,&incX,y2,&incY);
  91. for(i=0; i<2*N; i++){
  92. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  93. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  94. }
  95. }