Glue_minus

Classes

class  glue_minus
 Class for the minus operation, where the result is always a dense matrix. More...
class  glue_minus_diag
 Class for the minus operation, where one of the operands is a diagonal matrix. More...

Functions

template<typename T1 , typename T2 >
static void glue_minus::apply (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_minus > &X)
 Immediate out = A-B-...-Z (operands obtained from Glue).
template<typename T1 >
static void glue_minus::apply_inplace (Mat< typename T1::elem_type > &out, const T1 &X)
 Immediate out -= B.
template<typename eT1 , typename eT2 >
static void glue_minus::apply_mixed (Mat< typename promote_type< eT1, eT2 >::result > &out, const Mat< eT1 > &X, const Mat< eT2 > &Y)
 matrix subtraction with different element types
template<typename eT >
static void glue_minus::apply (Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B)
 Immediate out = A-B.
template<typename eT >
static void glue_minus::apply (Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B, const Mat< eT > &C)
 Immediate out = A-B-C.
template<typename T1 >
static void glue_minus::apply_inplace (Mat< typename T1::elem_type > &out, const Op< T1, op_scalar_times > &X)
template<typename T1 >
static void glue_minus::apply_inplace (Mat< typename T1::elem_type > &out, const Op< T1, op_scalar_div_pre > &X)
template<typename T1 >
static void glue_minus::apply_inplace (Mat< typename T1::elem_type > &out, const Op< T1, op_scalar_div_post > &X)
template<typename eT >
static void glue_minus::apply (Mat< eT > &out, const Glue< Mat< eT >, Mat< eT >, glue_minus > &X)
 Immediate out = A-B (operands obtained from Glue).
template<typename eT >
static void glue_minus::apply (Mat< eT > &out, const Glue< Glue< Mat< eT >, Mat< eT >, glue_minus >, Mat< eT >, glue_minus > &X)
 Immediate out = A-B-C (operands obtained from Glue).
template<typename T1 , typename T2 >
static void glue_minus::apply_inplace (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_minus > &X)
template<typename T1 , typename T2 >
static void glue_minus_diag::apply (Mat< typename T1::elem_type > &out, const T1 &A, const Op< T2, op_diagmat > &B)
template<typename T1 , typename T2 >
static void glue_minus_diag::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_diagmat > &A, const T2 &B)
template<typename T1 , typename T2 >
static void glue_minus_diag::apply (Mat< typename T1::elem_type > &out, const Op< T1, op_diagmat > &A, const Op< T2, op_diagmat > &B)
template<typename T1 , typename T2 >
static void glue_minus_diag::apply (Mat< typename T1::elem_type > &out, const Glue< T1, Op< T2, op_diagmat >, glue_minus_diag > &X)
template<typename T1 , typename T2 >
static void glue_minus_diag::apply (Mat< typename T1::elem_type > &out, const Glue< Op< T1, op_diagmat >, T2, glue_minus_diag > &X)
template<typename T1 , typename T2 >
static void glue_minus_diag::apply (Mat< typename T1::elem_type > &out, const Glue< Op< T1, op_diagmat >, Op< T2, op_diagmat >, glue_minus_diag > &X)

Function Documentation

template<typename T1 , typename T2 >
void glue_minus::apply ( Mat< typename T1::elem_type > &  out,
const Glue< T1, T2, glue_minus > &  X 
) [inline, static, inherited]

Immediate out = A-B-...-Z (operands obtained from Glue).

Definition at line 25 of file glue_minus_meat.hpp.

References Glue< T1, T2, glue_type >::A, apply_inplace(), Glue< T1, T2, glue_type >::B, and Mat< eT >::set_size().

Referenced by apply(), and apply_mixed().

