1 // SPDX-License-Identifier: Apache-2.0
2 //
3 // Copyright 2008-2016 Conrad Sanderson (http://conradsanderson.id.au)
4 // Copyright 2008-2016 National ICT Australia (NICTA)
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 // ------------------------------------------------------------------------
17
18
19 //! \addtogroup fn_powmat
20 //! @{
21
22
23 template<typename T1>
24 arma_warn_unused
25 inline
26 typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, const Op<T1,op_powmat> >::result
powmat(const Base<typename T1::elem_type,T1> & X,const int y)27 powmat(const Base<typename T1::elem_type,T1>& X, const int y)
28 {
29 arma_extra_debug_sigprint();
30
31 const uword aux_a = (y < int(0)) ? uword(-y) : uword(y);
32 const uword aux_b = (y < int(0)) ? uword(1) : uword(0);
33
34 return Op<T1,op_powmat>(X.get_ref(), aux_a, aux_b);
35 }
36
37
38
39 template<typename T1>
40 inline
41 typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, bool >::result
powmat(Mat<typename T1::elem_type> & out,const Base<typename T1::elem_type,T1> & X,const int y)42 powmat
43 (
44 Mat<typename T1::elem_type>& out,
45 const Base<typename T1::elem_type,T1>& X,
46 const int y
47 )
48 {
49 arma_extra_debug_sigprint();
50
51 const uword y_val = (y < int(0)) ? uword(-y) : uword(y);
52 const bool y_neg = (y < int(0));
53
54 const bool status = op_powmat::apply_direct(out, X.get_ref(), y_val, y_neg);
55
56 if(status == false)
57 {
58 out.soft_reset();
59 arma_debug_warn_level(3, "powmat(): transformation failed");
60 }
61
62 return status;
63 }
64
65
66
67 template<typename T1>
68 arma_warn_unused
69 inline
70 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
powmat(const Base<typename T1::elem_type,T1> & X,const double y)71 powmat(const Base<typename T1::elem_type,T1>& X, const double y)
72 {
73 arma_extra_debug_sigprint();
74
75 typedef std::complex<typename T1::pod_type> out_eT;
76
77 return mtOp<out_eT,T1,op_powmat_cx>('j', X.get_ref(), out_eT(y));
78 }
79
80
81
82 template<typename T1>
83 inline
84 typename enable_if2< is_supported_blas_type<typename T1::elem_type>::value, bool >::result
powmat(Mat<std::complex<typename T1::pod_type>> & out,const Base<typename T1::elem_type,T1> & X,const double y)85 powmat
86 (
87 Mat< std::complex<typename T1::pod_type> >& out,
88 const Base<typename T1::elem_type,T1>& X,
89 const double y
90 )
91 {
92 arma_extra_debug_sigprint();
93
94 typedef typename T1::pod_type T;
95
96 const bool status = op_powmat_cx::apply_direct(out, X.get_ref(), T(y));
97
98 if(status == false)
99 {
100 out.soft_reset();
101 arma_debug_warn_level(3, "powmat(): transformation failed");
102 }
103
104 return status;
105 }
106
107
108 //! @}
109