op_chol_meat.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. //! \addtogroup op_chol
  16. //! @{
  17. template<typename T1>
  18. inline
  19. void
  20. op_chol::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_chol>& X)
  21. {
  22. arma_extra_debug_sigprint();
  23. const bool status = op_chol::apply_direct(out, X.m, X.aux_uword_a);
  24. if(status == false)
  25. {
  26. out.soft_reset();
  27. arma_stop_runtime_error("chol(): decomposition failed");
  28. }
  29. }
  30. template<typename T1>
  31. inline
  32. bool
  33. op_chol::apply_direct(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type,T1>& A_expr, const uword layout)
  34. {
  35. arma_extra_debug_sigprint();
  36. typedef typename T1::elem_type eT;
  37. out = A_expr.get_ref();
  38. arma_debug_check( (out.is_square() == false), "chol(): given matrix must be square sized" );
  39. if(out.is_empty()) { return true; }
  40. // if(auxlib::rudimentary_sym_check(out) == false)
  41. // {
  42. // if(is_cx<eT>::no ) { arma_debug_warn("chol(): given matrix is not symmetric"); }
  43. // if(is_cx<eT>::yes) { arma_debug_warn("chol(): given matrix is not hermitian"); }
  44. // return false;
  45. // }
  46. if((arma_config::debug) && (auxlib::rudimentary_sym_check(out) == false))
  47. {
  48. if(is_cx<eT>::no ) { arma_debug_warn("chol(): given matrix is not symmetric"); }
  49. if(is_cx<eT>::yes) { arma_debug_warn("chol(): given matrix is not hermitian"); }
  50. }
  51. uword KD = 0;
  52. #if defined(ARMA_OPTIMISE_BAND)
  53. const bool is_band = (auxlib::crippled_lapack(out)) ? false : ((layout == 0) ? band_helper::is_band_upper(KD, out, uword(32)) : band_helper::is_band_lower(KD, out, uword(32)));
  54. #else
  55. const bool is_band = false;
  56. #endif
  57. const bool status = (is_band) ? auxlib::chol_band(out, KD, layout) : auxlib::chol(out, layout);
  58. return status;
  59. }
  60. //! @}