fn_powmat.hpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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_powmat
  16. //! @{
  17. template<typename T1>
  18. arma_warn_unused
  19. inline
  20. typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, const Op<T1,op_powmat> >::result
  21. powmat(const Base<typename T1::elem_type,T1>& X, const int y)
  22. {
  23. arma_extra_debug_sigprint();
  24. const uword aux_a = (y < int(0)) ? uword(-y) : uword(y);
  25. const uword aux_b = (y < int(0)) ? uword(1) : uword(0);
  26. return Op<T1,op_powmat>(X.get_ref(), aux_a, aux_b);
  27. }
  28. template<typename T1>
  29. arma_warn_unused
  30. inline
  31. typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, const mtOp<std::complex<typename T1::pod_type>,T1,op_powmat_cx> >::result
  32. powmat(const Base<typename T1::elem_type,T1>& X, const double y)
  33. {
  34. arma_extra_debug_sigprint();
  35. typedef std::complex<typename T1::pod_type> out_eT;
  36. return mtOp<out_eT,T1,op_powmat_cx>('j', X.get_ref(), out_eT(y));
  37. }
  38. template<typename T1>
  39. inline
  40. typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, bool >::result
  41. powmat
  42. (
  43. Mat<typename T1::elem_type>& out,
  44. const Base<typename T1::elem_type,T1>& X,
  45. const int y
  46. )
  47. {
  48. arma_extra_debug_sigprint();
  49. try
  50. {
  51. out = powmat(X,y);
  52. }
  53. catch(std::runtime_error&)
  54. {
  55. return false;
  56. }
  57. return true;
  58. }
  59. template<typename T1>
  60. inline
  61. typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, bool >::result
  62. powmat
  63. (
  64. Mat< std::complex<typename T1::pod_type> >& out,
  65. const Base<typename T1::elem_type,T1>& X,
  66. const double y
  67. )
  68. {
  69. arma_extra_debug_sigprint();
  70. try
  71. {
  72. out = powmat(X,y);
  73. }
  74. catch(std::runtime_error&)
  75. {
  76. return false;
  77. }
  78. return true;
  79. }
  80. //! @}