Op_inv

Classes

class  op_inv
 'invert matrix' operation More...

Functions

template<typename eT >
static void op_inv::apply (Mat< eT > &out, const Mat< eT > &A)
 immediate inverse of a matrix, storing the result in a dense matrix
template<typename T1 >
static void op_inv::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_inv > &in)
 immediate inverse of T1, storing the result in a dense matrix
template<typename T1 >
static void op_inv::apply_diag (Mat< typename T1::elem_type > &out, const Base< typename T1::elem_type, T1 > &X)

Function Documentation

template<typename eT >
void op_inv::apply ( Mat< eT > &  out,
const Mat< eT > &  A 
) [inline, static, inherited]

immediate inverse of a matrix, storing the result in a dense matrix

Definition at line 25 of file op_inv_meat.hpp.

References arma_warn(), auxlib::inv_inplace(), auxlib::inv_noalias(), Mat< eT >::is_square(), and Mat< eT >::set_size().

Referenced by apply().

00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   // no need to check for aliasing, due to:
00030   // - auxlib::inv() copies A to out before inversion
00031   // - for 2x2 and 3x3 matrices the code is alias safe
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   }

template<typename T1 >
void op_inv::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_inv > &  in 
) [inline, static, inherited]

immediate inverse of T1, storing the result in a dense matrix

Definition at line 50 of file op_inv_meat.hpp.

References apply(), apply_diag(), strip_diagmat< T1 >::do_diagmat, unwrap< T1 >::M, strip_diagmat< T1 >::M, and Op< T1, op_type >::m.

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   }

template<typename T1 >
void op_inv::apply_diag ( Mat< typename T1::elem_type > &  out,
const Base< typename T1::elem_type, T1 > &  X 
) [inline, static, inherited]

Definition at line 76 of file op_inv_meat.hpp.

References Mat< eT >::at(), Base< elem_type, derived >::get_ref(), and Mat< eT >::set_size().

Referenced by apply().

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   }