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.

166 lines
4.4 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) make_vector(y,*n) += alpha * make_vector(x,*n);
  17. else if(*incx>0 && *incy>0) make_vector(y,*n,*incy) += alpha * make_vector(x,*n,*incx);
  18. else if(*incx>0 && *incy<0) make_vector(y,*n,-*incy).reverse() += alpha * make_vector(x,*n,*incx);
  19. else if(*incx<0 && *incy>0) make_vector(y,*n,*incy) += alpha * make_vector(x,*n,-*incx).reverse();
  20. else if(*incx<0 && *incy<0) make_vector(y,*n,-*incy).reverse() += alpha * make_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. make_vector(y,*n) = make_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) make_vector(x,*n).cwiseAbs().maxCoeff(&ret);
  50. else make_vector(x,*n,std::abs(*incx)).cwiseAbs().maxCoeff(&ret);
  51. return int(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) make_vector(x,*n).cwiseAbs().minCoeff(&ret);
  59. else make_vector(x,*n,std::abs(*incx)).cwiseAbs().minCoeff(&ret);
  60. return int(ret)+1;
  61. }
  62. int EIGEN_BLAS_FUNC(rotg)(RealScalar *pa, RealScalar *pb, RealScalar *pc, RealScalar *ps)
  63. {
  64. using std::sqrt;
  65. using std::abs;
  66. Scalar& a = *reinterpret_cast<Scalar*>(pa);
  67. Scalar& b = *reinterpret_cast<Scalar*>(pb);
  68. RealScalar* c = pc;
  69. Scalar* s = reinterpret_cast<Scalar*>(ps);
  70. #if !ISCOMPLEX
  71. Scalar r,z;
  72. Scalar aa = abs(a);
  73. Scalar ab = abs(b);
  74. if((aa+ab)==Scalar(0))
  75. {
  76. *c = 1;
  77. *s = 0;
  78. r = 0;
  79. z = 0;
  80. }
  81. else
  82. {
  83. r = sqrt(a*a + b*b);
  84. Scalar amax = aa>ab ? a : b;
  85. r = amax>0 ? r : -r;
  86. *c = a/r;
  87. *s = b/r;
  88. z = 1;
  89. if (aa > ab) z = *s;
  90. if (ab > aa && *c!=RealScalar(0))
  91. z = Scalar(1)/ *c;
  92. }
  93. *pa = r;
  94. *pb = z;
  95. #else
  96. Scalar alpha;
  97. RealScalar norm,scale;
  98. if(abs(a)==RealScalar(0))
  99. {
  100. *c = RealScalar(0);
  101. *s = Scalar(1);
  102. a = b;
  103. }
  104. else
  105. {
  106. scale = abs(a) + abs(b);
  107. norm = scale*sqrt((numext::abs2(a/scale)) + (numext::abs2(b/scale)));
  108. alpha = a/abs(a);
  109. *c = abs(a)/norm;
  110. *s = alpha*numext::conj(b)/norm;
  111. a = alpha*norm;
  112. }
  113. #endif
  114. // JacobiRotation<Scalar> r;
  115. // r.makeGivens(a,b);
  116. // *c = r.c();
  117. // *s = r.s();
  118. return 0;
  119. }
  120. int EIGEN_BLAS_FUNC(scal)(int *n, RealScalar *palpha, RealScalar *px, int *incx)
  121. {
  122. if(*n<=0) return 0;
  123. Scalar* x = reinterpret_cast<Scalar*>(px);
  124. Scalar alpha = *reinterpret_cast<Scalar*>(palpha);
  125. if(*incx==1) make_vector(x,*n) *= alpha;
  126. else make_vector(x,*n,std::abs(*incx)) *= alpha;
  127. return 0;
  128. }
  129. int EIGEN_BLAS_FUNC(swap)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
  130. {
  131. if(*n<=0) return 0;
  132. Scalar* x = reinterpret_cast<Scalar*>(px);
  133. Scalar* y = reinterpret_cast<Scalar*>(py);
  134. if(*incx==1 && *incy==1) make_vector(y,*n).swap(make_vector(x,*n));
  135. else if(*incx>0 && *incy>0) make_vector(y,*n,*incy).swap(make_vector(x,*n,*incx));
  136. else if(*incx>0 && *incy<0) make_vector(y,*n,-*incy).reverse().swap(make_vector(x,*n,*incx));
  137. else if(*incx<0 && *incy>0) make_vector(y,*n,*incy).swap(make_vector(x,*n,-*incx).reverse());
  138. else if(*incx<0 && *incy<0) make_vector(y,*n,-*incy).reverse().swap(make_vector(x,*n,-*incx).reverse());
  139. return 1;
  140. }