00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 template<typename T1>
00023 class diagmat_proxy
00024 {
00025 public:
00026
00027 typedef typename T1::elem_type elem_type;
00028 typedef typename get_pod_type<elem_type>::result pod_type;
00029
00030 inline diagmat_proxy(const Base<typename T1::elem_type,T1>& X)
00031 : P (X.get_ref())
00032 , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) )
00033 , n_elem ( P_is_vec ? P.n_elem : P.n_rows )
00034 {
00035 arma_extra_debug_sigprint();
00036
00037 arma_debug_check( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" );
00038 }
00039
00040
00041 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00042 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00043
00044
00045 const Proxy<T1> P;
00046 const bool P_is_vec;
00047 const u32 n_elem;
00048 };
00049
00050
00051
00052 template<typename eT>
00053 class diagmat_proxy< Mat<eT> >
00054 {
00055 public:
00056
00057 typedef eT elem_type;
00058 typedef typename get_pod_type<elem_type>::result pod_type;
00059
00060
00061 inline diagmat_proxy(const Mat<eT>& X)
00062 : P(X)
00063 , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) )
00064 , n_elem( P_is_vec ? P.n_elem : P.n_rows )
00065 {
00066 arma_extra_debug_sigprint();
00067 arma_debug_check( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" );
00068 }
00069
00070
00071 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00072 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00073
00074 const Mat<eT>& P;
00075 const bool P_is_vec;
00076 const u32 n_elem;
00077 };
00078
00079
00080
00081 template<typename eT>
00082 class diagmat_proxy< Row<eT> >
00083 {
00084 public:
00085
00086 typedef eT elem_type;
00087 typedef typename get_pod_type<elem_type>::result pod_type;
00088
00089
00090 inline diagmat_proxy(const Row<eT>& X)
00091 : P(X)
00092 , P_is_vec(true)
00093 , n_elem(P.n_elem)
00094 {
00095 arma_extra_debug_sigprint();
00096 }
00097
00098
00099 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00100 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00101
00102
00103 const Row<eT>& P;
00104 const bool P_is_vec;
00105 const u32 n_elem;
00106 };
00107
00108
00109
00110 template<typename eT>
00111 class diagmat_proxy< Col<eT> >
00112 {
00113 public:
00114
00115 typedef eT elem_type;
00116 typedef typename get_pod_type<elem_type>::result pod_type;
00117
00118
00119 inline diagmat_proxy(const Col<eT>& X)
00120 : P(X)
00121 , P_is_vec(true)
00122 , n_elem(P.n_elem)
00123 {
00124 arma_extra_debug_sigprint();
00125 }
00126
00127
00128 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00129 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00130
00131
00132 const Col<eT>& P;
00133 const bool P_is_vec;
00134 const u32 n_elem;
00135 };
00136
00137
00138
00139 template<typename T1>
00140 class diagmat_proxy_check
00141 {
00142 public:
00143
00144 typedef typename T1::elem_type elem_type;
00145 typedef typename get_pod_type<elem_type>::result pod_type;
00146
00147 inline diagmat_proxy_check(const Base<typename T1::elem_type,T1>& X, const Mat<typename T1::elem_type>& out)
00148 : P(X.get_ref())
00149 , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) )
00150 , n_elem( P_is_vec ? P.n_elem : P.n_rows )
00151 {
00152 arma_extra_debug_sigprint();
00153 arma_debug_check( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" );
00154 }
00155
00156
00157 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00158 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00159
00160
00161 const Mat<elem_type> P;
00162 const bool P_is_vec;
00163 const u32 n_elem;
00164 };
00165
00166
00167
00168 template<typename eT>
00169 class diagmat_proxy_check< Mat<eT> >
00170 {
00171 public:
00172
00173 typedef eT elem_type;
00174 typedef typename get_pod_type<elem_type>::result pod_type;
00175
00176
00177 inline diagmat_proxy_check(const Mat<eT>& X, const Mat<eT>& out)
00178 : P_local ( (&X == &out) ? new Mat<eT>(X) : 0 )
00179 , P ( (&X == &out) ? (*P_local) : X )
00180 , P_is_vec( (P.n_rows == 1) || (P.n_cols == 1) )
00181 , n_elem ( P_is_vec ? P.n_elem : P.n_rows )
00182 {
00183 arma_extra_debug_sigprint();
00184
00185 arma_debug_check( (P_is_vec == false) && (P.n_rows != P.n_cols), "diagmat(): only vectors and square matrices are accepted" );
00186 }
00187
00188 inline ~diagmat_proxy_check()
00189 {
00190 if(P_local)
00191 {
00192 delete P_local;
00193 }
00194 }
00195
00196
00197 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00198 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00199
00200
00201 const Mat<eT>* P_local;
00202 const Mat<eT>& P;
00203 const bool P_is_vec;
00204 const u32 n_elem;
00205 };
00206
00207
00208
00209 template<typename eT>
00210 class diagmat_proxy_check< Row<eT> >
00211 {
00212 public:
00213
00214 typedef eT elem_type;
00215 typedef typename get_pod_type<elem_type>::result pod_type;
00216
00217 inline diagmat_proxy_check(const Row<eT>& X, const Mat<eT>& out)
00218 : P_local ( (&X == reinterpret_cast<const Row<eT>*>(&out)) ? new Row<eT>(X) : 0 )
00219 , P ( (&X == reinterpret_cast<const Row<eT>*>(&out)) ? (*P_local) : X )
00220 , P_is_vec(true)
00221 , n_elem (P.n_elem)
00222 {
00223 arma_extra_debug_sigprint();
00224 }
00225
00226
00227 inline ~diagmat_proxy_check()
00228 {
00229 if(P_local)
00230 {
00231 delete P_local;
00232 }
00233 }
00234
00235
00236 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00237 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00238
00239
00240 const Row<eT>* P_local;
00241 const Row<eT>& P;
00242 const bool P_is_vec;
00243 const u32 n_elem;
00244 };
00245
00246
00247
00248
00249
00250
00251 template<typename eT>
00252 class diagmat_proxy_check< Col<eT> >
00253 {
00254 public:
00255
00256 typedef eT elem_type;
00257 typedef typename get_pod_type<elem_type>::result pod_type;
00258
00259 inline diagmat_proxy_check(const Col<eT>& X, const Mat<eT>& out)
00260 : P_local ( (&X == reinterpret_cast<const Col<eT>*>(&out)) ? new Col<eT>(X) : 0 )
00261 , P ( (&X == reinterpret_cast<const Col<eT>*>(&out)) ? (*P_local) : X )
00262 , P_is_vec(true)
00263 , n_elem (P.n_elem)
00264 {
00265 arma_extra_debug_sigprint();
00266 }
00267
00268
00269 inline ~diagmat_proxy_check()
00270 {
00271 if(P_local)
00272 {
00273 delete P_local;
00274 }
00275 }
00276
00277
00278 arma_inline elem_type operator[] (const u32 i) const { return P_is_vec ? P[i] : P.at(i,i); }
00279 arma_inline elem_type at (const u32 row, const u32 col) const { return (row == col) ? ( P_is_vec ? P[row] : P.at(row,row) ) : elem_type(0); }
00280
00281
00282 const Col<eT>* P_local;
00283 const Col<eT>& P;
00284 const bool P_is_vec;
00285 const u32 n_elem;
00286 };
00287
00288
00289
00290