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_axpy.c 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*****************************************************************************
  2. Copyright (c) 2011-2014, 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 "common_utest.h"
  29. void test_daxpy_inc_0(void)
  30. {
  31. int i;
  32. int N=8,incX=0,incY=0;
  33. double a=0.25;
  34. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  35. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  36. double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  37. double y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  38. //OpenBLAS
  39. BLASFUNC(daxpy)(&N,&a,x1,&incX,y1,&incY);
  40. //reference
  41. BLASFUNC_REF(daxpy)(&N,&a,x2,&incX,y2,&incY);
  42. for(i=0; i<N; i++){
  43. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  44. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  45. }
  46. }
  47. void test_zaxpy_inc_0(void)
  48. {
  49. int i;
  50. int N=4,incX=0,incY=0;
  51. double a[2]={0.25,0.5};
  52. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  53. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  54. double x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  55. double y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  56. //OpenBLAS
  57. BLASFUNC(zaxpy)(&N,a,x1,&incX,y1,&incY);
  58. //reference
  59. BLASFUNC_REF(zaxpy)(&N,a,x2,&incX,y2,&incY);
  60. for(i=0; i<2*N; i++){
  61. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  62. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  63. }
  64. }
  65. void test_saxpy_inc_0(void)
  66. {
  67. int i;
  68. int N=8,incX=0,incY=0;
  69. float a=0.25;
  70. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  71. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  72. float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  73. float y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  74. //OpenBLAS
  75. BLASFUNC(saxpy)(&N,&a,x1,&incX,y1,&incY);
  76. //reference
  77. BLASFUNC_REF(saxpy)(&N,&a,x2,&incX,y2,&incY);
  78. for(i=0; i<N; i++){
  79. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  80. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  81. }
  82. }
  83. void test_caxpy_inc_0(void)
  84. {
  85. int i;
  86. int N=4,incX=0,incY=0;
  87. float a[2]={0.25,0.5};
  88. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  89. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  90. float x2[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  91. float y2[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  92. //OpenBLAS
  93. BLASFUNC(caxpy)(&N,a,x1,&incX,y1,&incY);
  94. //reference
  95. BLASFUNC_REF(caxpy)(&N,a,x2,&incX,y2,&incY);
  96. for(i=0; i<2*N; i++){
  97. CU_ASSERT_DOUBLE_EQUAL(x1[i], x2[i], CHECK_EPS);
  98. CU_ASSERT_DOUBLE_EQUAL(y1[i], y2[i], CHECK_EPS);
  99. }
  100. }