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.

100 lines
3.5 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. // computes the sum of magnitudes of all vector elements or, for a complex vector x, the sum
  11. // res = |Rex1| + |Imx1| + |Rex2| + |Imx2| + ... + |Rexn| + |Imxn|, where x is a vector of order n
  12. RealScalar EIGEN_BLAS_FUNC(asum)(int *n, RealScalar *px, int *incx)
  13. {
  14. // std::cerr << "_asum " << *n << " " << *incx << "\n";
  15. Scalar* x = reinterpret_cast<Scalar*>(px);
  16. if(*n<=0) return 0;
  17. if(*incx==1) return vector(x,*n).cwiseAbs().sum();
  18. else return vector(x,*n,std::abs(*incx)).cwiseAbs().sum();
  19. }
  20. // computes a vector-vector dot product.
  21. Scalar EIGEN_BLAS_FUNC(dot)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy)
  22. {
  23. // std::cerr << "_dot " << *n << " " << *incx << " " << *incy << "\n";
  24. if(*n<=0) return 0;
  25. Scalar* x = reinterpret_cast<Scalar*>(px);
  26. Scalar* y = reinterpret_cast<Scalar*>(py);
  27. if(*incx==1 && *incy==1) return (vector(x,*n).cwiseProduct(vector(y,*n))).sum();
  28. else if(*incx>0 && *incy>0) return (vector(x,*n,*incx).cwiseProduct(vector(y,*n,*incy))).sum();
  29. else if(*incx<0 && *incy>0) return (vector(x,*n,-*incx).reverse().cwiseProduct(vector(y,*n,*incy))).sum();
  30. else if(*incx>0 && *incy<0) return (vector(x,*n,*incx).cwiseProduct(vector(y,*n,-*incy).reverse())).sum();
  31. else if(*incx<0 && *incy<0) return (vector(x,*n,-*incx).reverse().cwiseProduct(vector(y,*n,-*incy).reverse())).sum();
  32. else return 0;
  33. }
  34. // computes the Euclidean norm of a vector.
  35. // FIXME
  36. Scalar EIGEN_BLAS_FUNC(nrm2)(int *n, RealScalar *px, int *incx)
  37. {
  38. // std::cerr << "_nrm2 " << *n << " " << *incx << "\n";
  39. if(*n<=0) return 0;
  40. Scalar* x = reinterpret_cast<Scalar*>(px);
  41. if(*incx==1) return vector(x,*n).stableNorm();
  42. else return vector(x,*n,std::abs(*incx)).stableNorm();
  43. }
  44. int EIGEN_BLAS_FUNC(rot)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *pc, RealScalar *ps)
  45. {
  46. // std::cerr << "_rot " << *n << " " << *incx << " " << *incy << "\n";
  47. if(*n<=0) return 0;
  48. Scalar* x = reinterpret_cast<Scalar*>(px);
  49. Scalar* y = reinterpret_cast<Scalar*>(py);
  50. Scalar c = *reinterpret_cast<Scalar*>(pc);
  51. Scalar s = *reinterpret_cast<Scalar*>(ps);
  52. StridedVectorType vx(vector(x,*n,std::abs(*incx)));
  53. StridedVectorType vy(vector(y,*n,std::abs(*incy)));
  54. Reverse<StridedVectorType> rvx(vx);
  55. Reverse<StridedVectorType> rvy(vy);
  56. if(*incx<0 && *incy>0) internal::apply_rotation_in_the_plane(rvx, vy, JacobiRotation<Scalar>(c,s));
  57. else if(*incx>0 && *incy<0) internal::apply_rotation_in_the_plane(vx, rvy, JacobiRotation<Scalar>(c,s));
  58. else internal::apply_rotation_in_the_plane(vx, vy, JacobiRotation<Scalar>(c,s));
  59. return 0;
  60. }
  61. /*
  62. // performs rotation of points in the modified plane.
  63. int EIGEN_BLAS_FUNC(rotm)(int *n, RealScalar *px, int *incx, RealScalar *py, int *incy, RealScalar *param)
  64. {
  65. Scalar* x = reinterpret_cast<Scalar*>(px);
  66. Scalar* y = reinterpret_cast<Scalar*>(py);
  67. // TODO
  68. return 0;
  69. }
  70. // computes the modified parameters for a Givens rotation.
  71. int EIGEN_BLAS_FUNC(rotmg)(RealScalar *d1, RealScalar *d2, RealScalar *x1, RealScalar *x2, RealScalar *param)
  72. {
  73. // TODO
  74. return 0;
  75. }
  76. */