newarp_UpperHessenbergQR_bones.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
  2. // Copyright 2008-2016 National ICT Australia (NICTA)
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. // ------------------------------------------------------------------------
  15. namespace newarp
  16. {
  17. //! Perform the QR decomposition of an upper Hessenberg matrix.
  18. template<typename eT>
  19. class UpperHessenbergQR
  20. {
  21. protected:
  22. uword n;
  23. Mat<eT> mat_T;
  24. // Gi = [ cos[i] sin[i]]
  25. // [-sin[i] cos[i]]
  26. // Q = G1 * G2 * ... * G_{n-1}
  27. Col<eT> rot_cos;
  28. Col<eT> rot_sin;
  29. bool computed;
  30. public:
  31. //! Default constructor. Computation can
  32. //! be performed later by calling the compute() method.
  33. inline UpperHessenbergQR();
  34. //! Constructor to create an object that performs and stores the
  35. //! QR decomposition of an upper Hessenberg matrix `mat_obj`.
  36. inline UpperHessenbergQR(const Mat<eT>& mat_obj);
  37. //! Conduct the QR factorisation of an upper Hessenberg matrix.
  38. virtual void compute(const Mat<eT>& mat_obj);
  39. //! Return the \f$RQ\f$ matrix, the multiplication of \f$R\f$ and \f$Q\f$,
  40. //! which is an upper Hessenberg matrix.
  41. virtual Mat<eT> matrix_RQ();
  42. //! Apply the \f$Q\f$ matrix to another matrix \f$Y\f$.
  43. inline void apply_YQ(Mat<eT>& Y);
  44. };
  45. //! Perform the QR decomposition of a tridiagonal matrix, a special
  46. //! case of upper Hessenberg matrices.
  47. template<typename eT>
  48. class TridiagQR : public UpperHessenbergQR<eT>
  49. {
  50. public:
  51. //! Default constructor. Computation can
  52. //! be performed later by calling the compute() method.
  53. inline TridiagQR();
  54. //! Constructor to create an object that performs and stores the
  55. //! QR decomposition of a tridiagonal matrix `mat_obj`.
  56. inline TridiagQR(const Mat<eT>& mat_obj);
  57. //! Conduct the QR factorisation of a tridiagonal matrix.
  58. inline void compute(const Mat<eT>& mat_obj);
  59. //! Return the \f$RQ\f$ matrix, the multiplication of \f$R\f$ and \f$Q\f$,
  60. //! which is a tridiagonal matrix.
  61. inline Mat<eT> matrix_RQ();
  62. };
  63. } // namespace newarp