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.

cblas_zgemv.c 4.0 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * cblas_zgemv.c
  3. * The program is a C interface of zgemv
  4. *
  5. * Keita Teranishi 5/20/98
  6. *
  7. */
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include "cblas.h"
  11. #include "cblas_f77.h"
  12. void cblas_zgemv(const CBLAS_LAYOUT layout,
  13. const CBLAS_TRANSPOSE TransA, const int M, const int N,
  14. const void *alpha, const void *A, const int lda,
  15. const void *X, const int incX, const void *beta,
  16. void *Y, const int incY)
  17. {
  18. char TA;
  19. #ifdef F77_CHAR
  20. F77_CHAR F77_TA;
  21. #else
  22. #define F77_TA &TA
  23. #endif
  24. #ifdef F77_INT
  25. F77_INT F77_M=M, F77_N=N, F77_lda=lda, F77_incX=incX, F77_incY=incY;
  26. #else
  27. #define F77_M M
  28. #define F77_N N
  29. #define F77_lda lda
  30. #define F77_incX incx
  31. #define F77_incY incY
  32. #endif
  33. int n, i=0, incx=incX;
  34. const double *xx= (double *)X, *alp= (double *)alpha, *bet = (double *)beta;
  35. double ALPHA[2],BETA[2];
  36. int tincY, tincx;
  37. double *x=(double *)X, *y=(double *)Y, *st=0, *tx;
  38. extern int CBLAS_CallFromC;
  39. extern int RowMajorStrg;
  40. RowMajorStrg = 0;
  41. CBLAS_CallFromC = 1;
  42. if (layout == CblasColMajor)
  43. {
  44. if (TransA == CblasNoTrans) TA = 'N';
  45. else if (TransA == CblasTrans) TA = 'T';
  46. else if (TransA == CblasConjTrans) TA = 'C';
  47. else
  48. {
  49. cblas_xerbla(2, "cblas_zgemv","Illegal TransA setting, %d\n", TransA);
  50. CBLAS_CallFromC = 0;
  51. RowMajorStrg = 0;
  52. return;
  53. }
  54. #ifdef F77_CHAR
  55. F77_TA = C2F_CHAR(&TA);
  56. #endif
  57. F77_zgemv(F77_TA, &F77_M, &F77_N, alpha, A, &F77_lda, X, &F77_incX,
  58. beta, Y, &F77_incY);
  59. }
  60. else if (layout == CblasRowMajor)
  61. {
  62. RowMajorStrg = 1;
  63. if (TransA == CblasNoTrans) TA = 'T';
  64. else if (TransA == CblasTrans) TA = 'N';
  65. else if (TransA == CblasConjTrans)
  66. {
  67. ALPHA[0]= *alp;
  68. ALPHA[1]= -alp[1];
  69. BETA[0]= *bet;
  70. BETA[1]= -bet[1];
  71. TA = 'N';
  72. if (M > 0)
  73. {
  74. n = M << 1;
  75. x = malloc(n*sizeof(double));
  76. tx = x;
  77. if( incX > 0 ) {
  78. i = incX << 1 ;
  79. tincx = 2;
  80. st= x+n;
  81. } else {
  82. i = incX *(-2);
  83. tincx = -2;
  84. st = x-2;
  85. x +=(n-2);
  86. }
  87. do
  88. {
  89. *x = *xx;
  90. x[1] = -xx[1];
  91. x += tincx ;
  92. xx += i;
  93. }
  94. while (x != st);
  95. x=tx;
  96. #ifdef F77_INT
  97. F77_incX = 1;
  98. #else
  99. incx = 1;
  100. #endif
  101. if(incY > 0)
  102. tincY = incY;
  103. else
  104. tincY = -incY;
  105. y++;
  106. if (N > 0)
  107. {
  108. i = tincY << 1;
  109. n = i * N ;
  110. st = y + n;
  111. do {
  112. *y = -(*y);
  113. y += i;
  114. } while(y != st);
  115. y -= n;
  116. }
  117. }
  118. else x = (double *) X;
  119. }
  120. else
  121. {
  122. cblas_xerbla(2, "cblas_zgemv","Illegal TransA setting, %d\n", TransA);
  123. CBLAS_CallFromC = 0;
  124. RowMajorStrg = 0;
  125. return;
  126. }
  127. #ifdef F77_CHAR
  128. F77_TA = C2F_CHAR(&TA);
  129. #endif
  130. if (TransA == CblasConjTrans)
  131. F77_zgemv(F77_TA, &F77_N, &F77_M, ALPHA, A, &F77_lda, x,
  132. &F77_incX, BETA, Y, &F77_incY);
  133. else
  134. F77_zgemv(F77_TA, &F77_N, &F77_M, alpha, A, &F77_lda, x,
  135. &F77_incX, beta, Y, &F77_incY);
  136. if (TransA == CblasConjTrans)
  137. {
  138. if (x != (double *)X) free(x);
  139. if (N > 0)
  140. {
  141. do
  142. {
  143. *y = -(*y);
  144. y += i;
  145. }
  146. while (y != st);
  147. }
  148. }
  149. }
  150. else cblas_xerbla(1, "cblas_zgemv", "Illegal layout setting, %d\n", layout);
  151. CBLAS_CallFromC = 0;
  152. RowMajorStrg = 0;
  153. return;
  154. }