00026   {
00027   arma_extra_debug_sigprint();
00028   
00029   typedef typename T1::elem_type eT;
00030   
00031   const u32 N_mat = 1 + depth_lhs< glue_minus, Glue<T1,T2,glue_minus> >::num;
00032   arma_extra_debug_print( arma_boost::format("N_mat = %d") % N_mat );
00033 
00034 
00035   if(N_mat == 2)
00036     {
00037     if(is_Mat<T1>::value == false)
00038       {
00039       out = X.A;
00040       glue_minus::apply_inplace(out, X.B);
00041       }
00042     else
00043       {
00044       const unwrap<T1> tmp1(X.A);
00045       const unwrap<T2> tmp2(X.B);
00046       
00047       glue_minus::apply(out, tmp1.M, tmp2.M);
00048       }
00049     }
00050   else
00051     {
00052     const Mat<eT>* ptrs[N_mat];
00053     bool            del[N_mat];
00054 
00055     mat_ptrs<glue_minus, Glue<T1,T2,glue_minus> >::get_ptrs(ptrs, del, X);
00056     //mat_ptrs_outcheck<glue_minus, Glue<T1,T2,glue_minus> >::get_ptrs(ptrs, del, X, &out);
00057 
00058     for(u32 i=0; i<N_mat; ++i)  arma_extra_debug_print( arma_boost::format("ptrs[%d] = %x")  % i % ptrs[i] );
00059     for(u32 i=0; i<N_mat; ++i)  arma_extra_debug_print( arma_boost::format(" del[%d] = %d")  % i %  del[i] );
00060 
00061     const Mat<eT>& tmp_mat = *(ptrs[0]);
00062     
00063     for(u32 i=1; i<N_mat; ++i)
00064       {
00065       arma_debug_assert_same_size(tmp_mat, *(ptrs[i]), "matrix subtraction");
00066       }
00067   
00068     const u32 n_rows = ptrs[0]->n_rows;
00069     const u32 n_cols = ptrs[0]->n_cols;
00070     
00071     // no aliasing problem
00072     out.set_size(n_rows,n_cols);
00073     
00074     const u32 n_elem = ptrs[0]->n_elem;
00075     
00076     for(u32 j=0; j<n_elem; ++j)
00077       {
00078       eT acc = ptrs[0]->mem[j];
00079       
00080       for(u32 i=1; i<N_mat; ++i)
00081         {
00082         acc -= ptrs[i]->mem[j];
00083         }
00084       
00085       out[j] = acc;
00086       }
00087     
00088     for(u32 i=0; i<N_mat; ++i)
00089       {
00090       if(del[i] == true)
00091         {
00092         arma_extra_debug_print( arma_boost::format("delete ptrs[%d]") % i );
00093         delete ptrs[i];
00094         }
00095       }
00096 
00097     }
00098   }

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

Immediate out -= B.

Definition at line 106 of file glue_minus_meat.hpp.

References Mat< eT >::mem, Mat< eT >::memptr(), and Mat< eT >::n_elem.

Referenced by apply(), and Mat< eT >::operator-=().

00107   {
00108   arma_extra_debug_sigprint();
00109   
00110   typedef typename T1::elem_type eT;
00111   
00112   const unwrap<T1>   tmp(X);
00113   const Mat<eT>& B = tmp.M;
00114   
00115   arma_debug_assert_same_size(out, B, "matrix subtraction");
00116   
00117         eT* out_mem = out.memptr();
00118   const eT* B_mem   = B.mem;
00119   
00120   const u32 n_elem  = out.n_elem;
00121   
00122   for(u32 i=0; i<n_elem; ++i)
00123     {
00124     out_mem[i] -= B_mem[i];
00125     }
00126   
00127   }

template<typename eT1 , typename eT2 >
void glue_minus::apply_mixed ( Mat< typename promote_type< eT1, eT2 >::result > &  out,
const Mat< eT1 > &  X,
const Mat< eT2 > &  Y 
) [inline, static, inherited]

matrix subtraction with different element types

Definition at line 135 of file glue_minus_meat.hpp.

References apply(), and Mat< eT >::mem.

Referenced by operator-().

00136   {
00137   arma_extra_debug_sigprint();
00138   
00139   typedef typename promote_type<eT1,eT2>::result out_eT;
00140   
00141   arma_debug_assert_same_size(X,Y, "matrix subtraction");
00142   
00143   //out.set_size(X.n_rows, X.n_cols);
00144   out.copy_size(X);
00145   
00146         out_eT* out_mem = out.memptr();
00147   const eT1*    X_mem   = X.mem;
00148   const eT2*    Y_mem   = Y.mem;
00149   
00150   const u32 n_elem = out.n_elem;
00151   
00152   for(u32 i=0; i<n_elem; ++i)
00153     {
00154     out_mem[i] = upgrade_val<eT1,eT2>::apply(X_mem[i]) - upgrade_val<eT1,eT2>::apply(Y_mem[i]);
00155     }
00156   }

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

