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.

57 lines
2.0 KiB

  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2012 Chen-Pang He <jdh8@ms63.hinet.net>
  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. #ifndef EIGEN_RANK2UPDATE_H
  10. #define EIGEN_RANK2UPDATE_H
  11. namespace internal {
  12. /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu'
  13. * This is the low-level version of SelfadjointRank2Update.h
  14. */
  15. template<typename Scalar, typename Index, int UpLo>
  16. struct rank2_update_selector
  17. {
  18. static void run(Index size, Scalar* mat, Index stride, const Scalar* u, const Scalar* v, Scalar alpha)
  19. {
  20. typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
  21. for (Index i=0; i<size; ++i)
  22. {
  23. Map<Matrix<Scalar,Dynamic,1> >(mat+stride*i+(UpLo==Lower ? i : 0), UpLo==Lower ? size-i : (i+1)) +=
  24. conj(alpha) * conj(u[i]) * OtherMap(v+(UpLo==Lower ? i : 0), UpLo==Lower ? size-i : (i+1))
  25. + alpha * conj(v[i]) * OtherMap(u+(UpLo==Lower ? i : 0), UpLo==Lower ? size-i : (i+1));
  26. }
  27. }
  28. };
  29. /* Optimized selfadjoint matrix += alpha * uv' + conj(alpha)*vu'
  30. * The matrix is in packed form.
  31. */
  32. template<typename Scalar, typename Index, int UpLo>
  33. struct packed_rank2_update_selector
  34. {
  35. static void run(Index size, Scalar* mat, const Scalar* u, const Scalar* v, Scalar alpha)
  36. {
  37. typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
  38. Index offset = 0;
  39. for (Index i=0; i<size; ++i)
  40. {
  41. Map<Matrix<Scalar,Dynamic,1> >(mat+offset, UpLo==Lower ? size-i : (i+1)) +=
  42. conj(alpha) * conj(u[i]) * OtherMap(v+(UpLo==Lower ? i : 0), UpLo==Lower ? size-i : (i+1))
  43. + alpha * conj(v[i]) * OtherMap(u+(UpLo==Lower ? i : 0), UpLo==Lower ? size-i : (i+1));
  44. //FIXME This should be handled outside.
  45. mat[offset+(UpLo==Lower ? 0 : i)] = real(mat[offset+(UpLo==Lower ? 0 : i)]);
  46. offset += UpLo==Lower ? size-i : (i+1);
  47. }
  48. }
  49. };
  50. } // end namespace internal
  51. #endif // EIGEN_RANK2UPDATE_H