Glue_schur

Classes

class  glue_schur
 Class which implements the immediate Schur product (element-wise multiplication) of two or more matrices. More...
class  glue_schur_diag

Functions

template<typename T1 , typename T2 >
static void glue_schur::apply (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_schur > &X)
template<typename T1 >
static void glue_schur::apply_inplace (Mat< typename T1::elem_type > &out, const T1 &X)
template<typename eT1 , typename eT2 >
static void glue_schur::apply_mixed (Mat< typename promote_type< eT1, eT2 >::result > &out, const Mat< eT1 > &X, const Mat< eT2 > &Y)
 matrix schur product with different element types
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B)
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Mat< eT > &A, const Mat< eT > &B, const Mat< eT > &C)
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Glue< Mat< eT >, Mat< eT >, glue_schur > &X)
template<typename eT >
static void glue_schur::apply (Mat< eT > &out, const Glue< Glue< Mat< eT >, Mat< eT >, glue_schur >, Mat< eT >, glue_schur > &X)
template<typename T1 , typename T2 >
static void glue_schur::apply_inplace (Mat< typename T1::elem_type > &out, const Glue< T1, T2, glue_schur > &X)
template<typename T1 , typename T2 >
static void glue_schur_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_schur_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_schur_diag::apply (Mat< typename T1::elem_type > &out, const Glue< T1, Op< T2, op_diagmat >, glue_schur_diag > &X)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const Glue< Op< T1, op_diagmat >, T2, glue_schur_diag > &X)
template<typename T1 , typename T2 >
static void glue_schur_diag::apply (Mat< typename T1::elem_type > &out, const Glue< Op< T1, op_diagmat >, Op< T2, op_diagmat >, glue_schur_diag > &X)

Function Documentation

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

Definition at line 24 of file glue_schur_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().

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

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

Definition at line 111 of file glue_schur_meat.hpp.

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

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

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

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

matrix schur product with different element types

Definition at line 140 of file glue_schur_meat.hpp.

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

Referenced by operator%().

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

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

Definition at line 168 of file glue_schur_meat.hpp.

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

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

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

Definition at line 196 of file glue_schur_meat.hpp.

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

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

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

Definition at line 230 of file glue_schur_meat.hpp.

References apply().

00231   {
00232   glue_schur::apply(out, X.A, X.B);
00233   }

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

Definition at line 240 of file glue_schur_meat.hpp.

References apply().

00241   {
00242   glue_schur::apply(out, X.A.A, X.A.B, X.B);
00243   }

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

Definition at line 250 of file glue_schur_meat.hpp.

00251   {
00252   arma_extra_debug_sigprint();
00253   
00254   out = X % out;
00255   }

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

Definition at line 270 of file glue_schur_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().

Referenced by glue_schur_diag::apply().

00271   {
00272   arma_extra_debug_sigprint();
00273   
00274   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00275   
00276   const unwrap<T1> tmp1(A_orig);
00277   const unwrap<T2> tmp2(B_orig.m);
00278   
00279   typedef typename T1::elem_type eT;
00280   
00281   const Mat<eT>& A = tmp1.M;
00282   const Mat<eT>& B = tmp2.M;
00283   
00284   arma_debug_check( (B.is_square() == false), "glue_schur_diag::apply(): matrices must be square" );
00285   arma_debug_assert_same_size(A, B, "matrix schur product");
00286 
00287   if( (&out != &A) && (&out != &B) )
00288     {
00289     out.zeros(A.n_rows, A.n_cols);
00290     
00291     for(u32 i=0; i<A.n_rows; ++i)
00292       {
00293       out.at(i,i) = A.at(i,i) * B.at(i,i);
00294       }
00295     }
00296   else
00297     {
00298     for(u32 col=0; col<A.n_cols; ++col)
00299       {
00300       for(u32 row=0; row<A.n_rows; ++row)
00301         {
00302         if(col != row)
00303           {
00304           out.at(row,col) = eT(0);
00305           }
00306         else
00307           {
00308           out.at(row,col) = A.at(row,col) * B.at(row,col);
00309           }
00310         }
00311       }
00312     }
00313   
00314   }

template<typename T1 , typename T2 >
void glue_schur_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 321 of file glue_schur_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().

00322   {
00323   arma_extra_debug_sigprint();
00324   
00325   isnt_same_type<typename T1::elem_type, typename T2::elem_type>::check();
00326   
00327   const unwrap<T1> tmp1(A_orig.m);
00328   const unwrap<T2> tmp2(B_orig.m);
00329   
00330   typedef typename T1::elem_type eT;
00331   
00332   const Mat<eT>& A = tmp1.M;
00333   const Mat<eT>& B = tmp2.M;
00334   
00335   arma_debug_check( (A.is_square() == false), "glue_schur_diag::apply(): matrices must be square" );
00336   arma_debug_assert_same_size(A, B, "matrix schur product");
00337   
00338   if( (&out != &A) && (&out != &B) )
00339     {
00340     out.zeros(A.n_rows, A.n_cols);
00341     
00342     for(u32 i=0; i<A.n_rows; ++i)
00343       {
00344       out.at(i,i) = A.at(i,i) * B.at(i,i);
00345       }
00346     }
00347   else
00348     {
00349     for(u32 col=0; col<A.n_cols; ++col)
00350       {
00351       for(u32 row=0; row<A.n_rows; ++row)
00352         {
00353         if(col != row)
00354           {
00355           out.at(row,col) = eT(0);
00356           }
00357         else
00358           {
00359           out.at(row,col) = A.at(row,col) * B.at(row,col);
00360           }
00361         }
00362       }
00363     }
00364   
00365   }

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

Definition at line 372 of file glue_schur_meat.hpp.

References glue_schur_diag::apply().

00373   {
00374   glue_schur_diag::apply(out, X.A, X.B);
00375   }

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

Definition at line 382 of file glue_schur_meat.hpp.

References glue_schur_diag::apply().

00383   {
00384   glue_schur_diag::apply(out, X.B, X.A);  // NOTE: arguments are swapped
00385   }

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

Definition at line 392 of file glue_schur_meat.hpp.

References glue_schur_diag::apply().

00393   {
00394   glue_schur_diag::apply(out, X.A, X.B);
00395   }