Immediate out = A-B.

Definition at line 164 of file glue_minus_meat.hpp.

References Mat< eT >::copy_size(), Mat< eT >::mem, Mat< eT >::memptr(), and Mat< eT >::n_elem.

00165   {
00166   arma_extra_debug_sigprint();
00167   
00168   arma_debug_assert_same_size(A, B, "matrix subtraction");
00169   
00170   // no aliasing problem
00171   //out.set_size(A.n_rows,A.n_cols);
00172   out.copy_size(A);
00173     
00174         eT* out_mem = out.memptr();
00175   const eT* A_mem   = A.mem;
00176   const eT* B_mem   = B.mem;
00177   
00178   const u32 n_elem  = A.n_elem;
00179   
00180   for(u32 i=0; i<n_elem; ++i)
00181     {
00182     out_mem[i] = A_mem[i] - B_mem[i];
00183     }
00184     
00185   }

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

Immediate out = A-B-C.

Definition at line 193 of file glue_minus_meat.hpp.

References Mat< eT >::copy_size(), Mat< eT >::mem, Mat< eT >::memptr(), and Mat< eT >::n_elem.

00194   {
00195   arma_extra_debug_sigprint();
00196   
00197   arma_debug_assert_same_size(A, B, "matrix subtraction");
00198   arma_debug_assert_same_size(A, C, "matrix subtraction");
00199   
00200   // no aliasing problem
00201   //out.set_size(A.n_rows, A.n_cols);
00202   out.copy_size(A);
00203     
00204         eT* out_mem = out.memptr();
00205   const eT* A_mem   = A.mem;
00206   const eT* B_mem   = B.mem;
00207   const eT* C_mem   = C.mem;
00208   
00209   const u32 n_elem = A.n_elem;
00210   
00211   for(u32 i=0; i<n_elem; ++i)
00212     {
00213     out_mem[i] = A_mem[i] - B_mem[i] - C_mem[i];
00214     }
00215   
00216   }

template<typename T1 >
void glue_minus::apply_inplace ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_scalar_times > &  X 
) [inline, static, inherited]

Definition at line 227 of file glue_minus_meat.hpp.

References Op< T1, op_type >::aux, Op< T1, op_type >::m, Mat< eT >::mem, Mat< eT >::memptr(), and Mat< eT >::n_elem.

00228   {
00229   arma_extra_debug_sigprint();
00230   
00231   typedef typename T1::elem_type eT;
00232   
00233   const unwrap<T1>   tmp(X.m);
00234   const Mat<eT>& A = tmp.M;
00235   
00236   arma_debug_assert_same_size(out, A, "matrix subtraction");
00237   
00238         eT* out_mem = out.memptr();
00239   const eT* A_mem   = A.mem;
00240   
00241   const eT  k       = X.aux;
00242   const u32 n_elem  = out.n_elem;
00243   
00244   for(u32 i=0; i<n_elem; ++i)
00245     {
00246     out_mem[i] -= k * A_mem[i];
00247     }
00248   }

template<typename T1 >
void glue_minus::apply_inplace ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_scalar_div_pre > &  X 
) [inline, static, inherited]

Definition at line 255 of file glue_minus_meat.hpp.

References Op< T1, op_type >::aux, Op< T1, op_type >::m, Mat< eT >::mem, Mat< eT >::memptr(), and Mat< eT >::n_elem.

00256   {
00257   arma_extra_debug_sigprint();
00258   
00259   typedef typename T1::elem_type eT;
00260   
00261   const unwrap<T1>   tmp(X.m);
00262   const Mat<eT>& A = tmp.M;
00263   
00264   arma_debug_assert_same_size(out, A, "matrix subtraction");
00265   
00266         eT* out_mem = out.memptr();
00267   const eT* A_mem   = A.mem;
00268   
00269   const eT  k       = X.aux;
00270   const u32 n_elem  = out.n_elem;
00271   
00272   for(u32 i=0; i<n_elem; ++i)
00273     {
00274     out_mem[i] -= k / A_mem[i];
00275     }
00276   }

