newarp_DoubleShiftQR_bones.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. template<typename eT>
  18. class DoubleShiftQR
  19. {
  20. private:
  21. uword n; // Dimension of the matrix
  22. Mat<eT> mat_H; // A copy of the matrix to be factorised
  23. eT shift_s; // Shift constant
  24. eT shift_t; // Shift constant
  25. Mat<eT> ref_u; // Householder reflectors
  26. Col<unsigned short> ref_nr; // How many rows does each reflector affects
  27. // 3 - A general reflector
  28. // 2 - A Givens rotation
  29. // 1 - An identity transformation
  30. const eT prec; // Approximately zero
  31. const eT eps_rel;
  32. const eT eps_abs;
  33. bool computed; // Whether matrix has been factorised
  34. inline void compute_reflector(const eT& x1, const eT& x2, const eT& x3, uword ind);
  35. arma_inline void compute_reflector(const eT* x, uword ind);
  36. // Update the block X = H(il:iu, il:iu)
  37. inline void update_block(uword il, uword iu);
  38. // P = I - 2 * u * u' = P'
  39. // PX = X - 2 * u * (u'X)
  40. inline void apply_PX(Mat<eT>& X, uword oi, uword oj, uword nrow, uword ncol, uword u_ind);
  41. // x is a pointer to a vector
  42. // Px = x - 2 * dot(x, u) * u
  43. inline void apply_PX(eT* x, uword u_ind);
  44. // XP = X - 2 * (X * u) * u'
  45. inline void apply_XP(Mat<eT>& X, uword oi, uword oj, uword nrow, uword ncol, uword u_ind);
  46. public:
  47. inline DoubleShiftQR(uword size);
  48. inline DoubleShiftQR(const Mat<eT>& mat_obj, eT s, eT t);
  49. inline void compute(const Mat<eT>& mat_obj, eT s, eT t);
  50. inline Mat<eT> matrix_QtHQ();
  51. inline void apply_QtY(Col<eT>& y);
  52. inline void apply_YQ(Mat<eT>& Y);
  53. };
  54. } // namespace newarp