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.

79 lines
3.1 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 STORMEIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H
  10. #define STORMEIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H
  11. namespace internal {
  12. template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs, int StorageOrder>
  13. struct packed_triangular_matrix_vector_product;
  14. template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs>
  15. struct packed_triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,ColMajor>
  16. {
  17. typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType ResScalar;
  18. enum {
  19. IsLower = (Mode & Lower) ==Lower,
  20. HasUnitDiag = (Mode & UnitDiag)==UnitDiag,
  21. HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag
  22. };
  23. static void run(Index size, const LhsScalar* lhs, const RhsScalar* rhs, ResScalar* res, ResScalar alpha)
  24. {
  25. internal::conj_if<ConjRhs> cj;
  26. typedef Map<const Matrix<LhsScalar,Dynamic,1> > LhsMap;
  27. typedef typename conj_expr_if<ConjLhs,LhsMap>::type ConjLhsType;
  28. typedef Map<Matrix<ResScalar,Dynamic,1> > ResMap;
  29. for (Index i=0; i<size; ++i)
  30. {
  31. Index s = IsLower&&(HasUnitDiag||HasZeroDiag) ? 1 : 0;
  32. Index r = IsLower ? size-i: i+1;
  33. if (STORMEIGEN_IMPLIES(HasUnitDiag||HasZeroDiag, (--r)>0))
  34. ResMap(res+(IsLower ? s+i : 0),r) += alpha * cj(rhs[i]) * ConjLhsType(LhsMap(lhs+s,r));
  35. if (HasUnitDiag)
  36. res[i] += alpha * cj(rhs[i]);
  37. lhs += IsLower ? size-i: i+1;
  38. }
  39. };
  40. };
  41. template<typename Index, int Mode, typename LhsScalar, bool ConjLhs, typename RhsScalar, bool ConjRhs>
  42. struct packed_triangular_matrix_vector_product<Index,Mode,LhsScalar,ConjLhs,RhsScalar,ConjRhs,RowMajor>
  43. {
  44. typedef typename scalar_product_traits<LhsScalar, RhsScalar>::ReturnType ResScalar;
  45. enum {
  46. IsLower = (Mode & Lower) ==Lower,
  47. HasUnitDiag = (Mode & UnitDiag)==UnitDiag,
  48. HasZeroDiag = (Mode & ZeroDiag)==ZeroDiag
  49. };
  50. static void run(Index size, const LhsScalar* lhs, const RhsScalar* rhs, ResScalar* res, ResScalar alpha)
  51. {
  52. internal::conj_if<ConjRhs> cj;
  53. typedef Map<const Matrix<LhsScalar,Dynamic,1> > LhsMap;
  54. typedef typename conj_expr_if<ConjLhs,LhsMap>::type ConjLhsType;
  55. typedef Map<const Matrix<RhsScalar,Dynamic,1> > RhsMap;
  56. typedef typename conj_expr_if<ConjRhs,RhsMap>::type ConjRhsType;
  57. for (Index i=0; i<size; ++i)
  58. {
  59. Index s = !IsLower&&(HasUnitDiag||HasZeroDiag) ? 1 : 0;
  60. Index r = IsLower ? i+1 : size-i;
  61. if (STORMEIGEN_IMPLIES(HasUnitDiag||HasZeroDiag, (--r)>0))
  62. res[i] += alpha * (ConjLhsType(LhsMap(lhs+s,r)).cwiseProduct(ConjRhsType(RhsMap(rhs+(IsLower ? 0 : s+i),r)))).sum();
  63. if (HasUnitDiag)
  64. res[i] += alpha * cj(rhs[i]);
  65. lhs += IsLower ? i+1 : size-i;
  66. }
  67. };
  68. };
  69. } // end namespace internal
  70. #endif // STORMEIGEN_PACKED_TRIANGULAR_MATRIX_VECTOR_H