template<typename T1 >
void glue_minus::apply_inplace ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_scalar_div_post > &  X 
) [inline, static, inherited]

Definition at line 283 of file glue_minus_meat.hpp.

References Op< T1, op_type >::aux, Op< T1, op_type >::m, Mat< eT >::mem, Mat< eT >::memptr(), and Mat< eT >::n_elem.

00284   {
00285   arma_extra_debug_sigprint();
00286   
00287   typedef typename T1::elem_type eT;
00288   
00289   const unwrap<T1>   tmp(X.m);
00290   const Mat<eT>& A = tmp.M;
00291   
00292   arma_debug_assert_same_size(out, A, "matrix subtraction");
00293   
00294         eT* out_mem = out.memptr();
00295   const eT* A_mem   = A.mem;
00296   
00297   const eT  k       = X.aux;
00298   const u32 n_elem  = out.n_elem;
00299   
00300   for(u32 i=0; i<n_elem; ++i)
00301     {
00302     out_mem[i] -= A_mem[i] / k;
00303     }
00304   }

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

Immediate out = A-B (operands obtained from Glue).

Definition at line 312 of file glue_minus_meat.hpp.

References apply().

00313   {
00314   glue_minus::apply(out, X.A, X.B);
00315   }

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

Immediate out = A-B-C (operands obtained from Glue).

Definition at line 323 of file glue_minus_meat.hpp.

References apply().

00324   {
00325   glue_minus::apply(out, X.A.A, X.A.B, X.B);
00326   }

template<typename T1 , typename T2 >
void glue_minus::apply_inplace ( Mat< typename T1::elem_type > &  out,
const Glue< T1, T2, glue_minus > &  X 
) [inline, static, inherited]

Definition at line 333 of file glue_minus_meat.hpp.

00334   {
00335   arma_extra_debug_sigprint();
00336   
00337   typedef typename T1::elem_type eT;
00338   
00339   out = out - X;
00340   }

template<typename T1 , typename T2 >
void glue_minus_diag::apply ( Mat< typename T1::elem_type > &  out,
const T1 &  A,
const Op< T2, op_diagmat > &  B 
) [inline, static, inherited]

Definition at line 355 of file glue_minus_meat.hpp.

References Mat< eT >::at(), Mat< eT >::copy_size(), Mat< eT >::is_square(), Op< T1, op_type >::m, Mat< eT >::n_cols, and Mat< eT >::n_rows.

Referenced by glue_minus_diag::apply().

00356   {
00357   arma_extra_debug_sigprint();
00358   
00359   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00360   
00361   const unwrap<T1> tmp1(A_orig);
00362   const unwrap<T2> tmp2(B_orig.m);
00363   
00364   typedef typename T1::elem_type eT;
00365   
00366   const Mat<eT>& A = tmp1.M;
00367   const Mat<eT>& B = tmp2.M;
00368   
00369   arma_debug_check( !B.is_square(), "glue_minus_diag::apply(): matrices must be square" );
00370   arma_debug_assert_same_size(A, B, "matrix subtraction");
00371 
00372   
00373   // no aliasing problem
00374   //out.set_size(A.n_rows, A.n_cols);
00375   out.copy_size(A);
00376   
00377   for(u32 col=0; col<A.n_cols; ++col)
00378     {
00379     for(u32 row=0; row<A.n_rows; ++row)
00380       {
00381       if(col != row)
00382         {
00383         out.at(row,col) = A.at(row,col);
00384         }
00385       else
00386         {
00387         out.at(row,col) = A.at(row,col) - B.at(row,col);
00388         }
00389       }
00390     }
00391   
00392   }

template<typename T1 , typename T2 >
void glue_minus_diag::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_diagmat > &  A,
const T2 &  B 
) [inline, static, inherited]

Definition at line 399 of file glue_minus_meat.hpp.

References Mat< eT >::at(), Mat< eT >::copy_size(), Mat< eT >::is_square(), Op< T1, op_type >::m, Mat< eT >::n_cols, and Mat< eT >::n_rows.

