Functions | |
template<typename T1 > | |
T1::elem_type | trace (const Base< typename T1::elem_type, T1 > &X) |
Immediate trace (sum of diagonal elements) of a square dense matrix. | |
template<typename T1 , typename T2 > | |
T1::elem_type | trace (const Glue< T1, T2, glue_plus > &X) |
Immediate trace (sum of diagonal elements) of A + B. A and B must be square and have the same dimensions. | |
template<typename T1 , typename T2 > | |
T1::elem_type | trace (const Glue< T1, T2, glue_minus > &X) |
Immediate trace (sum of diagonal elements) of A - B. A and B must be square and have the same dimensions. | |
template<typename T1 , typename T2 > | |
T1::elem_type | trace (const Glue< T1, T2, glue_schur > &X) |
Immediate trace (sum of diagonal elements) of A % B (where % is the element-wise multiplication operator). A and B must be square and have the same dimensions. | |
template<typename T1 > | |
T1::elem_type | trace (const Op< T1, op_scalar_times > &in) |
trace (sum of diagonal elements) of k * T1, where k is a scalar and T1 is converted to a dense matrix. | |
template<typename eT > | |
eT | trace (const Op< Mat< eT >, op_diagmat > &X) |
trace (sum of diagonal elements) of a diagonal matrix | |
template<typename eT > | |
eT | trace (const Op< Mat< eT >, op_diagmat_vec > &X) |
T1::elem_type trace | ( | const Base< typename T1::elem_type, T1 > & | X | ) | [inline] |
Immediate trace (sum of diagonal elements) of a square dense matrix.
Definition at line 24 of file fn_trace.hpp.
References Base< elem_type, derived >::get_ref().
Referenced by trace().
00025 { 00026 arma_extra_debug_sigprint(); 00027 00028 typedef typename T1::elem_type eT; 00029 00030 const unwrap<T1> A_tmp(X.get_ref()); 00031 const Mat<eT>& A = A_tmp.M; 00032 00033 arma_debug_check( !A.is_square(), "trace(): matrix must be square" ); 00034 00035 eT val = eT(0); 00036 00037 for(u32 i=0; i<A.n_rows; ++i) 00038 { 00039 val += A.at(i,i); 00040 } 00041 00042 return val; 00043 }
T1::elem_type trace | ( | const Glue< T1, T2, glue_plus > & | X | ) | [inline] |
Immediate trace (sum of diagonal elements) of A + B. A and B must be square and have the same dimensions.
Definition at line 53 of file fn_trace.hpp.
References Glue< T1, T2, glue_type >::A, Glue< T1, T2, glue_type >::B, isnt_same_type< T1, T2 >::check(), Mat< eT >::is_square(), Mat< eT >::n_cols, Mat< eT >::n_rows, and trace().
00054 { 00055 arma_extra_debug_sigprint(); 00056 00057 isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check(); 00058 00059 const unwrap<T1> tmp1(X.A); 00060 const unwrap<T2> tmp2(X.B); 00061 00062 typedef typename T1::elem_type eT; 00063 00064 const Mat<eT>& A = tmp1.M; 00065 const Mat<eT>& B = tmp2.M; 00066 00067 arma_debug_check( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols), "trace(): incompatible matrix dimensions"); 00068 arma_debug_check( !A.is_square(), "trace(): matrices must be square"); 00069 00070 return trace(A) + trace(B); 00071 }
T1::elem_type trace | ( | const Glue< T1, T2, glue_minus > & | X | ) | [inline] |
Immediate trace (sum of diagonal elements) of A - B. A and B must be square and have the same dimensions.
Definition at line 81 of file fn_trace.hpp.
References Glue< T1, T2, glue_type >::A, Glue< T1, T2, glue_type >::B, isnt_same_type< T1, T2 >::check(), Mat< eT >::is_square(), Mat< eT >::n_cols, Mat< eT >::n_rows, and trace().
00082 { 00083 arma_extra_debug_sigprint(); 00084 00085 isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check(); 00086 00087 const unwrap<T1> tmp1(X.A); 00088 const unwrap<T2> tmp2(X.B); 00089 00090 typedef typename T1::elem_type eT; 00091 00092 const Mat<eT>& A = tmp1.M; 00093 const Mat<eT>& B = tmp2.M; 00094 00095 arma_debug_check( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols), "trace(): incompatible matrix dimensions"); 00096 arma_debug_check( !A.is_square(), "trace(): matrices must be square"); 00097 00098 return trace(A) - trace(B); 00099 }
T1::elem_type trace | ( | const Glue< T1, T2, glue_schur > & | X | ) | [inline] |
Immediate trace (sum of diagonal elements) of A % B (where % is the element-wise multiplication operator). A and B must be square and have the same dimensions.
Definition at line 109 of file fn_trace.hpp.
References Glue< T1, T2, glue_type >::A, Mat< eT >::at(), Glue< T1, T2, glue_type >::B, isnt_same_type< T1, T2 >::check(), Mat< eT >::is_square(), Mat< eT >::n_cols, and Mat< eT >::n_rows.
00110 { 00111 arma_extra_debug_sigprint(); 00112 00113 isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check(); 00114 00115 const unwrap<T1> tmp1(X.A); 00116 const unwrap<T2> tmp2(X.B); 00117 00118 typedef typename T1::elem_type eT; 00119 00120 const Mat<eT>& A = tmp1.M; 00121 const Mat<eT>& B = tmp2.M; 00122 00123 arma_debug_check( (A.n_rows != B.n_rows) || (A.n_cols != B.n_cols), "trace(): incompatible matrix dimensions" ); 00124 arma_debug_check( !A.is_square(), "trace(): matrices must be square" ); 00125 00126 eT val = eT(0); 00127 for(u32 i=0; i<A.n_rows; ++i) 00128 { 00129 val += A.at(i,i) * B.at(i,i); 00130 } 00131 00132 return val; 00133 }
T1::elem_type trace | ( | const Op< T1, op_scalar_times > & | in | ) | [inline] |
trace (sum of diagonal elements) of k * T1, where k is a scalar and T1 is converted to a dense matrix.
Definition at line 143 of file fn_trace.hpp.
References Op< T1, op_type >::aux, Op< T1, op_type >::m, and trace().
00144 { 00145 arma_extra_debug_sigprint(); 00146 00147 typedef typename T1::elem_type eT; 00148 00149 const unwrap<T1> tmp(in.m); 00150 const Mat<eT>& X = tmp.M; 00151 00152 return trace(X) * in.aux; 00153 }
eT trace | ( | const Op< Mat< eT >, op_diagmat > & | X | ) | [inline] |
trace (sum of diagonal elements) of a diagonal matrix
Definition at line 161 of file fn_trace.hpp.
References trace().
eT trace | ( | const Op< Mat< eT >, op_diagmat_vec > & | X | ) | [inline] |
Definition at line 173 of file fn_trace.hpp.
References accu(), and Mat< eT >::is_vec().
00174 { 00175 arma_extra_debug_sigprint(); 00176 00177 const Mat<eT>& A = X.m; 00178 arma_debug_check( !A.is_vec(), "trace(): internal error: can't interpret as a vector" ); 00179 00180 00181 return accu(X.m); 00182 }