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.

164 lines
4.3 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. int EIGEN_BLAS_FUNC(axpy)(int *n, RealScalar *palpha, RealScalar *px, int *incx, RealScalar *py, int *incy)
  11. {
  12. Scalar* x = reinterpret_cast<Scalar*>(px);
  13. Scalar* y = reinterpret_cast<Scalar*>(py);
  14. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  15. if(*n<=0) return 0;
  16. if(*incx==1 && *incy==1) vector(y,*n) += alpha * vector(x,*n);
  17. else if(*incx>0 && *incy>0) vector(y,*n,*incy) += alpha * vector(x,*n,*incx);
  18. else if(*incx>0 && *incy<0) vector(y,*n,-*incy).reverse() += alpha * vector(x,*n,*incx);
  19. else if(*incx<0 && *incy>0) vector(y,*n,*incy) += alpha * vector(x,*n,-*incx).reverse();
  20. else if(*incx<0 && *incy<0) vector(y,*n,-*incy).reverse() += alpha * vector(x,*n,-*incx).reverse();
  21. return 0;
  22. }
  23. int EIGEN_BLAS_FUNC(copy)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
  24. {
  25. if(*n<=0) return 0;
  26. Scalar* x = reinterpret_cast<Scalar*>(px);
  27. Scalar* y = reinterpret_cast<Scalar*>(py);
  28. // be carefull, *incx==0 is allowed !!
  29. if(*incx==1 && *incy==1)
  30. vector(y,*n) = vector(x,*n);
  31. else
  32. {
  33. if(*incx<0) x = x - (*n-1)*(*incx);
  34. if(*incy<0) y = y - (*n-1)*(*incy);
  35. for(int i=0;i<*n;++i)
  36. {
  37. *y = *x;
  38. x += *incx;
  39. y += *incy;
  40. }
  41. }
  42. return 0;
  43. }
  44. int EIGEN_CAT(EIGEN_CAT(i,SCALAR_SUFFIX),amax_)(int *n, RealScalar *px, int *incx)
  45. {
  46. if(*n<=0) return 0;
  47. Scalar* x = reinterpret_cast<Scalar*>(px);
  48. DenseIndex ret;
  49. if(*incx==1) vector(x,*n).cwiseAbs().maxCoeff(&ret);
  50. else vector(x,*n,std::abs(*incx)).cwiseAbs().maxCoeff(&ret);
  51. return ret+1;
  52. }
  53. int EIGEN_CAT(EIGEN_CAT(i,SCALAR_SUFFIX),amin_)(int *n, RealScalar *px, int *incx)
  54. {
  55. if(*n<=0) return 0;
  56. Scalar* x = reinterpret_cast<Scalar*>(px);
  57. DenseIndex ret;
  58. if(*incx==1) vector(x,*n).cwiseAbs().minCoeff(&ret);
  59. else vector(x,*n,std::abs(*incx)).cwiseAbs().minCoeff(&ret);
  60. return ret+1;
  61. }
  62. int EIGEN_BLAS_FUNC(rotg)(RealScalar *pa, RealScalar *pb, RealScalar *pc, RealScalar *ps)
  63. {
  64. Scalar& a = *reinterpret_cast<Scalar*>(pa);
  65. Scalar& b = *reinterpret_cast<Scalar*>(pb);
  66. RealScalar* c = pc;
  67. Scalar* s = reinterpret_cast<Scalar*>(ps);
  68. #if !ISCOMPLEX
  69. Scalar r,z;
  70. Scalar aa = internal::abs(a);
  71. Scalar ab = internal::abs(b);
  72. if((aa+ab)==Scalar(0))
  73. {
  74. *c = 1;
  75. *s = 0;
  76. r = 0;
  77. z = 0;
  78. }
  79. else
  80. {
  81. r = internal::sqrt(a*a + b*b);
  82. Scalar amax = aa>ab ? a : b;
  83. r = amax>0 ? r : -r;
  84. *c = a/r;
  85. *s = b/r;
  86. z = 1;
  87. if (aa > ab) z = *s;
  88. if (ab > aa && *c!=RealScalar(0))
  89. z = Scalar(1)/ *c;
  90. }
  91. *pa = r;
  92. *pb = z;
  93. #else
  94. Scalar alpha;
  95. RealScalar norm,scale;
  96. if(internal::abs(a)==RealScalar(0))
  97. {
  98. *c = RealScalar(0);
  99. *s = Scalar(1);
  100. a = b;
  101. }
  102. else
  103. {
  104. scale = internal::abs(a) + internal::abs(b);
  105. norm = scale*internal::sqrt((internal::abs2(a/scale))+ (internal::abs2(b/scale)));
  106. alpha = a/internal::abs(a);
  107. *c = internal::abs(a)/norm;
  108. *s = alpha*internal::conj(b)/norm;
  109. a = alpha*norm;
  110. }
  111. #endif
  112. // JacobiRotation<Scalar> r;
  113. // r.makeGivens(a,b);
  114. // *c = r.c();
  115. // *s = r.s();
  116. return 0;
  117. }
  118. int EIGEN_BLAS_FUNC(scal)(int *n, RealScalar *palpha, RealScalar *px, int *incx)
  119. {
  120. if(*n<=0) return 0;
  121. Scalar* x = reinterpret_cast<Scalar*>(px);
  122. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  123. if(*incx==1) vector(x,*n) *= alpha;
  124. else vector(x,*n,std::abs(*incx)) *= alpha;
  125. return 0;
  126. }
  127. int EIGEN_BLAS_FUNC(swap)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
  128. {
  129. if(*n<=0) return 0;
  130. Scalar* x = reinterpret_cast<Scalar*>(px);
  131. Scalar* y = reinterpret_cast<Scalar*>(py);
  132. if(*incx==1 && *incy==1) vector(y,*n).swap(vector(x,*n));
  133. else if(*incx>0 && *incy>0) vector(y,*n,*incy).swap(vector(x,*n,*incx));
  134. else if(*incx>0 && *incy<0) vector(y,*n,-*incy).reverse().swap(vector(x,*n,*incx));
  135. else if(*incx<0 && *incy>0) vector(y,*n,*incy).swap(vector(x,*n,-*incx).reverse());
  136. else if(*incx<0 && *incy<0) vector(y,*n,-*incy).reverse().swap(vector(x,*n,-*incx).reverse());
  137. return 1;
  138. }