00400   {
00401   arma_extra_debug_sigprint();
00402   
00403   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00404   
00405   const unwrap<T1> tmp1(A_orig.m);
00406   const unwrap<T2> tmp2(B_orig);
00407   
00408   typedef typename T1::elem_type eT;
00409   
00410   const Mat<eT>& A = tmp1.M;
00411   const Mat<eT>& B = tmp2.M;
00412   
00413   arma_debug_check( !A.is_square(), "glue_minus_diag::apply(): matrices must be square" );
00414   arma_debug_assert_same_size(A, B, "matrix subtraction");
00415   
00416   
00417   // no aliasing problem
00418   //out.set_size(A.n_rows, A.n_cols);
00419   out.copy_size(A);
00420   
00421   for(u32 col=0; col<A.n_cols; ++col)
00422     {
00423     for(u32 row=0; row<A.n_rows; ++row)
00424       {
00425       if(col != row)
00426         {
00427         out.at(row,col) = -B.at(row,col);
00428         }
00429       else
00430         {
00431         out.at(row,col) = A.at(row,col) - B.at(row,col);
00432         }
00433       }
00434     }
00435   
00436   }

template<typename T1 , typename T2 >
void glue_minus_diag::apply ( Mat< typename T1::elem_type > &  out,
const Op< T1, op_diagmat > &  A,
const Op< T2, op_diagmat > &  B 
) [inline, static, inherited]

Definition at line 443 of file glue_minus_meat.hpp.

References Mat< eT >::at(), Mat< eT >::is_square(), Op< T1, op_type >::m, Mat< eT >::n_cols, Mat< eT >::n_rows, and Mat< eT >::zeros().

00444   {
00445   arma_extra_debug_sigprint();
00446   
00447   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00448   
00449   const unwrap<T1> tmp1(A_orig.m);
00450   const unwrap<T2> tmp2(B_orig.m);
00451   
00452   typedef typename T1::elem_type eT;
00453   
00454   const Mat<eT>& A = tmp1.M;
00455   const Mat<eT>& B = tmp2.M;
00456     
00457   arma_debug_check( !A.is_square(), "glue_minus_diag::apply(): matrices must be square" );
00458   arma_debug_assert_same_size(A, B, "matrix subtraction");
00459   
00460   
00461   if( (&out != &A) && (&out != &B) )
00462     {
00463     out.zeros(A.n_rows, A.n_cols);
00464     
00465     for(u32 i=0; i<A.n_rows; ++i)
00466       {
00467       out.at(i,i) = A.at(i,i) - B.at(i,i);
00468       }
00469     }
00470   else
00471     {
00472     for(u32 col=0; col<A.n_cols; ++col)
00473       {
00474       for(u32 row=0; row<A.n_rows; ++row)
00475         {
00476         if(col != row)
00477           {
00478           out.at(row,col) = 0.0;
00479           }
00480         else
00481           {
00482           out.at(row,col) = A.at(row,col) - B.at(row,col);
00483           }
00484         }
00485       }
00486     }
00487   
00488   }

template<typename T1 , typename T2 >
void glue_minus_diag::apply ( Mat< typename T1::elem_type > &  out,
const Glue< T1, Op< T2, op_diagmat >, glue_minus_diag > &  X 
) [inline, static, inherited]

Definition at line 495 of file glue_minus_meat.hpp.

References glue_minus_diag::apply().

00496   {
00497   glue_minus_diag::apply(out, X.A, X.B);
00498   }

template<typename T1 , typename T2 >
void glue_minus_diag::apply ( Mat< typename T1::elem_type > &  out,
const Glue< Op< T1, op_diagmat >, T2, glue_minus_diag > &  X 
) [inline, static, inherited]

Definition at line 505 of file glue_minus_meat.hpp.

References glue_minus_diag::apply().

00506   {
00507   glue_minus_diag::apply(out, X.A, X.B);
00508   }

template<typename T1 , typename T2 >
void glue_minus_diag::apply ( Mat< typename T1::elem_type > &  out,
const Glue< Op< T1, op_diagmat >, Op< T2, op_diagmat >, glue_minus_diag > &  X 
) [inline, static, inherited]

Definition at line 515 of file glue_minus_meat.hpp.

References glue_minus_diag::apply().

00516   {
00517   glue_minus_diag::apply(out, X.A, X.B);
00518   }