Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 template<typename eT>
00023 inline
00024 void
00025 op_inv::apply(Mat<eT>& out, const Mat<eT>& A)
00026 {
00027 arma_extra_debug_sigprint();
00028
00029
00030
00031
00032
00033 arma_debug_check( !A.is_square(), "op_inv::apply(): matrix must be square" );
00034
00035 const bool status = (&out != &A) ? auxlib::inv_noalias(out, A) : auxlib::inv_inplace(out);
00036
00037 if(status == false)
00038 {
00039 arma_warn( true, "inv(): matrix appears to be singular" );
00040 out.set_size(0,0);
00041 }
00042 }
00043
00044
00045
00046
00047 template<typename T1>
00048 inline
00049 void
00050 op_inv::apply(Mat<typename T1::elem_type>& out, const Op<T1,op_inv>& X)
00051 {
00052 arma_extra_debug_sigprint();
00053
00054 typedef typename T1::elem_type eT;
00055
00056 const strip_diagmat<T1> strip(X.m);
00057
00058 if(strip.do_diagmat == true)
00059 {
00060 op_inv::apply_diag(out, strip.M);
00061 }
00062 else
00063 {
00064 const unwrap<T1> tmp(X.m);
00065 const Mat<eT>& A = tmp.M;
00066
00067 op_inv::apply(out, A);
00068 }
00069 }
00070
00071
00072
00073 template<typename T1>
00074 inline
00075 void
00076 op_inv::apply_diag(Mat<typename T1::elem_type>& out, const Base<typename T1::elem_type, T1>& X)
00077 {
00078 arma_extra_debug_sigprint();
00079
00080 typedef typename T1::elem_type eT;
00081
00082 const diagmat_proxy_check<T1> A(X.get_ref(), out);
00083
00084 const u32 N = A.n_elem;
00085
00086 out.set_size(N,N);
00087
00088 for(u32 col=0; col<N; ++col)
00089 {
00090 for(u32 row=0; row<col; ++row) { out.at(row,col) = eT(0); }
00091
00092 out.at(col,col) = eT(1) / A[col];
00093
00094 for(u32 row=col+1; row<N; ++row) { out.at(row,col) = eT(0); }
00095 }
00096
00097 }
00098
00099
00100
00101