fn_lu.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 fn_lu
  16. //! @{
  17. //! immediate lower upper decomposition, permutation info is embedded into L (similar to Matlab/Octave)
  18. template<typename T1>
  19. inline
  20. bool
  21. lu
  22. (
  23. Mat<typename T1::elem_type>& L,
  24. Mat<typename T1::elem_type>& U,
  25. const Base<typename T1::elem_type,T1>& X,
  26. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  27. )
  28. {
  29. arma_extra_debug_sigprint();
  30. arma_ignore(junk);
  31. arma_debug_check( (&L == &U), "lu(): L and U are the same object");
  32. const bool status = auxlib::lu(L, U, X);
  33. if(status == false)
  34. {
  35. L.soft_reset();
  36. U.soft_reset();
  37. arma_debug_warn("lu(): decomposition failed");
  38. }
  39. return status;
  40. }
  41. //! immediate lower upper decomposition, also providing the permutation matrix
  42. template<typename T1>
  43. inline
  44. bool
  45. lu
  46. (
  47. Mat<typename T1::elem_type>& L,
  48. Mat<typename T1::elem_type>& U,
  49. Mat<typename T1::elem_type>& P,
  50. const Base<typename T1::elem_type,T1>& X,
  51. const typename arma_blas_type_only<typename T1::elem_type>::result* junk = 0
  52. )
  53. {
  54. arma_extra_debug_sigprint();
  55. arma_ignore(junk);
  56. arma_debug_check( ( (&L == &U) || (&L == &P) || (&U == &P) ), "lu(): two or more output objects are the same object");
  57. const bool status = auxlib::lu(L, U, P, X);
  58. if(status == false)
  59. {
  60. L.soft_reset();
  61. U.soft_reset();
  62. P.soft_reset();
  63. arma_debug_warn("lu(): decomposition failed");
  64. }
  65. return status;
  66. }
  67. //! @}