You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

270 lines
9.6 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2009-2010 Gael Guennebaud <gael.guennebaud@inria.fr>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include "common.h"
  10. /** ZHEMV performs the matrix-vector operation
  11. *
  12. * y := alpha*A*x + beta*y,
  13. *
  14. * where alpha and beta are scalars, x and y are n element vectors and
  15. * A is an n by n hermitian matrix.
  16. */
  17. int EIGEN_BLAS_FUNC(hemv)(char *uplo, int *n, RealScalar *palpha, RealScalar *pa, int *lda, RealScalar *px, int *incx, RealScalar *pbeta, RealScalar *py, int *incy)
  18. {
  19. Scalar* a = reinterpret_cast<Scalar*>(pa);
  20. Scalar* x = reinterpret_cast<Scalar*>(px);
  21. Scalar* y = reinterpret_cast<Scalar*>(py);
  22. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  23. Scalar beta = *reinterpret_cast<Scalar*>(pbeta);
  24. // check arguments
  25. int info = 0;
  26. if(UPLO(*uplo)==INVALID) info = 1;
  27. else if(*n<0) info = 2;
  28. else if(*lda<std::max(1,*n)) info = 5;
  29. else if(*incx==0) info = 7;
  30. else if(*incy==0) info = 10;
  31. if(info)
  32. return xerbla_(SCALAR_SUFFIX_UP"HEMV ",&info,6);
  33. if(*n==0)
  34. return 1;
  35. Scalar* actual_x = get_compact_vector(x,*n,*incx);
  36. Scalar* actual_y = get_compact_vector(y,*n,*incy);
  37. if(beta!=Scalar(1))
  38. {
  39. if(beta==Scalar(0)) vector(actual_y, *n).setZero();
  40. else vector(actual_y, *n) *= beta;
  41. }
  42. if(alpha!=Scalar(0))
  43. {
  44. // TODO performs a direct call to the underlying implementation function
  45. if(UPLO(*uplo)==UP) vector(actual_y,*n).noalias() += matrix(a,*n,*n,*lda).selfadjointView<Upper>() * (alpha * vector(actual_x,*n));
  46. else if(UPLO(*uplo)==LO) vector(actual_y,*n).noalias() += matrix(a,*n,*n,*lda).selfadjointView<Lower>() * (alpha * vector(actual_x,*n));
  47. }
  48. if(actual_x!=x) delete[] actual_x;
  49. if(actual_y!=y) delete[] copy_back(actual_y,y,*n,*incy);
  50. return 1;
  51. }
  52. /** ZHBMV performs the matrix-vector operation
  53. *
  54. * y := alpha*A*x + beta*y,
  55. *
  56. * where alpha and beta are scalars, x and y are n element vectors and
  57. * A is an n by n hermitian band matrix, with k super-diagonals.
  58. */
  59. // int EIGEN_BLAS_FUNC(hbmv)(char *uplo, int *n, int *k, RealScalar *alpha, RealScalar *a, int *lda,
  60. // RealScalar *x, int *incx, RealScalar *beta, RealScalar *y, int *incy)
  61. // {
  62. // return 1;
  63. // }
  64. /** ZHPMV performs the matrix-vector operation
  65. *
  66. * y := alpha*A*x + beta*y,
  67. *
  68. * where alpha and beta are scalars, x and y are n element vectors and
  69. * A is an n by n hermitian matrix, supplied in packed form.
  70. */
  71. // int EIGEN_BLAS_FUNC(hpmv)(char *uplo, int *n, RealScalar *alpha, RealScalar *ap, RealScalar *x, int *incx, RealScalar *beta, RealScalar *y, int *incy)
  72. // {
  73. // return 1;
  74. // }
  75. /** ZHPR performs the hermitian rank 1 operation
  76. *
  77. * A := alpha*x*conjg( x' ) + A,
  78. *
  79. * where alpha is a real scalar, x is an n element vector and A is an
  80. * n by n hermitian matrix, supplied in packed form.
  81. */
  82. // int EIGEN_BLAS_FUNC(hpr)(char *uplo, int *n, RealScalar *alpha, RealScalar *x, int *incx, RealScalar *ap)
  83. // {
  84. // return 1;
  85. // }
  86. /** ZHPR2 performs the hermitian rank 2 operation
  87. *
  88. * A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,
  89. *
  90. * where alpha is a scalar, x and y are n element vectors and A is an
  91. * n by n hermitian matrix, supplied in packed form.
  92. */
  93. // int EIGEN_BLAS_FUNC(hpr2)(char *uplo, int *n, RealScalar *palpha, RealScalar *x, int *incx, RealScalar *y, int *incy, RealScalar *ap)
  94. // {
  95. // return 1;
  96. // }
  97. /** ZHER performs the hermitian rank 1 operation
  98. *
  99. * A := alpha*x*conjg( x' ) + A,
  100. *
  101. * where alpha is a real scalar, x is an n element vector and A is an
  102. * n by n hermitian matrix.
  103. */
  104. int EIGEN_BLAS_FUNC(her)(char *uplo, int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *pa, int *lda)
  105. {
  106. Scalar* x = reinterpret_cast<Scalar*>(px);
  107. Scalar* a = reinterpret_cast<Scalar*>(pa);
  108. RealScalar alpha = *reinterpret_cast<RealScalar*>(palpha);
  109. int info = 0;
  110. if(UPLO(*uplo)==INVALID) info = 1;
  111. else if(*n<0) info = 2;
  112. else if(*incx==0) info = 5;
  113. else if(*lda<std::max(1,*n)) info = 7;
  114. if(info)
  115. return xerbla_(SCALAR_SUFFIX_UP"HER ",&info,6);
  116. if(alpha==RealScalar(0))
  117. return 1;
  118. Scalar* x_cpy = get_compact_vector(x, *n, *incx);
  119. // TODO perform direct calls to underlying implementation
  120. // if(UPLO(*uplo)==LO) matrix(a,*n,*n,*lda).selfadjointView<Lower>().rankUpdate(vector(x_cpy,*n), alpha);
  121. // else if(UPLO(*uplo)==UP) matrix(a,*n,*n,*lda).selfadjointView<Upper>().rankUpdate(vector(x_cpy,*n), alpha);
  122. if(UPLO(*uplo)==LO)
  123. for(int j=0;j<*n;++j)
  124. matrix(a,*n,*n,*lda).col(j).tail(*n-j) += alpha * internal::conj(x_cpy[j]) * vector(x_cpy+j,*n-j);
  125. else
  126. for(int j=0;j<*n;++j)
  127. matrix(a,*n,*n,*lda).col(j).head(j+1) += alpha * internal::conj(x_cpy[j]) * vector(x_cpy,j+1);
  128. matrix(a,*n,*n,*lda).diagonal().imag().setZero();
  129. if(x_cpy!=x) delete[] x_cpy;
  130. return 1;
  131. }
  132. /** ZHER2 performs the hermitian rank 2 operation
  133. *
  134. * A := alpha*x*conjg( y' ) + conjg( alpha )*y*conjg( x' ) + A,
  135. *
  136. * where alpha is a scalar, x and y are n element vectors and A is an n
  137. * by n hermitian matrix.
  138. */
  139. int EIGEN_BLAS_FUNC(her2)(char *uplo, int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pa, int *lda)
  140. {
  141. Scalar* x = reinterpret_cast<Scalar*>(px);
  142. Scalar* y = reinterpret_cast<Scalar*>(py);
  143. Scalar* a = reinterpret_cast<Scalar*>(pa);
  144. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  145. int info = 0;
  146. if(UPLO(*uplo)==INVALID) info = 1;
  147. else if(*n<0) info = 2;
  148. else if(*incx==0) info = 5;
  149. else if(*incy==0) info = 7;
  150. else if(*lda<std::max(1,*n)) info = 9;
  151. if(info)
  152. return xerbla_(SCALAR_SUFFIX_UP"HER2 ",&info,6);
  153. if(alpha==Scalar(0))
  154. return 1;
  155. Scalar* x_cpy = get_compact_vector(x, *n, *incx);
  156. Scalar* y_cpy = get_compact_vector(y, *n, *incy);
  157. // TODO perform direct calls to underlying implementation
  158. if(UPLO(*uplo)==LO) matrix(a,*n,*n,*lda).selfadjointView<Lower>().rankUpdate(vector(x_cpy,*n),vector(y_cpy,*n),alpha);
  159. else if(UPLO(*uplo)==UP) matrix(a,*n,*n,*lda).selfadjointView<Upper>().rankUpdate(vector(x_cpy,*n),vector(y_cpy,*n),alpha);
  160. matrix(a,*n,*n,*lda).diagonal().imag().setZero();
  161. if(x_cpy!=x) delete[] x_cpy;
  162. if(y_cpy!=y) delete[] y_cpy;
  163. return 1;
  164. }
  165. /** ZGERU performs the rank 1 operation
  166. *
  167. * A := alpha*x*y' + A,
  168. *
  169. * where alpha is a scalar, x is an m element vector, y is an n element
  170. * vector and A is an m by n matrix.
  171. */
  172. int EIGEN_BLAS_FUNC(geru)(int *m, int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pa, int *lda)
  173. {
  174. Scalar* x = reinterpret_cast<Scalar*>(px);
  175. Scalar* y = reinterpret_cast<Scalar*>(py);
  176. Scalar* a = reinterpret_cast<Scalar*>(pa);
  177. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  178. int info = 0;
  179. if(*m<0) info = 1;
  180. else if(*n<0) info = 2;
  181. else if(*incx==0) info = 5;
  182. else if(*incy==0) info = 7;
  183. else if(*lda<std::max(1,*m)) info = 9;
  184. if(info)
  185. return xerbla_(SCALAR_SUFFIX_UP"GERU ",&info,6);
  186. if(alpha==Scalar(0))
  187. return 1;
  188. Scalar* x_cpy = get_compact_vector(x,*m,*incx);
  189. Scalar* y_cpy = get_compact_vector(y,*n,*incy);
  190. // TODO perform direct calls to underlying implementation
  191. matrix(a,*m,*n,*lda) += alpha * vector(x_cpy,*m) * vector(y_cpy,*n).transpose();
  192. if(x_cpy!=x) delete[] x_cpy;
  193. if(y_cpy!=y) delete[] y_cpy;
  194. return 1;
  195. }
  196. /** ZGERC performs the rank 1 operation
  197. *
  198. * A := alpha*x*conjg( y' ) + A,
  199. *
  200. * where alpha is a scalar, x is an m element vector, y is an n element
  201. * vector and A is an m by n matrix.
  202. */
  203. int EIGEN_BLAS_FUNC(gerc)(int *m, int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pa, int *lda)
  204. {
  205. Scalar* x = reinterpret_cast<Scalar*>(px);
  206. Scalar* y = reinterpret_cast<Scalar*>(py);
  207. Scalar* a = reinterpret_cast<Scalar*>(pa);
  208. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  209. int info = 0;
  210. if(*m<0) info = 1;
  211. else if(*n<0) info = 2;
  212. else if(*incx==0) info = 5;
  213. else if(*incy==0) info = 7;
  214. else if(*lda<std::max(1,*m)) info = 9;
  215. if(info)
  216. return xerbla_(SCALAR_SUFFIX_UP"GERC ",&info,6);
  217. if(alpha==Scalar(0))
  218. return 1;
  219. Scalar* x_cpy = get_compact_vector(x,*m,*incx);
  220. Scalar* y_cpy = get_compact_vector(y,*n,*incy);
  221. // TODO perform direct calls to underlying implementation
  222. matrix(a,*m,*n,*lda) += alpha * vector(x_cpy,*m) * vector(y_cpy,*n).adjoint();
  223. if(x_cpy!=x) delete[] x_cpy;
  224. if(y_cpy!=y) delete[] y_cpy;
  225. return 1;
  226. }