Classes | Functions

Op_inv

//! More...

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)

Detailed Description

//!


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().

  {
  arma_extra_debug_sigprint();
  
  // no need to check for aliasing, due to:
  // - auxlib::inv() copies A to out before inversion
  // - for 2x2 and 3x3 matrices the code is alias safe
  
  arma_debug_check( !A.is_square(), "op_inv::apply(): matrix must be square" );
  
  const bool status = (&out != &A) ? auxlib::inv_noalias(out, A) : auxlib::inv_inplace(out);
  
  if(status == false)
    {
    arma_warn( true, "inv(): matrix appears to be singular" );
    out.set_size(0,0);
    }
  }

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.

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const strip_diagmat<T1> strip(X.m);
  
  if(strip.do_diagmat == true)
    {
    op_inv::apply_diag(out, strip.M);
    }
  else
    {
    const unwrap<T1>   tmp(X.m);
    const Mat<eT>& A = tmp.M;
  
    op_inv::apply(out, A);
    }
  }

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().

  {
  arma_extra_debug_sigprint();
  
  typedef typename T1::elem_type eT;
  
  const diagmat_proxy_check<T1> A(X.get_ref(), out);
  
  const u32 N = A.n_elem;
  
  out.set_size(N,N);
  
  for(u32 col=0; col<N; ++col)
    {
    for(u32 row=0; row<col; ++row)   { out.at(row,col) = eT(0); }
    
    out.at(col,col) = eT(1) / A[col];
    
    for(u32 row=col+1; row<N; ++row) { out.at(row,col) = eT(0); }
    }
  
  }