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_rot.c 6.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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 "openblas_utest.h"
  29. #ifdef BUILD_DOUBLE
  30. CTEST(rot,drot_inc_0)
  31. {
  32. blasint i=0;
  33. blasint N=4,incX=0,incY=0;
  34. double c=0.25,s=0.5;
  35. double x1[]={1.0,3.0,5.0,7.0};
  36. double y1[]={2.0,4.0,6.0,8.0};
  37. double x2[]={-0.21484375000000,3.0,5.0,7.0};
  38. double y2[]={ 0.03906250000000,4.0,6.0,8.0};
  39. //OpenBLAS
  40. BLASFUNC(drot)(&N,x1,&incX,y1,&incY,&c,&s);
  41. for(i=0; i<N; i++){
  42. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  43. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  44. }
  45. }
  46. CTEST(rot,drot_inc_1)
  47. {
  48. blasint i=0;
  49. blasint N=4,incX=1,incY=1;
  50. double c=1.0,s=1.0;
  51. double x1[]={1.0,3.0,5.0,7.0};
  52. double y1[]={2.0,4.0,6.0,8.0};
  53. double x2[]={3.0,7.0,11.0,15.0};
  54. double y2[]={1.0,1.0,1.0,1.0};
  55. BLASFUNC(drot)(&N,x1,&incX,y1,&incY,&c,&s);
  56. for(i=0; i<N; i++){
  57. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  58. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  59. }
  60. }
  61. CTEST(rot,drotm_inc_1)
  62. {
  63. blasint i = 0;
  64. blasint N = 12, incX = 1, incY = 1;
  65. double param[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
  66. double x_actual[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
  67. double y_actual[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
  68. double x_referece[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0, 27.0, 30.0, 33.0, 36.0};
  69. double y_referece[] = {4.0, 8.0, 12.0, 16.0, 20.0, 24.0, 28.0, 32.0, 36.0, 40.0, 44.0, 48.0};
  70. //OpenBLAS
  71. BLASFUNC(drotm)(&N, x_actual, &incX, y_actual, &incY, param);
  72. for(i = 0; i < N; i++){
  73. ASSERT_DBL_NEAR_TOL(x_referece[i], x_actual[i], DOUBLE_EPS);
  74. ASSERT_DBL_NEAR_TOL(y_referece[i], y_actual[i], DOUBLE_EPS);
  75. }
  76. }
  77. #endif
  78. #ifdef BUILD_COMPLEX16
  79. CTEST(rot,zdrot_inc_0)
  80. {
  81. blasint i=0;
  82. blasint N=4,incX=0,incY=0;
  83. double c=0.25,s=0.5;
  84. double x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  85. double y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  86. double x2[]={-0.21484375000000,-0.45703125000000 ,5.0,7.0,1.0,3.0,5.0,7.0};
  87. double y2[]={ 0.03906250000000, 0.17187500000000 ,6.0,8.0,2.0,4.0,6.0,8.0};
  88. //OpenBLAS
  89. BLASFUNC(zdrot)(&N,x1,&incX,y1,&incY,&c,&s);
  90. for(i=0; i<2*N; i++){
  91. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], DOUBLE_EPS);
  92. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], DOUBLE_EPS);
  93. }
  94. }
  95. #endif
  96. #ifdef BUILD_SINGLE
  97. CTEST(rot,srot_inc_0)
  98. {
  99. blasint i=0;
  100. blasint N=4,incX=0,incY=0;
  101. float c=0.25,s=0.5;
  102. float x1[]={1.0,3.0,5.0,7.0};
  103. float y1[]={2.0,4.0,6.0,8.0};
  104. float x2[]={-0.21484375000000,3.0,5.0,7.0};
  105. float y2[]={ 0.03906250000000,4.0,6.0,8.0};
  106. //OpenBLAS
  107. BLASFUNC(srot)(&N,x1,&incX,y1,&incY,&c,&s);
  108. for(i=0; i<N; i++){
  109. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  110. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  111. }
  112. }
  113. CTEST(rot,srot_inc_1)
  114. {
  115. blasint i=0;
  116. blasint N=4,incX=1,incY=1;
  117. float c=1.0,s=1.0;
  118. float x1[]={1.0,3.0,5.0,7.0};
  119. float y1[]={2.0,4.0,6.0,8.0};
  120. float x2[]={3.0,7.0,11.0,15.0};
  121. float y2[]={1.0,1.0,1.0,1.0};
  122. BLASFUNC(srot)(&N,x1,&incX,y1,&incY,&c,&s);
  123. for(i=0; i<N; i++){
  124. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  125. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  126. }
  127. }
  128. CTEST(rot,srotm_inc_1)
  129. {
  130. blasint i = 0;
  131. blasint N = 12, incX = 1, incY = 1;
  132. float param[5] = {1.0, 2.0, 3.0, 4.0, 5.0};
  133. float x_actual[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
  134. float y_actual[] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0};
  135. float x_referece[] = {3.0, 6.0, 9.0, 12.0, 15.0, 18.0, 21.0, 24.0, 27.0, 30.0, 33.0, 36.0};
  136. float y_referece[] = {4.0, 8.0, 12.0, 16.0, 20.0, 24.0, 28.0, 32.0, 36.0, 40.0, 44.0, 48.0};
  137. //OpenBLAS
  138. BLASFUNC(srotm)(&N, x_actual, &incX, y_actual, &incY, param);
  139. for(i = 0; i < N; i++){
  140. ASSERT_DBL_NEAR_TOL(x_referece[i], x_actual[i], SINGLE_EPS);
  141. ASSERT_DBL_NEAR_TOL(y_referece[i], y_actual[i], SINGLE_EPS);
  142. }
  143. }
  144. #endif
  145. #ifdef BUILD_COMPLEX
  146. CTEST(rot, csrot_inc_0)
  147. {
  148. blasint i=0;
  149. blasint N=4,incX=0,incY=0;
  150. float c=0.25,s=0.5;
  151. float x1[]={1.0,3.0,5.0,7.0,1.0,3.0,5.0,7.0};
  152. float y1[]={2.0,4.0,6.0,8.0,2.0,4.0,6.0,8.0};
  153. float x2[]={-0.21484375000000,-0.45703125000000 ,5.0,7.0,1.0,3.0,5.0,7.0};
  154. float y2[]={ 0.03906250000000, 0.17187500000000 ,6.0,8.0,2.0,4.0,6.0,8.0};
  155. //OpenBLAS
  156. BLASFUNC(csrot)(&N,x1,&incX,y1,&incY,&c,&s);
  157. for(i=0; i<2*N; i++){
  158. ASSERT_DBL_NEAR_TOL(x2[i], x1[i], SINGLE_EPS);
  159. ASSERT_DBL_NEAR_TOL(y2[i], y1[i], SINGLE_EPS);
  160. }
  161. }
  162. #endif