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.

54 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_SELFADJOINT_PACKED_PRODUCT_H
  10. #define EIGEN_SELFADJOINT_PACKED_PRODUCT_H
  11. namespace internal {
  12. /* Optimized matrix += alpha * uv'
  13. * The matrix is in packed form.
  14. */
  15. template<typename Scalar, typename Index, int StorageOrder, int UpLo, bool ConjLhs, bool ConjRhs>
  16. struct selfadjoint_packed_rank1_update;
  17. template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
  18. struct selfadjoint_packed_rank1_update<Scalar,Index,ColMajor,UpLo,ConjLhs,ConjRhs>
  19. {
  20. typedef typename NumTraits<Scalar>::Real RealScalar;
  21. static void run(Index size, Scalar* mat, const Scalar* vec, RealScalar alpha)
  22. {
  23. typedef Map<const Matrix<Scalar,Dynamic,1> > OtherMap;
  24. typedef typename conj_expr_if<ConjLhs,OtherMap>::type ConjRhsType;
  25. conj_if<ConjRhs> cj;
  26. for (Index i=0; i<size; ++i)
  27. {
  28. Map<Matrix<Scalar,Dynamic,1> >(mat, UpLo==Lower ? size-i : (i+1))
  29. += alpha * cj(vec[i]) * ConjRhsType(OtherMap(vec+(UpLo==Lower ? i : 0), UpLo==Lower ? size-i : (i+1)));
  30. //FIXME This should be handled outside.
  31. mat[UpLo==Lower ? 0 : i] = real(mat[UpLo==Lower ? 0 : i]);
  32. mat += UpLo==Lower ? size-i : (i+1);
  33. }
  34. }
  35. };
  36. template<typename Scalar, typename Index, int UpLo, bool ConjLhs, bool ConjRhs>
  37. struct selfadjoint_packed_rank1_update<Scalar,Index,RowMajor,UpLo,ConjLhs,ConjRhs>
  38. {
  39. typedef typename NumTraits<Scalar>::Real RealScalar;
  40. static void run(Index size, Scalar* mat, const Scalar* vec, RealScalar alpha)
  41. {
  42. selfadjoint_packed_rank1_update<Scalar,Index,ColMajor,UpLo==Lower?Upper:Lower,ConjRhs,ConjLhs>::run(size,mat,vec,alpha);
  43. }
  44. };
  45. } // end namespace internal
  46. #endif // EIGEN_SELFADJOINT_PACKED_PRODUCT_H